| /*=============================================================================# |
| # Copyright (c) 2009, 2018 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.docmlet.tex.core.ast; |
| |
| import static org.eclipse.statet.docmlet.tex.core.ast.ITexAstStatusConstants.STATUS2_MATH_NOT_CLOSED; |
| |
| import java.lang.reflect.InvocationTargetException; |
| |
| import org.eclipse.statet.docmlet.tex.core.ast.TexAst.NodeType; |
| import org.eclipse.statet.ltk.ast.core.AstNode; |
| import org.eclipse.statet.ltk.ast.core.AstVisitor; |
| |
| |
| public class Math extends ContainerNode { |
| |
| |
| static class SingleDollar extends Math { |
| |
| SingleDollar(final TexAstNode parent, final int startOffset, final int endOffset) { |
| super(parent, startOffset, endOffset); |
| } |
| |
| @Override |
| public String getText() { |
| return "$"; //$NON-NLS-1$ |
| } |
| |
| } |
| |
| static class DoubleDollar extends Math { |
| |
| DoubleDollar(final TexAstNode parent, final int startOffset, final int endOffset) { |
| super(parent, startOffset, endOffset); |
| } |
| |
| @Override |
| public String getText() { |
| return "$$"; //$NON-NLS-1$ |
| } |
| |
| } |
| |
| |
| private Math(final TexAstNode parent, final int startOffset, final int endOffset) { |
| super(parent, startOffset, endOffset); |
| } |
| |
| |
| @Override |
| public NodeType getNodeType() { |
| return NodeType.MATH; |
| } |
| |
| @Override |
| public final boolean hasChildren() { |
| return (this.children.length > 0); |
| } |
| |
| @Override |
| public final int getChildCount() { |
| return this.children.length; |
| } |
| |
| @Override |
| public final TexAstNode getChild(final int index) { |
| return this.children[index]; |
| } |
| |
| @Override |
| public final int getChildIndex(final AstNode element) { |
| for (int i= 0; i < this.children.length; i++) { |
| if (this.children[i] == element) { |
| return i; |
| } |
| } |
| return -1; |
| } |
| |
| @Override |
| public final void acceptInChildren(final AstVisitor visitor) throws InvocationTargetException { |
| for (final TexAstNode child : this.children) { |
| visitor.visit(child); |
| } |
| } |
| |
| @Override |
| public void acceptInTex(final TexAstVisitor visitor) throws InvocationTargetException { |
| visitor.visit(this); |
| } |
| |
| @Override |
| public final void acceptInTexChildren(final TexAstVisitor visitor) throws InvocationTargetException { |
| for (final TexAstNode child : this.children) { |
| child.acceptInTex(visitor); |
| } |
| } |
| |
| |
| @Override |
| void setEndNode(final int endOffset, final TexAstNode endNode) { |
| this.endOffset= endOffset; |
| } |
| |
| @Override |
| void setMissingEnd() { |
| this.status= STATUS2_MATH_NOT_CLOSED; |
| if (this.children.length > 0) { |
| this.endOffset= this.children[this.children.length-1].endOffset; |
| } |
| } |
| |
| } |