Package org.antlr.v4.runtime.tree

Examples of org.antlr.v4.runtime.tree.TerminalNode


    forEachChild(context, new Function<ParseTree, Void>() {
      @Override
      public Void apply(ParseTree input) {
        if (input instanceof TerminalNode) {
          TerminalNode terminalNode = (TerminalNode) input;
          if (terminalNode.getSymbol().getType() == JavaParser.Identifier) {
            IdentifierWithTypeArguments element =
                createNode(input, IdentifierWithTypeArguments.class);
            element.setIdentifier(getAdapter(IdentifierAdapter.class).adapt(terminalNode));
            identifierWithTypeArguments.add(element);
          }
View Full Code Here


    ExpressionContext expressionContext = getChild(context, ExpressionContext.class);
    if (expressionContext != null) {
      scopedExpression.setScope(getAdapter(ExpressionAdapter.class).adapt(expressionContext));
    }

    TerminalNode identifierNode = getTerminalNode(context, JavaParser.Identifier);
    if (identifierNode != null) {
      scopedExpression.setExpression(getAdapter(IdentifierAdapter.class).adapt(identifierNode));
      return scopedExpression;
    }

    TerminalNode thisNode = getTerminalNode(context, JavaParser.THIS);
    if (thisNode != null) {
      scopedExpression.setExpression(createNode(thisNode, ThisExpression.class));
      return scopedExpression;
    }

    TerminalNode newNode = getTerminalNode(context, JavaParser.NEW);
    if (newNode != null) {
      ClassInstantiation newInvocation = createNode(newNode, context, ClassInstantiation.class);

      NonWildcardTypeArgumentsContext nonWildcardTypeArgumentsContext =
          getChild(context, NonWildcardTypeArgumentsContext.class);
      if (nonWildcardTypeArgumentsContext != null) {
        newInvocation.setTypeArguments(getAdapter(NonWildcardTypeArgumentsAdapter.class).adapt(
            nonWildcardTypeArgumentsContext));
      }

      InnerCreatorContext innerCreatorContext = getChild(context, InnerCreatorContext.class);
      if (innerCreatorContext != null) {
        TerminalNode typeIdentifierNode =
            getTerminalNode(innerCreatorContext, JavaParser.Identifier);
        NonWildcardTypeArgumentsOrDiamondContext nonWildcardTypeArgumentsOrDiamondContext =
            getChild(innerCreatorContext, NonWildcardTypeArgumentsOrDiamondContext.class);
        TypeWithArguments typeWithArguments =
            createNode(typeIdentifierNode,
                nonWildcardTypeArgumentsOrDiamondContext == null
                    ? typeIdentifierNode
                    : nonWildcardTypeArgumentsOrDiamondContext,
                TypeWithArguments.class);
        typeWithArguments.setIdentifiersWithTypeArguments(
            convertIdentifiersWithTypeArguments(innerCreatorContext));
        newInvocation.setType(typeWithArguments);

        ClassCreatorRestContext classCreatorRestContext =
            getChild(innerCreatorContext, ClassCreatorRestContext.class);
        if (classCreatorRestContext != null) {
          ArgumentsContext arguments = getChild(classCreatorRestContext, ArgumentsContext.class);
          if (arguments != null) {
            newInvocation.setArguments(getAdapter(ArgumentsAdapter.class).adapt(arguments));
          }

          ClassBodyContext classBodyContext =
              getChild(classCreatorRestContext, ClassBodyContext.class);
          if (classBodyContext != null) {
            newInvocation.setMemberDeclarations(
                getAdapter(ClassBodyAdapter.class).adapt(classBodyContext));
          }
        }
      }

      scopedExpression.setExpression(newInvocation);
      return scopedExpression;
    }

    TerminalNode superNode = getTerminalNode(context, JavaParser.SUPER);
    if (superNode != null) {
      SuperInvocation superInvocation = createNode(superNode, context, SuperInvocation.class);

      SuperSuffixContext superSuffixContext = getChild(context, SuperSuffixContext.class);
      if (superSuffixContext != null) {
View Full Code Here

  @Override
  public TypeParameter adapt(TypeParameterContext context) {
    TypeParameter typeParameter = createNode(context);

    TerminalNode identifierNode = getTerminalNode(context, JavaParser.Identifier);
    if (identifierNode != null) {
      typeParameter.setName(getAdapter(IdentifierAdapter.class).adapt(identifierNode));
    }

    TypeBoundContext typeBoundContext = getChild(context, TypeBoundContext.class);
View Full Code Here

  @Override
  public AnnotationDeclaration adapt(AnnotationTypeDeclarationContext context) {
    AnnotationDeclaration annotationDeclaration = createNode(context);

    TerminalNode identifierNode = getTerminalNode(context, JavaParser.Identifier);
    if (identifierNode != null) {
      annotationDeclaration.setName(getAdapter(IdentifierAdapter.class).adapt(identifierNode));
    }

    AnnotationTypeBodyContext annotationTypeBodyContext =
View Full Code Here

    forEachChild(context, ClassOrInterfaceModifierContext.class,
        new Function<ClassOrInterfaceModifierContext, Void>() {
      @Override
      public Void apply(ClassOrInterfaceModifierContext context) {
        if (context.getChildCount() > 0 && context.getChild(0) instanceof TerminalNode) {
          TerminalNode child = (TerminalNode) context.getChild(0);
          int type = child.getSymbol().getType();
          switch (type) {
          case JavaParser.PUBLIC:
            node.setPublic(true);
            break;
          case JavaParser.PROTECTED:
View Full Code Here

    forEachChild(context, ModifierContext.class, new Function<ModifierContext, Void>() {
      @Override
      public Void apply(ModifierContext context) {
        if (context.getChildCount() > 0 && context.getChild(0) instanceof TerminalNode) {
          TerminalNode child = (TerminalNode) context.getChild(0);
          int type = child.getSymbol().getType();
          switch (type) {
          case JavaParser.NATIVE:
            node.setNative(true);
            break;
          case JavaParser.SYNCHRONIZED:
View Full Code Here

  public SuperInvocation adapt(SuperSuffixContext context) {
    throw new RuntimeException("Not supported");
  }

  public SuperInvocation adapt(SuperSuffixContext context, SuperInvocation superInvocation) {
    TerminalNode identifierNode = getTerminalNode(context, JavaParser.Identifier);
    if (identifierNode != null) {
      superInvocation.setName(getAdapter(IdentifierAdapter.class).adapt(identifierNode));
    }

    ArgumentsContext argumentsContext = getChild(context, ArgumentsContext.class);
View Full Code Here

  public Invocation adapt(ExplicitGenericInvocationSuffixContext context) {
    return adapt(context, Collections.<Type>emptyList());
  }

  public Invocation adapt(ExplicitGenericInvocationSuffixContext context, List<Type> typeList) {
    TerminalNode firstTerminal = getChild(context, TerminalNode.class);
    if (firstTerminal != null) {
      switch (firstTerminal.getSymbol().getType()) {
      case JavaParser.SUPER: {
        SuperInvocation superInvocation = createNode(context, SuperInvocation.class);
        superInvocation.setTypeArguments(typeList);

        SuperSuffixContext superSuffixContext = getChild(context, SuperSuffixContext.class);
View Full Code Here

  @Override
  public NameValuePair adapt(ElementValuePairContext context) {
    NameValuePair values = createNode(context);

    TerminalNode identifierNode = getTerminalNode(context, JavaParser.Identifier);
    if (identifierNode != null) {
      values.setName(getAdapter(IdentifierAdapter.class).adapt(identifierNode));
    }

    ElementValueContext elementValueContext = getChild(context, ElementValueContext.class);
View Full Code Here

    TypeContext typeContext = getChild(context, TypeContext.class);
    if (typeContext != null) {
      methodDeclaration.setReturnType(getAdapter(TypeAdapter.class).adapt(typeContext));
    } else {
      TerminalNode voidNode = getTerminalNode(context, JavaParser.VOID);
      if (voidNode != null) {
        methodDeclaration.setReturnType(createNode(voidNode, VoidType.class));
      }
    }

    TerminalNode identifierNode = getTerminalNode(context, JavaParser.Identifier);
    if (identifierNode != null) {
      methodDeclaration.setName(getAdapter(IdentifierAdapter.class).adapt(identifierNode));
    }

    FormalParametersContext formalParametersContext =
View Full Code Here

TOP

Related Classes of org.antlr.v4.runtime.tree.TerminalNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.