下面列出了org.eclipse.jdt.core.dom.InfixExpression#hasExtendedOperands ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
@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);
});
}
}
}
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");
}
@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);
}
}
}
}
@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);
}
}
}
}