List of usage examples for org.eclipse.jdt.core.dom InfixExpression hasExtendedOperands
public boolean hasExtendedOperands()
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
License:Apache License
/** * Helper method for {@link InfixExpression}s. Visit this {@link Expression} node, and its * children, as long as they are {@link InfixExpression} nodes of the same precedence. Accumulate * the operands and operators.//from w ww. j a v a 2s .c o m * @param precedence the precedence of the operators to collect * @param operands the output list of {@code n + 1} operands * @param operators the output list of {@code n} operators */ private static void walkInfix(int precedence, Expression expression, List<Expression> operands, List<String> operators) { if (expression.getNodeType() == ASTNode.INFIX_EXPRESSION) { InfixExpression infixExpression = (InfixExpression) expression; String myOperator = infixExpression.getOperator().toString(); if (PRECEDENCE.get(myOperator) == precedence) { walkInfix(precedence, infixExpression.getLeftOperand(), operands, operators); operators.add(myOperator); walkInfix(precedence, infixExpression.getRightOperand(), operands, operators); if (infixExpression.hasExtendedOperands()) { for (Expression extendedOperand : (List<Expression>) infixExpression.extendedOperands()) { operators.add(myOperator); walkInfix(precedence, extendedOperand, operands, operators); } } } else { operands.add(expression); } } else { operands.add(expression); } }
From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java
License:Open Source License
private CAstNode visit(InfixExpression n, WalkContext context) { Expression left = n.getLeftOperand(); ITypeBinding leftType = left.resolveTypeBinding(); int leftStartPosition = left.getStartPosition(); CAstNode leftNode = visitNode(left, context); int leftLength = n.getLeftOperand().getLength(); CAstNode result = createInfixExpression(n.getOperator(), leftType, leftStartPosition, leftLength, leftNode, n.getRightOperand(), context); if (n.hasExtendedOperands()) { // keep on adding operands on the right side leftLength = n.getRightOperand().getStartPosition() + n.getRightOperand().getLength() - leftStartPosition;// ww w .j av a2s . c o m for (Object o : n.extendedOperands()) { Expression operand = (Expression) o; result = createInfixExpression(n.getOperator(), leftType, leftStartPosition, leftLength, result, operand, context); if (leftType.isPrimitive() && operand.resolveTypeBinding().isPrimitive()) leftType = JDT2CAstUtils.promoteTypes(leftType, operand.resolveTypeBinding(), ast); // TODO: boxing else leftType = operand.resolveTypeBinding(); // leftStartPosition doesn't change, beginning is always the first operand leftLength = operand.getStartPosition() + operand.getLength() - leftStartPosition; } } return result; }
From source file:edu.cmu.cs.crystal.internal.ControlFlowVisitor.java
License:Open Source License
/** * Example: "Hello " + "World " + "How " + "Are " + "You?" * left + right + extOp1 + extOp2 + extOp3 *///from w w w .j a v a 2 s.c o m public boolean visit(InfixExpression node) { List<ControlFlowNode> cfns = null; ControlFlowNode leftCFN = controlFlowNode.newControlFlowNode(node.getLeftOperand()); ControlFlowNode rightCFN = controlFlowNode.newControlFlowNode(node.getRightOperand()); // Connect the back edges to the first operand (ie. left) controlFlowNode.moveEdges(ControlFlowNode.Direction.BACKWARDS, leftCFN); leftCFN.addEdge(ControlFlowNode.Direction.FORWARDS, rightCFN); // Add all extended operands if (node.hasExtendedOperands()) { cfns = createCFNListFromASTNodeList(node.extendedOperands()); ControlFlowNode cfn = cfns.get(0); rightCFN.addEdge(ControlFlowNode.Direction.FORWARDS, cfn); cfn = cfns.get(cfns.size() - 1); cfn.addEdge(ControlFlowNode.Direction.FORWARDS, controlFlowNode); } else rightCFN.addEdge(ControlFlowNode.Direction.FORWARDS, controlFlowNode); leftCFN.evaluate(); rightCFN.evaluate(); if (cfns != null) evaluate(cfns); return false; }
From source file:lang.java.jdt.internal.JdtAstToRascalAstConverter.java
License:Open Source License
public boolean visit(InfixExpression node) { IValue operator = values.string(node.getOperator().toString()); IValue leftSide = visitChild(node.getLeftOperand()); IValue rightSide = visitChild(node.getRightOperand()); IValueList extendedOperands = new IValueList(values); if (node.hasExtendedOperands()) { for (Iterator it = node.extendedOperands().iterator(); it.hasNext();) { Expression e = (Expression) it.next(); extendedOperands.add(visitChild(e)); }/*from www .j a v a 2 s. c o m*/ } ownValue = constructRascalNode(node, operator, leftSide, rightSide, extendedOperands.asList()); return false; }
From source file:org.autorefactor.refactoring.ASTSemanticMatcher.java
License:Open Source License
@Override public boolean match(final InfixExpression node, final Object other) { if (!node.hasExtendedOperands() && other instanceof InfixExpression) { InfixExpression ie = (InfixExpression) other; if (!ie.hasExtendedOperands() && isPassive(node.getLeftOperand()) && isPassive(node.getRightOperand()) && safeSubtreeMatch(node.getLeftOperand(), ie.getRightOperand()) && safeSubtreeMatch(node.getRightOperand(), ie.getLeftOperand())) { if (node.getOperator().equals(INFIX_TO_MIRROR_OPERATOR.get(ie.getOperator()))) { return true; } else if (Arrays.asList(InfixExpression.Operator.PLUS, InfixExpression.Operator.TIMES) .contains(ie.getOperator()) && node.getOperator().equals(ie.getOperator()) && hasType(node.getLeftOperand(), "short", "int", "long", "float", "double", "java.lang.Short", "java.lang.Integer", "java.lang.Long", "java.lang.Float", "java.lang.Double") && haveSameType(node.getLeftOperand(), node.getRightOperand())) { return true; }// ww w. j a v a 2 s .co m } } return super.match(node, other); }
From source file:org.autorefactor.refactoring.ASTSemanticMatcher.java
License:Open Source License
private boolean matchAssignmentWithAndWithoutEqual(final Assignment node, final Assignment assignment) { if (Assignment.Operator.ASSIGN.equals(node.getOperator()) && node.getRightHandSide() instanceof InfixExpression) { InfixExpression infixExpr = (InfixExpression) node.getRightHandSide(); if (!infixExpr.hasExtendedOperands() && Arrays.asList(Assignment.Operator.PLUS_ASSIGN, Assignment.Operator.MINUS_ASSIGN, Assignment.Operator.TIMES_ASSIGN, Assignment.Operator.DIVIDE_ASSIGN, Assignment.Operator.BIT_AND_ASSIGN, Assignment.Operator.BIT_OR_ASSIGN, Assignment.Operator.BIT_XOR_ASSIGN, Assignment.Operator.REMAINDER_ASSIGN, Assignment.Operator.LEFT_SHIFT_ASSIGN, Assignment.Operator.RIGHT_SHIFT_SIGNED_ASSIGN, Assignment.Operator.RIGHT_SHIFT_UNSIGNED_ASSIGN).contains(assignment.getOperator()) && ASSIGN_TO_INFIX_OPERATOR.get(assignment.getOperator()).equals(infixExpr.getOperator())) { return safeSubtreeMatch(node.getLeftHandSide(), assignment.getLeftHandSide()) && safeSubtreeMatch(infixExpr.getLeftOperand(), assignment.getLeftHandSide()) && safeSubtreeMatch(infixExpr.getRightOperand(), assignment.getRightHandSide()); }//from ww w .j a v a2 s .com } return false; }
From source file:org.autorefactor.refactoring.ASTSemanticMatcher.java
License:Open Source License
private boolean match0(final Assignment assignment, final Expression prefixOrPostfixOperand, final Operator infixAssociatedOperator, final Assignment.Operator assignmentAssociatedOperator) { if (Assignment.Operator.ASSIGN.equals(assignment.getOperator()) && assignment.getRightHandSide() instanceof InfixExpression) { InfixExpression infixExpr = (InfixExpression) assignment.getRightHandSide(); if (!infixExpr.hasExtendedOperands() && infixAssociatedOperator.equals(infixExpr.getOperator())) { if (isOneLiteral(infixExpr.getRightOperand())) { return safeSubtreeMatch(prefixOrPostfixOperand, assignment.getLeftHandSide()) && safeSubtreeMatch(prefixOrPostfixOperand, infixExpr.getLeftOperand()); } else if (Operator.PLUS.equals(infixExpr.getOperator()) && isOneLiteral(infixExpr.getLeftOperand())) { return safeSubtreeMatch(prefixOrPostfixOperand, assignment.getLeftHandSide()) && safeSubtreeMatch(prefixOrPostfixOperand, infixExpr.getRightOperand()); }/*from w w w . j av a2 s . com*/ } } else if (Arrays.asList(Assignment.Operator.PLUS_ASSIGN, Assignment.Operator.MINUS_ASSIGN).contains( assignment.getOperator()) && assignmentAssociatedOperator.equals(assignment.getOperator())) { Object assignmentExpr = assignment.resolveConstantExpressionValue(); if (assignmentExpr instanceof Number && ((Number) assignmentExpr).longValue() == 1) { return safeSubtreeMatch(prefixOrPostfixOperand, assignment.getLeftHandSide()); } } return false; }
From source file:org.autorefactor.refactoring.ForLoopHelper.java
License:Open Source License
private static ForLoopContent getIndexOnIterable(final Expression condition) { final InfixExpression ie = as(condition, InfixExpression.class); if (ie != null && !ie.hasExtendedOperands()) { final Expression leftOp = ie.getLeftOperand(); final Expression rightOp = ie.getRightOperand(); if (hasOperator(ie, LESS)) { return buildForLoopContent(leftOp, rightOp); } else if (hasOperator(ie, GREATER)) { return buildForLoopContent(rightOp, leftOp); }//from w w w . j a v a 2 s .c o m } return null; }
From source file:org.autorefactor.refactoring.rules.BooleanEqualsRatherThanNullCheckRefactoring.java
License:Open Source License
@Override public boolean visit(InfixExpression node) { if (hasOperator(node, CONDITIONAL_AND, CONDITIONAL_OR)) { final Expression leftOperand = node.getLeftOperand(); final Expression rightOperand = node.getRightOperand(); final InfixExpression condition = as(leftOperand, InfixExpression.class); final boolean isNullCheck = hasOperator(condition, EQUALS); final boolean isAndExpr = hasOperator(node, CONDITIONAL_AND); if (!node.hasExtendedOperands() && isNullCheck ^ isAndExpr && condition != null && hasOperator(condition, EQUALS, NOT_EQUALS)) { Expression firstExpr = null; if (isNullLiteral(condition.getLeftOperand())) { firstExpr = condition.getRightOperand(); } else if (isNullLiteral(condition.getRightOperand())) { firstExpr = condition.getLeftOperand(); }/*from w w w . j a v a2 s. c om*/ Expression secondExpr = null; final PrefixExpression negateSecondExpr = as(rightOperand, PrefixExpression.class); final boolean isPositiveExpr; if (negateSecondExpr != null && hasOperator(negateSecondExpr, NOT)) { secondExpr = negateSecondExpr.getOperand(); isPositiveExpr = false; } else { secondExpr = rightOperand; isPositiveExpr = true; } if (firstExpr != null && hasType(firstExpr, "java.lang.Boolean") && isPassive(firstExpr) && match(new ASTSemanticMatcher(), firstExpr, secondExpr)) { replaceNullCheck(node, firstExpr, isNullCheck, isAndExpr, isPositiveExpr); return DO_NOT_VISIT_SUBTREE; } } } return VISIT_SUBTREE; }
From source file:org.autorefactor.refactoring.rules.ComparisonRefactoring.java
License:Open Source License
@Override public boolean visit(InfixExpression node) { if (!node.hasExtendedOperands()) { if (maybeStandardizeComparison(node, node.getLeftOperand(), node.getRightOperand()) == DO_NOT_VISIT_SUBTREE) { return DO_NOT_VISIT_SUBTREE; }/*from w w w .ja v a 2 s . c o m*/ return maybeStandardizeComparison(node, node.getRightOperand(), node.getLeftOperand()); } return VISIT_SUBTREE; }