Package com.bacoder.parser.java.JavaParser

Examples of com.bacoder.parser.java.JavaParser.ExpressionContext


        getChild(context, StatementExpressionContext.class);
    if (statementExpressionContext != null) {
      ExpressionStatement expressionStatement =
          createNode(statementExpressionContext, ExpressionStatement.class);

      ExpressionContext expressionContext =
          getChild(statementExpressionContext, ExpressionContext.class);
      if (expressionContext != null) {
        expressionStatement.setExpression(
            getAdapter(ExpressionAdapter.class).adapt(expressionContext));
      }
View Full Code Here


          @Override
          public SwitchLabel apply(SwitchLabelContext context) {
            ConstantExpressionContext constantExpressionContext =
                getChild(context, ConstantExpressionContext.class);
            if (constantExpressionContext != null) {
              ExpressionContext expressionContext =
                  getChild(constantExpressionContext, ExpressionContext.class);
              if (expressionContext != null) {
                return getAdapter(ExpressionAdapter.class).adapt(expressionContext);
              }
View Full Code Here

      doWhileStatement.setStatement(getAdapter(StatementAdapter.class).adapt(statementContext));
    }

    ParExpressionContext parExpressionContext = getChild(context, ParExpressionContext.class);
    if (parExpressionContext != null) {
      ExpressionContext expressionContext = getChild(parExpressionContext, ExpressionContext.class);
      if (expressionContext != null) {
        doWhileStatement.setCondition(getAdapter(ExpressionAdapter.class).adapt(expressionContext));
      }
    }
View Full Code Here

            loopControl.setInitExpressions(
                getAdapter(ExpressionListAdapter.class).adapt(expressionListContext));
          }
        }

        ExpressionContext expressionContext = getChild(forControlContext, ExpressionContext.class);
        if (expressionContext != null) {
          loopControl.setCondition(getAdapter(ExpressionAdapter.class).adapt(expressionContext));
        }

        ForUpdateContext forUpdateContext = getChild(forControlContext, ForUpdateContext.class);
        if (forUpdateContext != null) {
          ExpressionListContext expressionListContext =
              getChild(forUpdateContext, ExpressionListContext.class);
          if (expressionListContext != null) {
            loopControl.setUpdateExpressions(
                getAdapter(ExpressionListAdapter.class).adapt(expressionListContext));
          }
        }

        forStatement.setControl(loopControl);

      } else {
        ForEachControl forEachControl =
            createNode(enhancedForControlContext, ForEachControl.class);
        setModifiers(enhancedForControlContext, forEachControl);

        TypeContext typeContext = getChild(enhancedForControlContext, TypeContext.class);
        if (typeContext != null) {
          forEachControl.setType(getAdapter(TypeAdapter.class).adapt(typeContext));
        }

        TerminalNode identifierNode =
            getTerminalNode(enhancedForControlContext, JavaParser.Identifier);
        if (identifierNode != null) {
          forEachControl.setVariable(getAdapter(IdentifierAdapter.class).adapt(identifierNode));
        }

        ExpressionContext expressionContext =
            getChild(enhancedForControlContext, ExpressionContext.class);
        if (expressionContext != null) {
          forEachControl.setIterable(
              getAdapter(ExpressionAdapter.class).adapt(expressionContext));
        }
View Full Code Here

  }

  protected ReturnStatement processReturnStatement(StatementContext context) {
    ReturnStatement returnStatement = createNode(context, ReturnStatement.class);

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

    return returnStatement;
View Full Code Here

  }

  protected ThrowStatement processThrowStatement(StatementContext context) {
    ThrowStatement throwStatement = createNode(context, ThrowStatement.class);

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

    return throwStatement;
View Full Code Here

                  resource.setDimensions(
                      getAdapter(ArrayDimensionsAdapter.class).adapt(variableDeclaratorIdContext));
                }

                ExpressionContext expressionContext = getChild(context, ExpressionContext.class);
                if (expressionContext != null) {
                  resource.setInitializer(
                      getAdapter(ExpressionAdapter.class).adapt(expressionContext));
                }
View Full Code Here

    return whileStatement;
  }

  private Expression processParExpression(ParExpressionContext parExpressionContext) {
    if (parExpressionContext != null) {
      ExpressionContext expressionContext =
          getChild(parExpressionContext, ExpressionContext.class);
      if (expressionContext != null) {
        return getAdapter(ExpressionAdapter.class).adapt(expressionContext);
      }
    }
View Full Code Here

    if (hasTerminalNode(context, JavaParser.LBRACK)) {
      ArrayAccess arrayAccess = createNode(context, ArrayAccess.class);

      if (context.getChildCount() > 0 && context.getChild(0) instanceof ExpressionContext) {
        ExpressionContext expressionContext = (ExpressionContext) context.getChild(0);
        arrayAccess.setArray(getAdapter(ExpressionAdapter.class).adapt(expressionContext));
      }

      if (context.getChildCount() > 2 && context.getChild(2) instanceof ExpressionContext) {
        ExpressionContext expressionContext = (ExpressionContext) context.getChild(2);
        arrayAccess.setIndex(getAdapter(ExpressionAdapter.class).adapt(expressionContext));
      }

      return arrayAccess;
    }

    if (context.getChildCount() > 2
        && context.getChild(0) instanceof ExpressionContext
        && isTerminalNode(context, 1, JavaParser.LPAREN)) {
      return processExpressionInvocation(context);
    }

    if (context.getChildCount() > 0 && isTerminalNode(context, 0, JavaParser.NEW)) {
      return processCreator(context);
    }

    if (context.getChildCount() > 0
        && context.getChild(0) instanceof TerminalNode
        && ((TerminalNode) context.getChild(0)).getSymbol().getType() == JavaParser.LPAREN) {
      TypeCast typeCast = createNode(context, TypeCast.class);

      TypeContext typeContext = getChild(context, TypeContext.class);
      if (typeContext != null) {
        typeCast.setType(getAdapter(TypeAdapter.class).adapt(typeContext));
      }

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

      return typeCast;
    }

    if (context.getChildCount() == 2
        && context.getChild(1) instanceof TerminalNode
        && POSTFIX_OPERATOR_MAP.containsKey(
            ((TerminalNode) context.getChild(1)).getSymbol().getType())) {
      PostfixExpression postfixExpression = createNode(context, PostfixExpression.class);

      postfixExpression.setOperator(
          POSTFIX_OPERATOR_MAP.get(((TerminalNode) context.getChild(1)).getSymbol().getType()));

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

      return postfixExpression;
    }

    if (context.getChildCount() == 2
        && context.getChild(0) instanceof TerminalNode
        && PREFIX_OPERATOR_MAP.containsKey(
            ((TerminalNode) context.getChild(0)).getSymbol().getType())) {
      PrefixExpression prefixExpression = createNode(context, PrefixExpression.class);

      prefixExpression.setOperator(
          PREFIX_OPERATOR_MAP.get(((TerminalNode) context.getChild(0)).getSymbol().getType()));

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

      return prefixExpression;
    }

    if (context.getChildCount() > 2
        && context.getChild(1) instanceof TerminalNode
        && INFIX_OPERATOR_MAP.containsKey(
            ((TerminalNode) context.getChild(1)).getSymbol().getType())
        && context.getChild(0) instanceof ExpressionContext
        && context.getChild(context.getChildCount() - 1) instanceof ExpressionContext) {
      InfixExpression.Operator operator = null;
      if (context.getChildCount() == 3) {
        operator =
            INFIX_OPERATOR_MAP.get(((TerminalNode) context.getChild(1)).getSymbol().getType());
      } else if (context.getChildCount() == 4
          && isTerminalNode(context, 1, JavaParser.LT)
          && isTerminalNode(context, 2, JavaParser.LT)) {
        operator = InfixExpression.Operator.LEFT_SHIFT;
      } else if (context.getChildCount() == 4
          && isTerminalNode(context, 1, JavaParser.GT)
          && isTerminalNode(context, 2, JavaParser.GT)) {
        operator = InfixExpression.Operator.SIGNED_RIGHT_SHIFT;
      } else if (context.getChildCount() == 5
          && isTerminalNode(context, 1, JavaParser.GT)
          && isTerminalNode(context, 2, JavaParser.GT)
          && isTerminalNode(context, 3, JavaParser.GT)) {
        operator = InfixExpression.Operator.UNSIGNED_RIGHT_SHIFT;
      }

      if (operator != null) {
        InfixExpression infixExpression = createNode(context, InfixExpression.class);
        infixExpression.setLeftHandSide(
            getAdapter(ExpressionAdapter.class).adapt((ExpressionContext) context.getChild(0)));
        infixExpression.setOperator(operator);
        infixExpression.setRightHandSide(
            getAdapter(ExpressionAdapter.class).adapt(
                (ExpressionContext) context.getChild(context.getChildCount() - 1)));
        return infixExpression;
      }
    }

    if (hasTerminalNode(context, JavaParser.INSTANCEOF)) {
      InstanceOf instanceOf = createNode(context, InstanceOf.class);

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

      TypeContext typeContext = getChild(context, TypeContext.class);
View Full Code Here

    return null;
  }

  protected Invocation processExpressionInvocation(ExpressionContext context) {
    ExpressionContext expressionContext = getChild(context, ExpressionContext.class);
    if (expressionContext == null) {
      return null;
    }

    Expression expression = getAdapter(ExpressionAdapter.class).adapt(expressionContext);
View Full Code Here

TOP

Related Classes of com.bacoder.parser.java.JavaParser.ExpressionContext

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.