Class BaseNode

java.lang.Object
com.javacc.parser.BaseNode
All Implemented Interfaces:
JavaCCConstants, Node, freemarker.template.TemplateHashModel, freemarker.template.TemplateModel, freemarker.template.TemplateNodeModel, freemarker.template.TemplateScalarModel, Comparable<Node>
Direct Known Subclasses:
AdditiveExpression, AllocationExpression, AndExpression, AnnotationMethodDeclaration, AnnotationTypeBody, AnnotationTypeDeclaration, AnnotationTypeMemberDeclaration, ArrayAccess, ArrayDimsAndInits, ArrayInitializer, AssignmentExpression, BlockStatement, BNFProduction, CharacterRange, ClassDeclaration, ClassicCaseStatement, ClassicSwitchLabel, ClassicSwitchStatement, ClassLiteral, ClassOrInterfaceBody, CodeInjection, CodeInjection2, CompilationUnit, ConditionalAndExpression, ConditionalOrExpression, ConstructorDeclaration, DefaultValue, DiamondOperator, DotName, DotSuper, DotThis, EmptyDeclaration, EnumBody, EnumConstant, EnumDeclaration, EqualityExpression, ExceptionType, ExclusiveOrExpression, Expansion, ExpansionUnit, ExplicitConstructorInvocation, ExtendsList, FieldDeclaration, FinallyBlock, ForInit, FormalParameter, FormalParameters, Grammar, GrammarFile, GrammarInclusion, ImplementsList, ImportDeclaration, InclusiveOrExpression, Initializer, InstanceOfExpression, InterfaceDeclaration, InvocationArguments, Label, LambdaExpression, LambdaLHS, LambdaParameter, LambdaParameters, LexicalStateSwitch, LiteralExpression, LocalVariableDeclaration, Lookahead, LookBehind, MarkerAnnotation, MemberValue, MemberValueArrayInitializer, MemberValuePair, MemberValuePairs, MethodCall, MethodDeclaration, MethodReference, MultiplicativeExpression, Name, NewCaseStatement, NewSwitchLabel, NewSwitchStatement, NormalAnnotation, ObjectCastExpression, ObjectType, Options, PackageDeclaration, Parentheses, ParserCodeDecls, PermitsList, PostfixExpression, PreDecrementExpression, PreIncrementExpression, PrimitiveArrayType, PrimitiveCastExpression, PrimitiveType, RecordBody, RecordComponent, RecordDeclaration, RecordHeader, ReferenceType, RegexpSpec, RelationalExpression, ReturnType, scan, Setting, ShiftExpression, SingleMemberAnnotation, Statement, StatementExpression, StatementExpressionList, SwitchExpression, TernaryExpression, ThrowsList, TokenActivation, TokenManagerDecls, TokenProduction, TreeBuildingAnnotation, TypeArgument, TypeArguments, TypeBound, TypeParameter, TypeParameters, UnaryExpression, UnaryExpressionNotPlusMinus, VariableDeclarator, VariableDeclaratorId, VariableInitializer, WildcardBounds

public class BaseNode extends Object implements Node, freemarker.template.TemplateHashModel, JavaCCConstants
The base concrete class for non-terminal Nodes
  • Field Details

    • parent

      protected Node parent
      the parent node
    • children

      protected List<Node> children
      the child nodes
  • Constructor Details

    • BaseNode

      public BaseNode()
  • Method Details

    • get

      public freemarker.template.TemplateModel get(String key) throws freemarker.template.TemplateModelException
      Specified by:
      get in interface freemarker.template.TemplateHashModel
      Throws:
      freemarker.template.TemplateModelException
    • getGrammar

      public Grammar getGrammar()
      Specified by:
      getGrammar in interface Node
    • setGrammar

      public void setGrammar(Grammar grammar)
      Specified by:
      setGrammar in interface Node
    • getSimpleName

      public String getSimpleName()
    • getInnerText

      protected String getInnerText()
    • prepend

      public void prepend(Node n)
    • getAsString

      public String getAsString()
      Specified by:
      getAsString in interface freemarker.template.TemplateScalarModel
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface freemarker.template.TemplateHashModel
    • hasKeyWord

      public boolean hasKeyWord(String keyWord)
    • getLiteralText

      protected String getLiteralText()
    • getTokenSource

      public JavaCCLexer getTokenSource()
      Specified by:
      getTokenSource in interface Node
      Returns:
      the #JavaCCLexer from which this Node object originated. There is no guarantee that this doesn't return null. Most likely that would simply be because you constructed the Node yourself, i.e. it didn't really come about via the parsing/tokenizing machinery.
    • setTokenSource

      public void setTokenSource(JavaCCLexer tokenSource)
      Specified by:
      setTokenSource in interface Node
    • setListClass

      public static void setListClass(Class<? extends List> listClass)
      Sets the List class that is used to store child nodes. By default, this is java.util.ArrayList. There is probably very little reason to ever use anything else, though you could use this method to replace this with LinkedList or your own java.util.List implementation even.
      Parameters:
      listClass - the #java.util.List implementation to use internally for the child nodes. By default #java.util.ArrayList is used.
    • isUnparsed

      public boolean isUnparsed()
      Specified by:
      isUnparsed in interface Node
      Returns:
      whether this Node was created by regular operations of the parsing machinery.
    • setUnparsed

      public void setUnparsed(boolean unparsed)
      Description copied from interface: Node
      Mark whether this Node is unparsed, i.e. not the result of normal parsing
      Specified by:
      setUnparsed in interface Node
      Parameters:
      unparsed - whether to set the Node as unparsed or parsed.
    • setParent

      public void setParent(Node n)
      Specified by:
      setParent in interface Node
      Parameters:
      n - The Node to set as the parent. Mostly used internally. The various addChild or appendChild sorts of methods should use this to set the node's parent.
    • getParent

      public Node getParent()
      Specified by:
      getParent in interface Node
      Returns:
      this node's parent Node
    • addChild

      public void addChild(Node n)
      Description copied from interface: Node
      appends a child node to this Node
      Specified by:
      addChild in interface Node
      Parameters:
      n - the Node to append
    • addChild

      public void addChild(int i, Node n)
      Description copied from interface: Node
      inserts a child Node at a specific index, displacing the nodes after the index by 1.
      Specified by:
      addChild in interface Node
      Parameters:
      i - the (zero-based) index at which to insert the node
      n - the Node to insert
    • getChild

      public Node getChild(int i)
      Specified by:
      getChild in interface Node
      Parameters:
      i - the index of the Node to return
      Returns:
      the Node at the specific offset
    • setChild

      public void setChild(int i, Node n)
      Description copied from interface: Node
      Replace the node at index i
      Specified by:
      setChild in interface Node
      Parameters:
      i - the index
      n - the node
    • removeChild

      public Node removeChild(int i)
      Description copied from interface: Node
      Remove the node at index i. Any Nodes after i are shifted to the left.
      Specified by:
      removeChild in interface Node
      Parameters:
      i - the index at which to remove
      Returns:
      the removed Node
    • clearChildren

      public void clearChildren()
      Description copied from interface: Node
      Remove all the child nodes
      Specified by:
      clearChildren in interface Node
    • getChildCount

      public int getChildCount()
      Specified by:
      getChildCount in interface Node
      Returns:
      the number of child nodes
    • children

      public List<Node> children()
      Specified by:
      children in interface Node
    • getBeginOffset

      public int getBeginOffset()
      Specified by:
      getBeginOffset in interface Node
      Returns:
      the offset in the input source where the token begins, expressed in code units.
    • setBeginOffset

      public void setBeginOffset(int beginOffset)
      Description copied from interface: Node
      Set the offset where the token begins, expressed in code units.
      Specified by:
      setBeginOffset in interface Node
    • getEndOffset

      public int getEndOffset()
      Specified by:
      getEndOffset in interface Node
      Returns:
      the offset in the input source where the token ends, expressed in code units. This is actually the offset where the very next token would begin.
    • setEndOffset

      public void setEndOffset(int endOffset)
      Description copied from interface: Node
      Set the offset where the token ends, actually the location where the very next token should begin.
      Specified by:
      setEndOffset in interface Node
    • getChildNodes

      public freemarker.template.TemplateSequenceModel getChildNodes()
      Specified by:
      getChildNodes in interface freemarker.template.TemplateNodeModel
    • getParentNode

      public freemarker.template.TemplateNodeModel getParentNode()
      Specified by:
      getParentNode in interface freemarker.template.TemplateNodeModel
    • getNodeName

      public String getNodeName()
      Specified by:
      getNodeName in interface freemarker.template.TemplateNodeModel
    • getNodeType

      public String getNodeType()
      Specified by:
      getNodeType in interface freemarker.template.TemplateNodeModel
    • getNodeNamespace

      public String getNodeNamespace()
      Specified by:
      getNodeNamespace in interface freemarker.template.TemplateNodeModel
    • toString

      public String toString()
      Overrides:
      toString in class Object