コード例 #1
0
ファイル: ASTBuilder.java プロジェクト: nboldi/markfactory
 public Expression newInfixOperatorExpr(
     String operator, Expression leftOperand, Expression rightOperand) {
   InfixExpression expression = ast.newInfixExpression();
   expression.setOperator(Operator.toOperator(operator));
   expression.setLeftOperand(leftOperand);
   expression.setRightOperand(rightOperand);
   return expression;
 }
コード例 #2
0
 /**
  * Builds a new {@link InfixExpression} instance.
  *
  * @param leftOperand the left operand
  * @param operator the infix operator
  * @param rightOperand the right operand
  * @param extendedOperands the extended operands
  * @return a new infix expression
  */
 public InfixExpression infixExpr(
     Expression leftOperand,
     InfixExpression.Operator operator,
     Expression rightOperand,
     Collection<? extends Expression> extendedOperands) {
   final InfixExpression ie = ast.newInfixExpression();
   ie.setLeftOperand(leftOperand);
   ie.setOperator(operator);
   ie.setRightOperand(rightOperand);
   extendedOperands(ie).addAll(extendedOperands);
   return ie;
 }
コード例 #3
0
 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);
 }
コード例 #4
0
 /**
  * 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()));
       infix.setRightOperand(copiedRightOp);
       ITypeBinding infixType = infix.resolveTypeBinding();
       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;
 }