Java Code Examples for org.eclipse.jdt.core.dom.InfixExpression#extendedOperands()
The following examples show how to use
org.eclipse.jdt.core.dom.InfixExpression#extendedOperands() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InvertBooleanUtility.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private static Expression getInversedAndOrExpression(ASTRewrite rewrite, InfixExpression infixExpression, Operator newOperator, SimpleNameRenameProvider provider) { InfixExpression newExpression = rewrite.getAST().newInfixExpression(); newExpression.setOperator(newOperator); int newOperatorPrecedence = OperatorPrecedence.getOperatorPrecedence(newOperator); Expression leftOperand = getInversedExpression(rewrite, infixExpression.getLeftOperand(), provider); newExpression.setLeftOperand(parenthesizeIfRequired(leftOperand, newOperatorPrecedence)); Expression rightOperand = getInversedExpression(rewrite, infixExpression.getRightOperand(), provider); newExpression.setRightOperand(parenthesizeIfRequired(rightOperand, newOperatorPrecedence)); List<Expression> extraOperands = infixExpression.extendedOperands(); List<Expression> newExtraOperands = newExpression.extendedOperands(); for (int i = 0; i < extraOperands.size(); i++) { Expression extraOperand = getInversedExpression(rewrite, extraOperands.get(i), provider); newExtraOperands.add(parenthesizeIfRequired(extraOperand, newOperatorPrecedence)); } return newExpression; }
Example 2
Source File: InvertBooleanUtility.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private static int isOperatorSelected(InfixExpression infixExpression, int offset, int length) { ASTNode left = infixExpression.getLeftOperand(); ASTNode right = infixExpression.getRightOperand(); if (isSelectingOperator(left, right, offset, length)) { return ASTNodes.getExclusiveEnd(left); } List<Expression> extended = infixExpression.extendedOperands(); for (int i = 0; i < extended.size(); i++) { left = right; right = extended.get(i); if (isSelectingOperator(left, right, offset, length)) { return ASTNodes.getExclusiveEnd(left); } } return -1; }
Example 3
Source File: InvertBooleanUtility.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private static void breakInfixOperationAtOperation(ASTRewrite rewrite, Expression expression, Operator operator, int operatorOffset, boolean removeParentheses, Expression[] res) { if (expression.getStartPosition() + expression.getLength() <= operatorOffset) { // add to the left res[0] = combineOperands(rewrite, res[0], expression, removeParentheses, operator); return; } if (operatorOffset <= expression.getStartPosition()) { // add to the right res[1] = combineOperands(rewrite, res[1], expression, removeParentheses, operator); return; } if (!(expression instanceof InfixExpression)) { throw new IllegalArgumentException("Cannot break up non-infix expression"); //$NON-NLS-1$ } InfixExpression infixExpression = (InfixExpression) expression; if (infixExpression.getOperator() != operator) { throw new IllegalArgumentException("Incompatible operator"); //$NON-NLS-1$ } breakInfixOperationAtOperation(rewrite, infixExpression.getLeftOperand(), operator, operatorOffset, removeParentheses, res); breakInfixOperationAtOperation(rewrite, infixExpression.getRightOperand(), operator, operatorOffset, removeParentheses, res); List<Expression> extended = infixExpression.extendedOperands(); for (int i = 0; i < extended.size(); i++) { breakInfixOperationAtOperation(rewrite, extended.get(i), operator, operatorOffset, removeParentheses, res); } }
Example 4
Source File: AdvancedQuickAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static Expression getInversedAndOrExpression(ASTRewrite rewrite, InfixExpression infixExpression, Operator newOperator, SimpleNameRenameProvider provider) { InfixExpression newExpression= rewrite.getAST().newInfixExpression(); newExpression.setOperator(newOperator); int newOperatorPrecedence= OperatorPrecedence.getOperatorPrecedence(newOperator); // Expression leftOperand= getInversedExpression(rewrite, infixExpression.getLeftOperand(), provider); newExpression.setLeftOperand(parenthesizeIfRequired(leftOperand, newOperatorPrecedence)); Expression rightOperand= getInversedExpression(rewrite, infixExpression.getRightOperand(), provider); newExpression.setRightOperand(parenthesizeIfRequired(rightOperand, newOperatorPrecedence)); List<Expression> extraOperands= infixExpression.extendedOperands(); List<Expression> newExtraOperands= newExpression.extendedOperands(); for (int i= 0; i < extraOperands.size(); i++) { Expression extraOperand= getInversedExpression(rewrite, extraOperands.get(i), provider); newExtraOperands.add(parenthesizeIfRequired(extraOperand, newOperatorPrecedence)); } return newExpression; }
Example 5
Source File: AdvancedQuickAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static int isOperatorSelected(InfixExpression infixExpression, int offset, int length) { ASTNode left= infixExpression.getLeftOperand(); ASTNode right= infixExpression.getRightOperand(); if (isSelectingOperator(left, right, offset, length)) { return ASTNodes.getExclusiveEnd(left); } List<Expression> extended= infixExpression.extendedOperands(); for (int i= 0; i < extended.size(); i++) { left= right; right= extended.get(i); if (isSelectingOperator(left, right, offset, length)) { return ASTNodes.getExclusiveEnd(left); } } return -1; }
Example 6
Source File: AdvancedQuickAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static void breakInfixOperationAtOperation(ASTRewrite rewrite, Expression expression, Operator operator, int operatorOffset, boolean removeParentheses, Expression[] res) { if (expression.getStartPosition() + expression.getLength() <= operatorOffset) { // add to the left res[0]= combineOperands(rewrite, res[0], expression, removeParentheses, operator); return; } if (operatorOffset <= expression.getStartPosition()) { // add to the right res[1]= combineOperands(rewrite, res[1], expression, removeParentheses, operator); return; } if (!(expression instanceof InfixExpression)) { throw new IllegalArgumentException("Cannot break up non-infix expression"); //$NON-NLS-1$ } InfixExpression infixExpression= (InfixExpression) expression; if (infixExpression.getOperator() != operator) { throw new IllegalArgumentException("Incompatible operator"); //$NON-NLS-1$ } breakInfixOperationAtOperation(rewrite, infixExpression.getLeftOperand(), operator, operatorOffset, removeParentheses, res); breakInfixOperationAtOperation(rewrite, infixExpression.getRightOperand(), operator, operatorOffset, removeParentheses, res); List<Expression> extended= infixExpression.extendedOperands(); for (int i= 0; i < extended.size(); i++) { breakInfixOperationAtOperation(rewrite, extended.get(i), operator, operatorOffset, removeParentheses, res); } }
Example 7
Source File: TreedBuilder.java From compiler with Apache License 2.0 | 5 votes |
@Override public boolean visit(InfixExpression node) { List<?> l = node.extendedOperands(); if (l != null && l.size() > 10 - 2) return false; return super.visit(node); }
Example 8
Source File: QuickAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static void collectInfixPlusOperands(Expression expression, List<Expression> collector) { if (expression instanceof InfixExpression && ((InfixExpression)expression).getOperator() == InfixExpression.Operator.PLUS) { InfixExpression infixExpression= (InfixExpression)expression; collectInfixPlusOperands(infixExpression.getLeftOperand(), collector); collectInfixPlusOperands(infixExpression.getRightOperand(), collector); List<Expression> extendedOperands= infixExpression.extendedOperands(); for (Iterator<Expression> iter= extendedOperands.iterator(); iter.hasNext();) { collectInfixPlusOperands(iter.next(), collector); } } else { collector.add(expression); } }
Example 9
Source File: BindingSignatureVisitor.java From JDeodorant with MIT License | 5 votes |
public boolean visit(InfixExpression expr) { handleExpression(expr.getLeftOperand()); bindingKeys.add(expr.getOperator().toString()); handleExpression(expr.getRightOperand()); List extendedOperands = expr.extendedOperands(); for (int i = 0; i < extendedOperands.size(); i++){ bindingKeys.add(expr.getOperator().toString()); handleExpression((Expression) extendedOperands.get(i)); } return false; }
Example 10
Source File: InfixExpressionWriter.java From juniversal with MIT License | 5 votes |
@SuppressWarnings("unchecked") @Override public void write(InfixExpression infixExpression) { InfixExpression.Operator operator = infixExpression.getOperator(); if (operator == InfixExpression.Operator.RIGHT_SHIFT_UNSIGNED) { write("rightShiftUnsigned("); writeNode(infixExpression.getLeftOperand()); // Skip spaces before the >>> but if there's a newline (or comments) there, copy them skipSpacesAndTabs(); copySpaceAndComments(); matchAndWrite(">>>", ","); copySpaceAndComments(); writeNode(infixExpression.getRightOperand()); write(")"); } else { writeNode(infixExpression.getLeftOperand()); copySpaceAndComments(); String operatorToken = this.equivalentOperators.get(infixExpression.getOperator()); matchAndWrite(operatorToken); copySpaceAndComments(); writeNode(infixExpression.getRightOperand()); if (infixExpression.hasExtendedOperands()) { for (Expression extendedOperand : (List<Expression>) infixExpression.extendedOperands()) { copySpaceAndComments(); matchAndWrite(operatorToken); copySpaceAndComments(); writeNode(extendedOperand); } } } }
Example 11
Source File: AbstractLoopUtilities.java From JDeodorant with MIT License | 4 votes |
public static boolean isVariableLeftOperand(SimpleName variable, InfixExpression infixExpression) { boolean leftOperandIsVariable = false; Expression leftOperand = infixExpression.getLeftOperand(); //Expression rightOperand = infixExpression.getRightOperand(); IBinding infixVariableBinding = variable.resolveBinding(); if (leftOperand instanceof SimpleName) { SimpleName leftOperandSimpleName = (SimpleName) leftOperand; IBinding leftOperandBinding = leftOperandSimpleName.resolveBinding(); if (leftOperandBinding.isEqualTo(infixVariableBinding)) { leftOperandIsVariable = true; } } else if (leftOperand instanceof InfixExpression) { InfixExpression infixLeftOperand = (InfixExpression) leftOperand; boolean left = isVariableLeftOperand(variable, infixLeftOperand); boolean right = isVariableRightOperand(variable, infixLeftOperand); List<Expression> extendedOperands = infixLeftOperand.extendedOperands(); boolean variableFoundInExtendedOperands = false; for (Expression expression : extendedOperands) { if (expression instanceof SimpleName) { SimpleName simpleName = (SimpleName) expression; IBinding simpleNameBinding = simpleName.resolveBinding(); if (simpleNameBinding.isEqualTo(infixVariableBinding)) { variableFoundInExtendedOperands = true; break; } } } if (left || right || variableFoundInExtendedOperands) { leftOperandIsVariable = true; } } return leftOperandIsVariable; }
Example 12
Source File: AbstractLoopUtilities.java From JDeodorant with MIT License | 4 votes |
private static boolean isVariableRightOperand(SimpleName variable, InfixExpression infixExpression) { boolean rightOperandIsVariable = false; //Expression leftOperand = infixExpression.getLeftOperand(); Expression rightOperand = infixExpression.getRightOperand(); IBinding infixVariableBinding = variable.resolveBinding(); if (rightOperand instanceof SimpleName) { SimpleName rightOperandSimpleName = (SimpleName) rightOperand; IBinding rightOperandBinding = rightOperandSimpleName.resolveBinding(); if (rightOperandBinding.isEqualTo(infixVariableBinding)) { rightOperandIsVariable = true; } } else if (rightOperand instanceof InfixExpression) { InfixExpression infixRightOperand = (InfixExpression) rightOperand; boolean left = isVariableLeftOperand(variable, infixRightOperand); boolean right = isVariableRightOperand(variable, infixRightOperand); List<Expression> extendedOperands = infixRightOperand.extendedOperands(); boolean variableFoundInExtendedOperands = false; for (Expression expression : extendedOperands) { if (expression instanceof SimpleName) { SimpleName simpleName = (SimpleName) expression; IBinding simpleNameBinding = simpleName.resolveBinding(); if (simpleNameBinding.isEqualTo(infixVariableBinding)) { variableFoundInExtendedOperands = true; break; } } } if (left || right || variableFoundInExtendedOperands) { rightOperandIsVariable = true; } } return rightOperandIsVariable; }
Example 13
Source File: InfixExpressionWriter.java From juniversal with MIT License | 4 votes |
@SuppressWarnings("unchecked") @Override public void write(ASTNode node) { InfixExpression infixExpression = (InfixExpression) node; // TODO: Add spaces to left & right of binary operators if needed, per Swift's rules about needing space on // both sides or neither InfixExpression.Operator operator = infixExpression.getOperator(); if (operator == InfixExpression.Operator.RIGHT_SHIFT_UNSIGNED) { // TODO: Handle this write("rightShiftUnsigned("); swiftASTWriters.writeNode(infixExpression.getLeftOperand()); // Skip spaces before the >>> but if there's a newline (or comments) there, copy them skipSpacesAndTabs(); copySpaceAndComments(); matchAndWrite(">>>", ","); copySpaceAndComments(); swiftASTWriters.writeNode(infixExpression.getRightOperand()); write(")"); } else { swiftASTWriters.writeNode(infixExpression.getLeftOperand()); copySpaceAndComments(); String operatorToken = this.equivalentOperators.get(infixExpression.getOperator()); matchAndWrite(operatorToken); copySpaceAndComments(); swiftASTWriters.writeNode(infixExpression.getRightOperand()); if (infixExpression.hasExtendedOperands()) { for (Expression extendedOperand : (List<Expression>) infixExpression.extendedOperands()) { copySpaceAndComments(); matchAndWrite(operatorToken); copySpaceAndComments(); swiftASTWriters.writeNode(extendedOperand); } } } }