当前位置: 首页>>代码示例>>Java>>正文


Java InfixExpression.LEFT_OPERAND_PROPERTY属性代码示例

本文整理汇总了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;
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:58,代码来源:NecessaryParenthesesChecker.java

示例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;
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:63,代码来源:NecessaryParenthesesChecker.java

示例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;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:55,代码来源:NecessaryParenthesesChecker.java

示例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


注:本文中的org.eclipse.jdt.core.dom.InfixExpression.LEFT_OPERAND_PROPERTY属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。