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


Java InfixExpression.resolveTypeBinding方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.InfixExpression.resolveTypeBinding方法的典型用法代码示例。如果您正苦于以下问题:Java InfixExpression.resolveTypeBinding方法的具体用法?Java InfixExpression.resolveTypeBinding怎么用?Java InfixExpression.resolveTypeBinding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.dom.InfixExpression的用法示例。


在下文中一共展示了InfixExpression.resolveTypeBinding方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createInfixInvocationFromPostPrefixExpression

import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
private static Expression createInfixInvocationFromPostPrefixExpression(InfixExpression.Operator operator, Expression getterExpression, AST ast, ITypeBinding variableType, boolean is50OrHigher) {
	InfixExpression infix = ast.newInfixExpression();
	infix.setLeftOperand(getterExpression);
	infix.setOperator(operator);
	NumberLiteral number = ast.newNumberLiteral();
	number.setToken("1"); //$NON-NLS-1$
	infix.setRightOperand(number);
	ITypeBinding infixType = infix.resolveTypeBinding();
	return createNarrowCastIfNessecary(infix, infixType, ast, variableType, is50OrHigher);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:11,代码来源:GetterSetterUtil.java

示例2: createInfixInvocationFromPostPrefixExpression

import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
private static Expression createInfixInvocationFromPostPrefixExpression(
    InfixExpression.Operator operator,
    Expression getterExpression,
    AST ast,
    ITypeBinding variableType,
    boolean is50OrHigher) {
  InfixExpression infix = ast.newInfixExpression();
  infix.setLeftOperand(getterExpression);
  infix.setOperator(operator);
  NumberLiteral number = ast.newNumberLiteral();
  number.setToken("1"); // $NON-NLS-1$
  infix.setRightOperand(number);
  ITypeBinding infixType = infix.resolveTypeBinding();
  return createNarrowCastIfNessecary(infix, infixType, ast, variableType, is50OrHigher);
}
 
开发者ID:eclipse,项目名称:che,代码行数:16,代码来源:GetterSetterUtil.java

示例3: createInfixInvocationFromPostPrefixExpression

import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
private static Expression createInfixInvocationFromPostPrefixExpression(InfixExpression.Operator operator, Expression getterExpression, AST ast, ITypeBinding variableType, boolean is50OrHigher) {
	InfixExpression infix= ast.newInfixExpression();
	infix.setLeftOperand(getterExpression);
	infix.setOperator(operator);
	NumberLiteral number= ast.newNumberLiteral();
	number.setToken("1"); //$NON-NLS-1$
	infix.setRightOperand(number);
	ITypeBinding infixType= infix.resolveTypeBinding();
	return createNarrowCastIfNessecary(infix, infixType, ast, variableType, is50OrHigher);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:11,代码来源:GetterSetterUtil.java

示例4: needsParenthesesInInfixExpression

import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
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,代码行数:59,代码来源:NecessaryParenthesesChecker.java

示例5: getAssignedValue

import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
/**
 * Converts an assignment, postfix expression or prefix expression into an
 * assignable equivalent expression using the getter.
 *
 * @param node
 *            the assignment/prefix/postfix node
 * @param astRewrite
 *            the astRewrite to use
 * @param getterExpression
 *            the expression to insert for read accesses or
 *            <code>null</code> if such an expression does not exist
 * @param variableType
 *            the type of the variable that the result will be assigned to
 * @param is50OrHigher
 *            <code>true</code> if a 5.0 or higher environment can be used
 * @return an expression that can be assigned to the type variableType with
 *         node being replaced by a equivalent expression using the getter
 */
public static Expression getAssignedValue(ASTNode node, ASTRewrite astRewrite, Expression getterExpression, ITypeBinding variableType, boolean is50OrHigher) {
	InfixExpression.Operator op = null;
	AST ast = astRewrite.getAST();
	if (isNotInBlock(node)) {
		return null;
	}
	if (node.getNodeType() == ASTNode.ASSIGNMENT) {
		Assignment assignment = ((Assignment) node);
		Expression rightHandSide = assignment.getRightHandSide();
		Expression copiedRightOp = (Expression) astRewrite.createCopyTarget(rightHandSide);
		if (assignment.getOperator() == Operator.ASSIGN) {
			ITypeBinding rightHandSideType = rightHandSide.resolveTypeBinding();
			copiedRightOp = createNarrowCastIfNessecary(copiedRightOp, rightHandSideType, ast, variableType, is50OrHigher);
			return copiedRightOp;
		}
		if (getterExpression != null) {
			InfixExpression infix = ast.newInfixExpression();
			infix.setLeftOperand(getterExpression);
			infix.setOperator(ASTNodes.convertToInfixOperator(assignment.getOperator()));
			ITypeBinding infixType = infix.resolveTypeBinding();
			if (NecessaryParenthesesChecker.needsParenthesesForRightOperand(rightHandSide, infix, variableType)) {
				ParenthesizedExpression p = ast.newParenthesizedExpression();
				p.setExpression(copiedRightOp);
				copiedRightOp = p;
			}
			infix.setRightOperand(copiedRightOp);
			return createNarrowCastIfNessecary(infix, infixType, ast, variableType, is50OrHigher);
		}
	} else if (node.getNodeType() == ASTNode.POSTFIX_EXPRESSION) {
		PostfixExpression po = (PostfixExpression) node;
		if (po.getOperator() == PostfixExpression.Operator.INCREMENT) {
			op = InfixExpression.Operator.PLUS;
		}
		if (po.getOperator() == PostfixExpression.Operator.DECREMENT) {
			op = InfixExpression.Operator.MINUS;
		}
	} else if (node.getNodeType() == ASTNode.PREFIX_EXPRESSION) {
		PrefixExpression pe = (PrefixExpression) node;
		if (pe.getOperator() == PrefixExpression.Operator.INCREMENT) {
			op = InfixExpression.Operator.PLUS;
		}
		if (pe.getOperator() == PrefixExpression.Operator.DECREMENT) {
			op= InfixExpression.Operator.MINUS;
		}
	}
	if (op != null && getterExpression != null) {
		return createInfixInvocationFromPostPrefixExpression(op, getterExpression, ast, variableType, is50OrHigher);
	}
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:69,代码来源:GetterSetterUtil.java

示例6: needsParenthesesInInfixExpression

import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
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,代码行数:64,代码来源:NecessaryParenthesesChecker.java

示例7: getAssignedValue

import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
/**
 * Converts an assignment, postfix expression or prefix expression into an assignable equivalent
 * expression using the getter.
 *
 * @param node the assignment/prefix/postfix node
 * @param astRewrite the astRewrite to use
 * @param getterExpression the expression to insert for read accesses or <code>null</code> if such
 *     an expression does not exist
 * @param variableType the type of the variable that the result will be assigned to
 * @param is50OrHigher <code>true</code> if a 5.0 or higher environment can be used
 * @return an expression that can be assigned to the type variableType with node being replaced by
 *     a equivalent expression using the getter
 */
public static Expression getAssignedValue(
    ASTNode node,
    ASTRewrite astRewrite,
    Expression getterExpression,
    ITypeBinding variableType,
    boolean is50OrHigher) {
  InfixExpression.Operator op = null;
  AST ast = astRewrite.getAST();
  if (isNotInBlock(node)) return null;
  if (node.getNodeType() == ASTNode.ASSIGNMENT) {
    Assignment assignment = ((Assignment) node);
    Expression rightHandSide = assignment.getRightHandSide();
    Expression copiedRightOp = (Expression) astRewrite.createCopyTarget(rightHandSide);
    if (assignment.getOperator() == Operator.ASSIGN) {
      ITypeBinding rightHandSideType = rightHandSide.resolveTypeBinding();
      copiedRightOp =
          createNarrowCastIfNessecary(
              copiedRightOp, rightHandSideType, ast, variableType, is50OrHigher);
      return copiedRightOp;
    }
    if (getterExpression != null) {
      InfixExpression infix = ast.newInfixExpression();
      infix.setLeftOperand(getterExpression);
      infix.setOperator(ASTNodes.convertToInfixOperator(assignment.getOperator()));
      ITypeBinding infixType = infix.resolveTypeBinding();
      if (NecessaryParenthesesChecker.needsParenthesesForRightOperand(
          rightHandSide, infix, variableType)) {
        ParenthesizedExpression p = ast.newParenthesizedExpression();
        p.setExpression(copiedRightOp);
        copiedRightOp = p;
      }
      infix.setRightOperand(copiedRightOp);
      return createNarrowCastIfNessecary(infix, infixType, ast, variableType, is50OrHigher);
    }
  } else if (node.getNodeType() == ASTNode.POSTFIX_EXPRESSION) {
    PostfixExpression po = (PostfixExpression) node;
    if (po.getOperator() == PostfixExpression.Operator.INCREMENT)
      op = InfixExpression.Operator.PLUS;
    if (po.getOperator() == PostfixExpression.Operator.DECREMENT)
      op = InfixExpression.Operator.MINUS;
  } else if (node.getNodeType() == ASTNode.PREFIX_EXPRESSION) {
    PrefixExpression pe = (PrefixExpression) node;
    if (pe.getOperator() == PrefixExpression.Operator.INCREMENT)
      op = InfixExpression.Operator.PLUS;
    if (pe.getOperator() == PrefixExpression.Operator.DECREMENT)
      op = InfixExpression.Operator.MINUS;
  }
  if (op != null && getterExpression != null) {
    return createInfixInvocationFromPostPrefixExpression(
        op, getterExpression, ast, variableType, is50OrHigher);
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:67,代码来源:GetterSetterUtil.java

示例8: needsParenthesesInInfixExpression

import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
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,代码行数:56,代码来源:NecessaryParenthesesChecker.java

示例9: getAssignedValue

import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
/**
 * Converts an assignment, postfix expression or prefix expression into an assignable equivalent expression using the getter.
 *
 * @param node the assignment/prefix/postfix node
 * @param astRewrite the astRewrite to use
 * @param getterExpression the expression to insert for read accesses or <code>null</code> if such an expression does not exist
 * @param variableType the type of the variable that the result will be assigned to
 * @param is50OrHigher <code>true</code> if a 5.0 or higher environment can be used
 * @return an expression that can be assigned to the type variableType with node being replaced by a equivalent expression using the getter
 */
public static Expression getAssignedValue(ASTNode node, ASTRewrite astRewrite, Expression getterExpression, ITypeBinding variableType, boolean is50OrHigher) {
	InfixExpression.Operator op= null;
	AST ast= astRewrite.getAST();
	if (isNotInBlock(node))
		return null;
	if (node.getNodeType() == ASTNode.ASSIGNMENT) {
		Assignment assignment= ((Assignment) node);
		Expression rightHandSide= assignment.getRightHandSide();
		Expression copiedRightOp= (Expression) astRewrite.createCopyTarget(rightHandSide);
		if (assignment.getOperator() == Operator.ASSIGN) {
			ITypeBinding rightHandSideType= rightHandSide.resolveTypeBinding();
			copiedRightOp= createNarrowCastIfNessecary(copiedRightOp, rightHandSideType, ast, variableType, is50OrHigher);
			return copiedRightOp;
		}
		if (getterExpression != null) {
			InfixExpression infix= ast.newInfixExpression();
			infix.setLeftOperand(getterExpression);
			infix.setOperator(ASTNodes.convertToInfixOperator(assignment.getOperator()));
			ITypeBinding infixType= infix.resolveTypeBinding();
			if (NecessaryParenthesesChecker.needsParenthesesForRightOperand(rightHandSide, infix, variableType)) {
				ParenthesizedExpression p= ast.newParenthesizedExpression();
				p.setExpression(copiedRightOp);
				copiedRightOp= p;
			}
			infix.setRightOperand(copiedRightOp);
			return createNarrowCastIfNessecary(infix, infixType, ast, variableType, is50OrHigher);
		}
	} else if (node.getNodeType() == ASTNode.POSTFIX_EXPRESSION) {
		PostfixExpression po= (PostfixExpression) node;
		if (po.getOperator() == PostfixExpression.Operator.INCREMENT)
			op= InfixExpression.Operator.PLUS;
		if (po.getOperator() == PostfixExpression.Operator.DECREMENT)
			op= InfixExpression.Operator.MINUS;
	} else if (node.getNodeType() == ASTNode.PREFIX_EXPRESSION) {
		PrefixExpression pe= (PrefixExpression) node;
		if (pe.getOperator() == PrefixExpression.Operator.INCREMENT)
			op= InfixExpression.Operator.PLUS;
		if (pe.getOperator() == PrefixExpression.Operator.DECREMENT)
			op= InfixExpression.Operator.MINUS;
	}
	if (op != null && getterExpression != null) {
		return createInfixInvocationFromPostPrefixExpression(op, getterExpression, ast, variableType, is50OrHigher);
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:56,代码来源:GetterSetterUtil.java

示例10: getConvertStringConcatenationProposals

import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
private static boolean getConvertStringConcatenationProposals(IInvocationContext context, Collection<ICommandAccess> resultingCollections) {
	ASTNode node= context.getCoveringNode();
	BodyDeclaration parentDecl= ASTResolving.findParentBodyDeclaration(node);
	if (!(parentDecl instanceof MethodDeclaration || parentDecl instanceof Initializer))
		return false;

	AST ast= node.getAST();
	ITypeBinding stringBinding= ast.resolveWellKnownType("java.lang.String"); //$NON-NLS-1$

	if (node instanceof Expression && !(node instanceof InfixExpression)) {
		node= node.getParent();
	}
	if (node instanceof VariableDeclarationFragment) {
		node= ((VariableDeclarationFragment) node).getInitializer();
	} else if (node instanceof Assignment) {
		node= ((Assignment) node).getRightHandSide();
	}

	InfixExpression oldInfixExpression= null;
	while (node instanceof InfixExpression) {
		InfixExpression curr= (InfixExpression) node;
		if (curr.resolveTypeBinding() == stringBinding && curr.getOperator() == InfixExpression.Operator.PLUS) {
			oldInfixExpression= curr; // is a infix expression we can use
		} else {
			break;
		}
		node= node.getParent();
	}
	if (oldInfixExpression == null)
		return false;

	if (resultingCollections == null) {
		return true;
	}

	LinkedCorrectionProposal stringBufferProposal= getConvertToStringBufferProposal(context, ast, oldInfixExpression);
	resultingCollections.add(stringBufferProposal);

	ASTRewriteCorrectionProposal messageFormatProposal= getConvertToMessageFormatProposal(context, ast, oldInfixExpression);
	if (messageFormatProposal != null)
		resultingCollections.add(messageFormatProposal);

	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:45,代码来源:QuickAssistProcessor.java

示例11: getAssignedValue

import org.eclipse.jdt.core.dom.InfixExpression; //导入方法依赖的package包/类
/**
 * Converts an assignment, postfix expression or prefix expression into an assignable equivalent expression using the getter.
 *
 * @param node the assignment/prefix/postfix node
 * @param astRewrite the astRewrite to use
 * @param getterExpression the expression to insert for read accesses or <code>null</code> if such an expression does not exist
 * @param variableType the type of the variable that the result will be assigned to
 * @param is50OrHigher <code>true</code> if a 5.0 or higher environment can be used
 * @return an expression that can be assigned to the type variableType with node being replaced by a equivalent expression using the getter
 */
public static Expression getAssignedValue(ASTNode node, ASTRewrite astRewrite, Expression getterExpression, ITypeBinding variableType, boolean is50OrHigher) {
	InfixExpression.Operator op= null;
	AST ast= astRewrite.getAST();
	if (isNotInBlock(node))
		return null;
	if (node.getNodeType() == ASTNode.ASSIGNMENT) {
		Assignment assignment= ((Assignment) node);
		Expression rightHandSide= assignment.getRightHandSide();
		Expression copiedRightOp= (Expression) astRewrite.createCopyTarget(rightHandSide);
		if (assignment.getOperator() == Operator.ASSIGN) {
			ITypeBinding rightHandSideType= rightHandSide.resolveTypeBinding();
			copiedRightOp= createNarrowCastIfNessecary(copiedRightOp, rightHandSideType, ast, variableType, is50OrHigher);
			return copiedRightOp;
		}
		if (getterExpression != null) {
			InfixExpression infix= ast.newInfixExpression();
			infix.setLeftOperand(getterExpression);
			infix.setOperator(ASTNodes.convertToInfixOperator(assignment.getOperator()));
			ITypeBinding infixType= infix.resolveTypeBinding();
			if (NecessaryParenthesesChecker.needsParentheses(copiedRightOp, infix, InfixExpression.RIGHT_OPERAND_PROPERTY)) {
				//TODO: this introduces extra parentheses as the new "infix" node doesn't have bindings
				ParenthesizedExpression p= ast.newParenthesizedExpression();
				p.setExpression(copiedRightOp);
				copiedRightOp= p;
			}
			infix.setRightOperand(copiedRightOp);
			return createNarrowCastIfNessecary(infix, infixType, ast, variableType, is50OrHigher);
		}
	} else if (node.getNodeType() == ASTNode.POSTFIX_EXPRESSION) {
		PostfixExpression po= (PostfixExpression) node;
		if (po.getOperator() == PostfixExpression.Operator.INCREMENT)
			op= InfixExpression.Operator.PLUS;
		if (po.getOperator() == PostfixExpression.Operator.DECREMENT)
			op= InfixExpression.Operator.MINUS;
	} else if (node.getNodeType() == ASTNode.PREFIX_EXPRESSION) {
		PrefixExpression pe= (PrefixExpression) node;
		if (pe.getOperator() == PrefixExpression.Operator.INCREMENT)
			op= InfixExpression.Operator.PLUS;
		if (pe.getOperator() == PrefixExpression.Operator.DECREMENT)
			op= InfixExpression.Operator.MINUS;
	}
	if (op != null && getterExpression != null) {
		return createInfixInvocationFromPostPrefixExpression(op, getterExpression, ast, variableType, is50OrHigher);
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:57,代码来源:GetterSetterUtil.java


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