本文整理汇总了Java中org.eclipse.jdt.core.dom.InfixExpression.LEFT_OPERAND_PROPERTY属性的典型用法代码示例。如果您正苦于以下问题:Java InfixExpression.LEFT_OPERAND_PROPERTY属性的具体用法?Java InfixExpression.LEFT_OPERAND_PROPERTY怎么用?Java InfixExpression.LEFT_OPERAND_PROPERTY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.eclipse.jdt.core.dom.InfixExpression
的用法示例。
在下文中一共展示了InfixExpression.LEFT_OPERAND_PROPERTY属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: needsParenthesesInInfixExpression
private static boolean needsParenthesesInInfixExpression(Expression expression, InfixExpression parentInfix, StructuralPropertyDescriptor locationInParent,
ITypeBinding leftOperandType) {
InfixExpression.Operator parentInfixOperator= parentInfix.getOperator();
ITypeBinding rightOperandType;
ITypeBinding parentInfixExprType;
if (leftOperandType == null) { // parentInfix has bindings
leftOperandType= parentInfix.getLeftOperand().resolveTypeBinding();
rightOperandType= parentInfix.getRightOperand().resolveTypeBinding();
parentInfixExprType= parentInfix.resolveTypeBinding();
} else {
rightOperandType= expression.resolveTypeBinding();
parentInfixExprType= getInfixExpressionType(parentInfixOperator, leftOperandType, rightOperandType);
}
boolean isAllOperandsHaveSameType= isAllOperandsHaveSameType(parentInfix, leftOperandType, rightOperandType);
if (locationInParent == InfixExpression.LEFT_OPERAND_PROPERTY) {
//we have (expr op expr) op expr
//infix expressions are evaluated from left to right -> parentheses not needed
return false;
} else if (isAssociative(parentInfixOperator, parentInfixExprType, isAllOperandsHaveSameType)) {
//we have parent op (expr op expr) and op is associative
//left op (right) == (right) op left == right op left
if (expression instanceof InfixExpression) {
InfixExpression infixExpression= (InfixExpression)expression;
Operator operator= infixExpression.getOperator();
if (isStringType(parentInfixExprType)) {
if (parentInfixOperator == InfixExpression.Operator.PLUS && operator == InfixExpression.Operator.PLUS && isStringType(infixExpression.resolveTypeBinding())) {
// 1 + ("" + 2) == 1 + "" + 2
// 1 + (2 + "") != 1 + 2 + ""
// "" + (2 + "") == "" + 2 + ""
return !isStringType(infixExpression.getLeftOperand().resolveTypeBinding()) && !isStringType(leftOperandType);
}
//"" + (1 + 2), "" + (1 - 2) etc
return true;
}
if (parentInfixOperator != InfixExpression.Operator.TIMES) {
return false;
}
if (operator == InfixExpression.Operator.TIMES) {
// x * (y * z) == x * y * z
return false;
}
if (operator == InfixExpression.Operator.REMAINDER || operator == InfixExpression.Operator.DIVIDE) {
// x * (y % z) != x * y % z , x * (y / z) == x * y / z rounding involved
return true;
}
return false;
}
return false;
} else {
return true;
}
}
示例2: needsParenthesesInInfixExpression
private static boolean needsParenthesesInInfixExpression(
Expression expression,
InfixExpression parentInfix,
StructuralPropertyDescriptor locationInParent,
ITypeBinding leftOperandType) {
InfixExpression.Operator parentInfixOperator = parentInfix.getOperator();
ITypeBinding rightOperandType;
ITypeBinding parentInfixExprType;
if (leftOperandType == null) { // parentInfix has bindings
leftOperandType = parentInfix.getLeftOperand().resolveTypeBinding();
rightOperandType = parentInfix.getRightOperand().resolveTypeBinding();
parentInfixExprType = parentInfix.resolveTypeBinding();
} else {
rightOperandType = expression.resolveTypeBinding();
parentInfixExprType =
getInfixExpressionType(parentInfixOperator, leftOperandType, rightOperandType);
}
boolean isAllOperandsHaveSameType =
isAllOperandsHaveSameType(parentInfix, leftOperandType, rightOperandType);
if (locationInParent == InfixExpression.LEFT_OPERAND_PROPERTY) {
// we have (expr op expr) op expr
// infix expressions are evaluated from left to right -> parentheses not needed
return false;
} else if (isAssociative(parentInfixOperator, parentInfixExprType, isAllOperandsHaveSameType)) {
// we have parent op (expr op expr) and op is associative
// left op (right) == (right) op left == right op left
if (expression instanceof InfixExpression) {
InfixExpression infixExpression = (InfixExpression) expression;
Operator operator = infixExpression.getOperator();
if (isStringType(parentInfixExprType)) {
if (parentInfixOperator == InfixExpression.Operator.PLUS
&& operator == InfixExpression.Operator.PLUS
&& isStringType(infixExpression.resolveTypeBinding())) {
// 1 + ("" + 2) == 1 + "" + 2
// 1 + (2 + "") != 1 + 2 + ""
// "" + (2 + "") == "" + 2 + ""
return !isStringType(infixExpression.getLeftOperand().resolveTypeBinding())
&& !isStringType(leftOperandType);
}
// "" + (1 + 2), "" + (1 - 2) etc
return true;
}
if (parentInfixOperator != InfixExpression.Operator.TIMES) return false;
if (operator == InfixExpression.Operator.TIMES)
// x * (y * z) == x * y * z
return false;
if (operator == InfixExpression.Operator.REMAINDER
|| operator == InfixExpression.Operator.DIVIDE)
// x * (y % z) != x * y % z , x * (y / z) == x * y / z rounding involved
return true;
return false;
}
return false;
} else {
return true;
}
}
示例3: needsParenthesesInInfixExpression
private static boolean needsParenthesesInInfixExpression(Expression expression, InfixExpression parentInfix, StructuralPropertyDescriptor locationInParent,
ITypeBinding leftOperandType) {
InfixExpression.Operator parentInfixOperator= parentInfix.getOperator();
ITypeBinding rightOperandType;
ITypeBinding parentInfixExprType;
if (leftOperandType == null) { // parentInfix has bindings
leftOperandType= parentInfix.getLeftOperand().resolveTypeBinding();
rightOperandType= parentInfix.getRightOperand().resolveTypeBinding();
parentInfixExprType= parentInfix.resolveTypeBinding();
} else {
rightOperandType= expression.resolveTypeBinding();
parentInfixExprType= getInfixExpressionType(parentInfixOperator, leftOperandType, rightOperandType);
}
boolean isAllOperandsHaveSameType= isAllOperandsHaveSameType(parentInfix, leftOperandType, rightOperandType);
if (locationInParent == InfixExpression.LEFT_OPERAND_PROPERTY) {
//we have (expr op expr) op expr
//infix expressions are evaluated from left to right -> parentheses not needed
return false;
} else if (isAssociative(parentInfixOperator, parentInfixExprType, isAllOperandsHaveSameType)) {
//we have parent op (expr op expr) and op is associative
//left op (right) == (right) op left == right op left
if (expression instanceof InfixExpression) {
InfixExpression infixExpression= (InfixExpression)expression;
Operator operator= infixExpression.getOperator();
if (isStringType(parentInfixExprType)) {
if (parentInfixOperator == InfixExpression.Operator.PLUS && operator == InfixExpression.Operator.PLUS && isStringType(infixExpression.resolveTypeBinding())) {
// 1 + ("" + 2) == 1 + "" + 2
// 1 + (2 + "") != 1 + 2 + ""
// "" + (2 + "") == "" + 2 + ""
return !isStringType(infixExpression.getLeftOperand().resolveTypeBinding()) && !isStringType(leftOperandType);
}
//"" + (1 + 2), "" + (1 - 2) etc
return true;
}
if (parentInfixOperator != InfixExpression.Operator.TIMES)
return false;
if (operator == InfixExpression.Operator.TIMES)
// x * (y * z) == x * y * z
return false;
if (operator == InfixExpression.Operator.REMAINDER || operator == InfixExpression.Operator.DIVIDE)
// x * (y % z) != x * y % z , x * (y / z) == x * y / z rounding involved
return true;
return false;
}
return false;
} else {
return true;
}
}
示例4: needsParenthesesInInfixExpression
private static boolean needsParenthesesInInfixExpression(Expression expression, InfixExpression parentInfix, StructuralPropertyDescriptor locationInParent) {
if (locationInParent == InfixExpression.LEFT_OPERAND_PROPERTY) {
//we have (expr op expr) op expr
//infix expressions are evaluated from left to right -> parentheses not needed
return false;
} else if (isAssociative(parentInfix)) {
//we have parent op (expr op expr) and op is associative
//left op (right) == (right) op left == right op left
if (expression instanceof InfixExpression) {
InfixExpression infixExpression= (InfixExpression)expression;
Operator operator= infixExpression.getOperator();
if (isExpressionStringType(parentInfix)) {
if (parentInfix.getOperator() == InfixExpression.Operator.PLUS && operator == InfixExpression.Operator.PLUS && isExpressionStringType(infixExpression)) {
// 1 + ("" + 2) == 1 + "" + 2
// 1 + (2 + "") != 1 + 2 + ""
// "" + (2 + "") == "" + 2 + ""
return !isExpressionStringType(infixExpression.getLeftOperand()) && !isExpressionStringType(parentInfix.getLeftOperand());
}
//"" + (1 + 2), "" + (1 - 2) etc
return true;
}
if (parentInfix.getOperator() != InfixExpression.Operator.TIMES)
return false;
if (operator == InfixExpression.Operator.TIMES)
// x * (y * z) == x * y * z
return false;
if (operator == InfixExpression.Operator.REMAINDER || operator == InfixExpression.Operator.DIVIDE)
// x * (y % z) != x * y % z , x * (y / z) == x * y / z rounding involved
return true;
return false;
}
return false;
} else {
return true;
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:41,代码来源:NecessaryParenthesesChecker.java