Exemplo n.º 1
0
 @SuppressWarnings("unchecked")
 public Expression newArrayCreationFromDimensions(Type type, List<Expression> dimensions) {
   ArrayCreation ac = ast.newArrayCreation();
   ac.dimensions().addAll(dimensions);
   ac.setType(ast.newArrayType(type));
   return ac;
 }
Exemplo n.º 2
0
  /**
   * Builds a new {@link ArrayCreation} instance.
   *
   * @param typeBinding the type binding of the instantiated type
   * @param arrayInitializers the expressions forming the array initializer
   * @return a new array creation instance
   */
  public ArrayCreation newArray(ITypeBinding typeBinding, Expression arrayInitializers) {
    final ArrayInitializer ai = ast.newArrayInitializer();
    expressions(ai).add(arrayInitializers);

    final ArrayCreation ac = ast.newArrayCreation();
    ac.setType((ArrayType) toType(ast, typeBinding));
    ac.setInitializer(ai);
    return ac;
  }
Exemplo n.º 3
0
 @SuppressWarnings("unchecked")
 public ArrayCreation newArrayCreation(Type type, Collection<Expression> values) {
   ArrayCreation ac = ast.newArrayCreation();
   ArrayInitializer initializer = ast.newArrayInitializer();
   for (Expression expr : values) {
     initializer.expressions().add(expr);
   }
   ac.setInitializer(initializer);
   ac.setType(ast.newArrayType(type));
   return ac;
 }
 /* (non-Javadoc)
  * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ArrayCreation)
  */
 public boolean visit(ArrayCreation node) {
   PTArrayCreation ac = InstantiationFactory.eINSTANCE.createPTArrayCreation();
   ac.setType(resolver.resolveType(node.getType()));
   List acDims = ac.getDimensions();
   List nDims = node.dimensions();
   int nsize = nDims.size();
   for (int i = 0; i < nsize; i++) {
     acDims.add(perform((Expression) nDims.get(i)));
   }
   ac.setInitializer((PTArrayInitializer) perform(node.getInitializer()));
   expression = ac;
   return false;
 }
Exemplo n.º 5
0
 public void endVisit(ArrayCreation node) {
   VMArrayInitializer role =
       (node.getInitializer() == null) ? null : (VMArrayInitializer) (expressions.pop());
   Stack<VMExpression> arguments = new Stack<VMExpression>();
   for (int i = 0; i < node.dimensions().size(); i++) {
     arguments.push((VMExpression) expressions.pop());
   }
   VMArrayCreation arrayCreation = new VMArrayCreation(node, role);
   while (!arguments.empty()) {
     arrayCreation.getDimensions().add(arguments.pop());
   }
   expressions.push(arrayCreation);
 }
 /*
  * @see ASTVisitor#visit(ArrayCreation)
  */
 public boolean visit(ArrayCreation node) {
   this.fBuffer.append("new "); // $NON-NLS-1$
   ArrayType at = node.getType();
   int dims = at.getDimensions();
   Type elementType = at.getElementType();
   elementType.accept(this);
   for (Iterator it = node.dimensions().iterator(); it.hasNext(); ) {
     this.fBuffer.append("["); // $NON-NLS-1$
     Expression e = (Expression) it.next();
     e.accept(this);
     this.fBuffer.append("]"); // $NON-NLS-1$
     dims--;
   }
   // add empty "[]" for each extra array dimension
   for (int i = 0; i < dims; i++) {
     this.fBuffer.append("[]"); // $NON-NLS-1$
   }
   if (node.getInitializer() != null) {
     node.getInitializer().accept(this);
   }
   return false;
 }
Exemplo n.º 7
0
 public Expression newArrayCreation(String canonicalName, ArrayInitializer initializer) {
   ArrayCreation ac = ast.newArrayCreation();
   ac.setInitializer(initializer);
   ac.setType(ast.newArrayType(newType(canonicalName)));
   return ac;
 }
  private void collectSideEffects(Expression expr, List<Expression> sideEffectExprs) {
    // local variable, parameter, enum constant, etc.
    // OR method starting with is*(), get*()
    // except atomic long, atomic integer, etc.
    switch (expr.getNodeType()) {
      case METHOD_INVOCATION:
        MethodInvocation mi = (MethodInvocation) expr;
        methodHasSideEffects(mi.resolveMethodBinding(), mi, sideEffectExprs);
        collectSideEffects(mi.getExpression(), sideEffectExprs);
        collectSideEffects(arguments(mi), sideEffectExprs);
        break;

      case SUPER_METHOD_INVOCATION:
        SuperMethodInvocation smi = (SuperMethodInvocation) expr;
        methodHasSideEffects(smi.resolveMethodBinding(), smi, sideEffectExprs);
        collectSideEffects(arguments(smi), sideEffectExprs);
        break;

      case CLASS_INSTANCE_CREATION:
        ClassInstanceCreation cic = (ClassInstanceCreation) expr;
        methodHasSideEffects(cic.resolveConstructorBinding(), cic, sideEffectExprs);
        collectSideEffects(cic.getExpression(), sideEffectExprs);
        collectSideEffects(arguments(cic), sideEffectExprs);
        break;

      case ARRAY_ACCESS:
        ArrayAccess aa = (ArrayAccess) expr;
        collectSideEffects(aa.getArray(), sideEffectExprs);
        collectSideEffects(aa.getIndex(), sideEffectExprs);
        break;
      case ARRAY_CREATION:
        ArrayCreation ac = (ArrayCreation) expr;
        collectSideEffects(ac.getInitializer(), sideEffectExprs);
        collectSideEffects(ac.dimensions(), sideEffectExprs);
        break;
      case ARRAY_INITIALIZER:
        ArrayInitializer ai = (ArrayInitializer) expr;
        collectSideEffects(expressions(ai), sideEffectExprs);
        break;
      case ASSIGNMENT:
        Assignment as = (Assignment) expr;
        collectSideEffects(as.getLeftHandSide(), sideEffectExprs);
        collectSideEffects(as.getRightHandSide(), sideEffectExprs);
        break;

      case CONDITIONAL_EXPRESSION:
        ConditionalExpression ce = (ConditionalExpression) expr;
        collectSideEffects(ce.getExpression(), sideEffectExprs);
        collectSideEffects(ce.getThenExpression(), sideEffectExprs);
        collectSideEffects(ce.getElseExpression(), sideEffectExprs);
        break;

      case FIELD_ACCESS:
        FieldAccess fa = (FieldAccess) expr;
        collectSideEffects(fa.getExpression(), sideEffectExprs);
        collectSideEffects(fa.getName(), sideEffectExprs);
        break;
      case SUPER_FIELD_ACCESS:
        SuperFieldAccess sfa = (SuperFieldAccess) expr;
        collectSideEffects(sfa.getQualifier(), sideEffectExprs);
        collectSideEffects(sfa.getName(), sideEffectExprs);
        break;
      case THIS_EXPRESSION:
        collectSideEffects(((ThisExpression) expr).getQualifier(), sideEffectExprs);
        break;
      case VARIABLE_DECLARATION_EXPRESSION:
        collectSideEffects((VariableDeclarationExpression) expr, sideEffectExprs);
        break;

      case INFIX_EXPRESSION:
        InfixExpression ie = (InfixExpression) expr;
        collectSideEffects(ie.getLeftOperand(), sideEffectExprs);
        collectSideEffects(ie.getRightOperand(), sideEffectExprs);
        collectSideEffects(extendedOperands(ie), sideEffectExprs);
        break;

      case CAST_EXPRESSION:
        collectSideEffects(((CastExpression) expr).getExpression(), sideEffectExprs);
        break;
      case INSTANCEOF_EXPRESSION:
        collectSideEffects(((InstanceofExpression) expr).getLeftOperand(), sideEffectExprs);
        break;
      case PARENTHESIZED_EXPRESSION:
        collectSideEffects(((ParenthesizedExpression) expr).getExpression(), sideEffectExprs);
        break;
      case POSTFIX_EXPRESSION:
        sideEffectExprs.add(expr);
        break;
      case PREFIX_EXPRESSION:
        PrefixExpression pe = (PrefixExpression) expr;
        PrefixExpression.Operator op = pe.getOperator();
        if (PrefixExpression.Operator.INCREMENT.equals(op)
            | PrefixExpression.Operator.DECREMENT.equals(op)) {
          sideEffectExprs.add(pe);
        } else {
          collectSideEffects(pe.getOperand(), sideEffectExprs);
        }
        break;

      default:
        // literals
        // names
    }
  }