Java Code Examples for org.eclipse.jdt.core.dom.InfixExpression#hasExtendedOperands()
The following examples show how to use
org.eclipse.jdt.core.dom.InfixExpression#hasExtendedOperands() .
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: IfStatementExpressionAnalyzer.java From JDeodorant with MIT License | 5 votes |
private void processExpression(DefaultMutableTreeNode parent, Expression expression) { if(expression instanceof InfixExpression) { InfixExpression infixExpression = (InfixExpression)expression; InfixExpression.Operator operator = infixExpression.getOperator(); if(operator.equals(InfixExpression.Operator.CONDITIONAL_AND) || operator.equals(InfixExpression.Operator.CONDITIONAL_OR)) { parent.setUserObject(operator); DefaultMutableTreeNode leftOperandNode = new DefaultMutableTreeNode(); DefaultMutableTreeNode rightOperandNode = new DefaultMutableTreeNode(); parent.add(leftOperandNode); parent.add(rightOperandNode); processExpression(leftOperandNode, infixExpression.getLeftOperand()); processExpression(rightOperandNode, infixExpression.getRightOperand()); if(infixExpression.hasExtendedOperands()) { DefaultMutableTreeNode grandParent = (DefaultMutableTreeNode)parent.getParent(); int parentIndex = -1; if(grandParent != null) parentIndex = grandParent.getIndex(parent); DefaultMutableTreeNode newParent = processExtendedOperands(parent, infixExpression.extendedOperands()); if(grandParent != null) grandParent.insert(newParent, parentIndex); else root = newParent; } } else { parent.setUserObject(infixExpression); } } else { parent.setUserObject(expression); } }
Example 2
Source File: InfixExpressionWriter.java From juniversal with MIT License | 5 votes |
@Override public void write(InfixExpression infixExpression) { InfixExpression.Operator operator = infixExpression.getOperator(); if (operator == InfixExpression.Operator.RIGHT_SHIFT_UNSIGNED) { writeRightShiftUnsigned(infixExpression); } else { writeNode(infixExpression.getLeftOperand()); copySpaceAndComments(); String operatorToken = this.equivalentOperators.get(operator); matchAndWrite(operatorToken); copySpaceAndComments(); writeNode(infixExpression.getRightOperand()); if (infixExpression.hasExtendedOperands()) { forEach(infixExpression.extendedOperands(), (Expression extendedOperand) -> { copySpaceAndComments(); matchAndWrite(operatorToken); copySpaceAndComments(); writeNode(extendedOperand); }); } } }
Example 3
Source File: InfixExpressionWriter.java From juniversal with MIT License | 5 votes |
private void writeRightShiftUnsigned(InfixExpression infixExpression) { ITypeBinding typeBinding = infixExpression.getLeftOperand().resolveTypeBinding(); String typeName = typeBinding.getName(); //TODO: Remove inner parens for left operand if it's a simple (single elmt) expression, not needing them String cSharpTypeName; String cSharpUnsignedTypeName; if (typeBinding.getName().equals("long")) { cSharpTypeName = "long"; cSharpUnsignedTypeName = "ulong"; } else if (typeBinding.getName().equals("int")) { cSharpTypeName = "int"; cSharpUnsignedTypeName = "uint"; } else if (typeBinding.getName().equals("short")) { cSharpTypeName = "short"; cSharpUnsignedTypeName = "ushort"; } else if (typeBinding.getName().equals("byte")) { cSharpTypeName = "sbyte"; cSharpUnsignedTypeName = "byte"; } else throw new JUniversalException("Unexpected >>> left operand type: " + typeName); write("(" + cSharpTypeName + ")((" + cSharpUnsignedTypeName + ")("); writeNode(infixExpression.getLeftOperand()); write(")"); copySpaceAndComments(); matchAndWrite(">>>", ">>"); copySpaceAndComments(); writeNode(infixExpression.getRightOperand()); write(")"); if (infixExpression.hasExtendedOperands()) throw sourceNotSupported(">>> extended operands (with multiple >>> operators in a row, like 'a >>> b >>> c') not currently supported"); }
Example 4
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 5
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); } } } }