@Override public void createArrayInitStmt(final CaptureLog log, final int logRecNo) { final int oid = log.objectIds.get(logRecNo); final Object[] params = log.params.get(logRecNo); final String arrTypeName = log.oidClassNames.get(log.oidRecMapping.get(oid)); final Class<?> arrType = getClassForName(arrTypeName); // --- create array instance creation e.g. int[] var = new int[10]; final ArrayType arrAstType = (ArrayType) createAstArrayType(arrTypeName, ast); final ArrayCreation arrCreationExpr = ast.newArrayCreation(); arrCreationExpr.setType(arrAstType); arrCreationExpr.dimensions().add(ast.newNumberLiteral(String.valueOf(params.length))); final String arrVarName = this.createNewVarName(oid, arrTypeName); final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment(); final SimpleName arrVarNameExpr = ast.newSimpleName(arrVarName); vd.setName(arrVarNameExpr); vd.setInitializer(arrCreationExpr); final VariableDeclarationStatement varDeclStmt = ast.newVariableDeclarationStatement(vd); varDeclStmt.setType(this.createAstType(arrTypeName, ast)); methodBlock.statements().add(varDeclStmt); // create array access statements var[0] = var1; Integer paramOID; Assignment assign; ArrayAccess arrAccessExpr; for(int i = 0; i < params.length; i++) { assign = ast.newAssignment(); arrAccessExpr = ast.newArrayAccess(); arrAccessExpr.setIndex(ast.newNumberLiteral(String.valueOf(i))); arrAccessExpr.setArray(arrVarNameExpr); assign.setLeftHandSide(arrAccessExpr); paramOID = (Integer) params[i]; if(paramOID == null) { assign.setRightHandSide(ast.newNullLiteral()); } else { assign.setRightHandSide(ast.newSimpleName(this.oidToVarMapping.get(paramOID))); } methodBlock.statements().add(assign); } }
@Override protected void complete() throws CoreException { super.complete(); ReturnStatement rStatement= fAst.newReturnStatement(); String formatClass; if (getContext().is50orHigher()) formatClass= "java.lang.String"; //$NON-NLS-1$ else formatClass= "java.text.MessageFormat"; //$NON-NLS-1$ MethodInvocation formatInvocation= createMethodInvocation(addImport(formatClass), "format", null); //$NON-NLS-1$ StringLiteral literal= fAst.newStringLiteral(); literal.setLiteralValue(buffer.toString()); formatInvocation.arguments().add(literal); if (getContext().is50orHigher()) { formatInvocation.arguments().addAll(arguments); } else { ArrayCreation arrayCreation= fAst.newArrayCreation(); arrayCreation.setType(fAst.newArrayType(fAst.newSimpleType(addImport("java.lang.Object")))); //$NON-NLS-1$ ArrayInitializer initializer= fAst.newArrayInitializer(); arrayCreation.setInitializer(initializer); initializer.expressions().addAll(arguments); formatInvocation.arguments().add(arrayCreation); } rStatement.setExpression(formatInvocation); toStringMethod.getBody().statements().add(rStatement); }
@Override 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<Expression> it= node.dimensions().iterator(); it.hasNext();) { this.fBuffer.append("[");//$NON-NLS-1$ Expression e= 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; }
public boolean visit(ArrayCreation node) { this.buffer.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.buffer.append("[");//$NON-NLS-1$ Expression e = (Expression) it.next(); e.accept(this); this.buffer.append("]");//$NON-NLS-1$ dims--; } // add empty "[]" for each extra array dimension for (int i= 0; i < dims; i++) { this.buffer.append("[]");//$NON-NLS-1$ } if (node.getInitializer() != null) { node.getInitializer().accept(this); } return false; }
@Override public boolean visit(ArrayCreation node) { //System.out.println("Found: " + node.getClass()); if (node.getInitializer() != null) { node.getInitializer().accept(this); return false; } print("new "); Type base = node.getType().getComponentType(); while (base instanceof ArrayType) { base = ((ArrayType)base).getComponentType(); } base.accept(this); print("["); int printed = 0; for (Object o : node.dimensions()) { Expression e = (Expression)o; if (printed > 0) { print("]["); } e.accept(this); printed++; } print("]"); return false; }
private static ITypeBinding getTargetTypeForArrayInitializer(ArrayInitializer arrayInitializer) { ASTNode initializerParent= arrayInitializer.getParent(); while (initializerParent instanceof ArrayInitializer) { initializerParent= initializerParent.getParent(); } if (initializerParent instanceof ArrayCreation) { return ((ArrayCreation) initializerParent).getType().getElementType().resolveBinding(); } else if (initializerParent instanceof VariableDeclaration) { ITypeBinding typeBinding= ((VariableDeclaration) initializerParent).getName().resolveTypeBinding(); if (typeBinding != null) { return typeBinding.getElementType(); } } return null; }
@Override public void endVisit(ArrayCreation node) { if (skipNode(node)) { return; } GenericSequentialFlowInfo info = processSequential(node, node.getType()); process(info, node.dimensions()); process(info, node.getInitializer()); }
@Override public void endVisit(ArrayCreation node) { ArrayType arrayType = node.getType(); TypeVariable2 arrayTypeCv = (TypeVariable2) getConstraintVariable(arrayType); if (arrayTypeCv == null) return; setConstraintVariable(node, arrayTypeCv); // TODO: constraints for array initializer? }
private Expression getTempInitializerCopy(ASTRewrite rewrite) { final Expression initializer = (Expression) rewrite.createCopyTarget(getTempInitializer()); if (initializer instanceof ArrayInitializer && ASTNodes.getDimensions(fTempDeclarationNode) > 0) { ArrayCreation arrayCreation = rewrite.getAST().newArrayCreation(); arrayCreation.setType( (ArrayType) ASTNodeFactory.newType(rewrite.getAST(), fTempDeclarationNode)); arrayCreation.setInitializer((ArrayInitializer) initializer); return arrayCreation; } return initializer; }
private VariableReference retrieveVariableReference(ArrayCreation arrayCreation) { Class<?> arrayType = retrieveTypeClass(arrayCreation.getType()); List<?> dimensions = ((AbstractList<?>) arrayCreation.getStructuralProperty(ArrayCreation.DIMENSIONS_PROPERTY)); if (dimensions.size() > 1) { throw new RuntimeException("Multidimensional arrays not implemented!"); } Integer length = (Integer) ((NumberLiteral) dimensions.get(0)).resolveConstantExpressionValue(); // ArrayReference arrayReference = new // ValidArrayReference(testCase.getReference(), arrayType, length); ArrayStatement arrayAssignment = new ArrayStatement(testCase.getReference(), arrayType, length); testCase.addStatement(arrayAssignment); return arrayAssignment.getReturnValue(); }
@Override public final void endVisit(final ArrayCreation node) { final ConstraintVariable2 ancestor= (ConstraintVariable2) node.getType().getProperty(PROPERTY_CONSTRAINT_VARIABLE); node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, ancestor); final ArrayInitializer initializer= node.getInitializer(); if (initializer != null) { final ConstraintVariable2 descendant= (ConstraintVariable2) initializer.getProperty(PROPERTY_CONSTRAINT_VARIABLE); if (descendant != null) fModel.createSubtypeConstraint(descendant, ancestor); } }
@Override public void endVisit(ArrayCreation node) { ArrayType arrayType= node.getType(); TypeVariable2 arrayTypeCv= (TypeVariable2) getConstraintVariable(arrayType); if (arrayTypeCv == null) return; setConstraintVariable(node, arrayTypeCv); //TODO: constraints for array initializer? }
private Expression getTempInitializerCopy(ASTRewrite rewrite) { final Expression initializer= (Expression) rewrite.createCopyTarget(getTempInitializer()); if (initializer instanceof ArrayInitializer && ASTNodes.getDimensions(fTempDeclarationNode) > 0) { ArrayCreation arrayCreation= rewrite.getAST().newArrayCreation(); arrayCreation.setType((ArrayType) ASTNodeFactory.newType(rewrite.getAST(), fTempDeclarationNode)); arrayCreation.setInitializer((ArrayInitializer) initializer); return arrayCreation; } return initializer; }
@Override public void endVisit(ArrayCreation node) { if (skipNode(node)) return; GenericSequentialFlowInfo info= processSequential(node, node.getType()); process(info, node.dimensions()); process(info, node.getInitializer()); }
@Override public void write(ArrayCreation arrayCreation) { // TODO: C# doesn't support an exact equivalent to Integer[], with boxed integers (or other primitive types). // Consider disallowing arrays of that type to be created, instead forcing the dev to either create an // Object[] if they want boxed types or an int[] if they want primitive types List<?> dimensions = arrayCreation.dimensions(); // TODO: Support multidimensional arrays if (dimensions.size() > 1) throw new JUniversalException("Multidimensional arrays not currently supported"); matchAndWrite("new"); copySpaceAndComments(); writeNode(arrayCreation.getType().getElementType()); copySpaceAndComments(); matchAndWrite("["); writeNodes(arrayCreation.dimensions()); copySpaceAndComments(); matchAndWrite("]"); // TODO: Check all syntax combinations here @Nullable ArrayInitializer arrayInitializer = arrayCreation.getInitializer(); if (arrayInitializer != null) { copySpaceAndComments(); writeNode(arrayInitializer); } }
@Override public void write(ArrayCreation arrayCreation) { matchAndWrite("new"); List<?> dimensions = arrayCreation.dimensions(); // TODO: Support multidimensional arrays if (dimensions.size() > 1) throw new JUniversalException("Multidimensional arrays not currently supported"); // TODO: Support array initializers if (arrayCreation.getInitializer() != null) throw new JUniversalException("Array initializers not currently supported"); Expression dimensionSizeExpression = (Expression) dimensions.get(0); setPosition(dimensionSizeExpression.getStartPosition()); write("("); writeNode(dimensionSizeExpression); copySpaceAndComments(); write(") "); ArrayType arrayType = arrayCreation.getType(); setPosition(arrayType.getStartPosition()); write("Array<"); writeNode(arrayType.getElementType()); skipSpaceAndComments(); write(">"); setPosition(ASTUtil.getEndPosition(dimensionSizeExpression)); skipSpaceAndComments(); match("]"); }
@Override public boolean visit(ArrayCreation node) { if (dimensionInitializerToReplace != null) { return false; } @SuppressWarnings("unchecked") List<Expression> dimensions = node.dimensions(); if (dimensions.size() != 1) { return true; } Expression initializer = dimensions.get(0); if (Integer.valueOf(0).equals(initializer.resolveConstantExpressionValue())) { try { collectionTurnedToArray = findCollection(node); } catch (NotPartOfToArrayMethodInvocationException e) { // bail out, we haven't found a toArray call return true; } dimensionInitializerToReplace = initializer; arrayTypeName = findArrayTypeName(node); return false; } return true; }
private Expression findCollection(ArrayCreation node) throws NotPartOfToArrayMethodInvocationException { ASTNode parent = node.getParent(); if (parent instanceof MethodInvocation) { MethodInvocation parentMethodInvocation = (MethodInvocation) parent; if ("toArray".equals(parentMethodInvocation.getName().getIdentifier())) { return parentMethodInvocation.getExpression(); } } throw new NotPartOfToArrayMethodInvocationException(); }
@SuppressWarnings("unchecked") public void writeKeyList(QKeyListTerm keyList) { VariableDeclarationFragment variable = getAST().newVariableDeclarationFragment(); variable.setName(getAST().newSimpleName(getCompilationUnit().normalizeTermName(keyList.getName()))); FieldDeclaration field = getAST().newFieldDeclaration(variable); field.modifiers().add(getAST().newModifier(ModifierKeyword.PUBLIC_KEYWORD)); Type bufferedType = getAST().newSimpleType(getAST().newSimpleName(QBufferedData.class.getSimpleName())); field.setType(getAST().newArrayType(bufferedType)); // array of bufferedData ArrayCreation arrayCreation = getAST().newArrayCreation(); arrayCreation.setType(getAST().newArrayType(getAST().newSimpleType(getAST().newSimpleName(QBufferedData.class.getSimpleName())))); ArrayInitializer arrayInitializer = getAST().newArrayInitializer(); for (String keyField : keyList.getKeyFields()) { QExpression expression = expressionParser.parseExpression(keyField); Expression jdtExpression = buildExpression(getAST(), expression, null); arrayInitializer.expressions().add(jdtExpression); } arrayCreation.setInitializer(arrayInitializer); variable.setInitializer(arrayCreation); getTarget().bodyDeclarations().add(field); }
@SuppressWarnings("unchecked") @Override public boolean visit(QCall statement) { Block block = blocks.peek(); MethodInvocation methodInvocation = ast.newMethodInvocation(); methodInvocation.setExpression(ast.newSimpleName("qRPJ")); methodInvocation.setName(ast.newSimpleName("qCall")); // program name QTermExpression expression = expressionParser.parseTerm(statement.getProgram()); Expression jdtExpression = buildExpression(ast, expression, String.class); methodInvocation.arguments().add(jdtExpression); // array of parameter ArrayCreation arrayCreation = ast.newArrayCreation(); arrayCreation.setType(ast.newArrayType(ast.newSimpleType(ast.newSimpleName(QData.class.getSimpleName())))); ArrayInitializer arrayInitializer = ast.newArrayInitializer(); for (String parameter : statement.getParameters()) { expression = expressionParser.parseTerm(parameter); jdtExpression = buildExpression(ast, expression, null); arrayInitializer.expressions().add(jdtExpression); } arrayCreation.setInitializer(arrayInitializer); methodInvocation.arguments().add(arrayCreation); ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation); block.statements().add(expressionStatement); return super.visit(statement); }
private boolean expressionContainsTaintedVariable(Expression node) { if(node instanceof SimpleName) { return expressionContainsTaintedVariable((SimpleName) node); } else if (node instanceof ArrayAccess) { return expressionContainsTaintedVariable((ArrayAccess)node); } else if (node instanceof ArrayCreation) { return expressionContainsTaintedVariable((ArrayCreation)node); } else if (node instanceof CastExpression) { return expressionContainsTaintedVariable((CastExpression) node); } else if (node instanceof ClassInstanceCreation) { return expressionContainsTaintedVariable((ClassInstanceCreation)node); } else if (node instanceof ConditionalExpression) { return expressionContainsTaintedVariable((ConditionalExpression)node); } else if(node instanceof FieldAccess) { return expressionContainsTaintedVariable((FieldAccess)node); } else if(node instanceof InfixExpression) { return expressionContainsTaintedVariable((InfixExpression) node); } else if(node instanceof MethodInvocation) { return expressionContainsTaintedVariable((MethodInvocation) node); } else if(node instanceof ParenthesizedExpression) { return expressionContainsTaintedVariable((ParenthesizedExpression) node); } else if(node instanceof PostfixExpression) { return expressionContainsTaintedVariable((PostfixExpression) node); } else if(node instanceof PrefixExpression) { return expressionContainsTaintedVariable((PrefixExpression) node); } else if(node instanceof SuperMethodInvocation) { return expressionContainsTaintedVariable((SuperMethodInvocation) node); } return false; }
/** * Does the <code>expression</code> need parentheses when inserted into <code>parent</code> at * <code>locationInParent</code> ? * * @param expression the expression * @param parent the parent node * @param locationInParent location of expression in the parent * @param leftOperandType the type of the left operand in <code>parent</code> if * <code>parent</code> is an infix expression with no bindings and * <code>expression</code> is the right operand in it, <code>null</code> otherwise * @return <code>true</code> if <code>expression</code> needs parentheses, <code>false</code> * otherwise. * * @since 3.9 */ private static boolean needsParentheses(Expression expression, ASTNode parent, StructuralPropertyDescriptor locationInParent, ITypeBinding leftOperandType) { if (!expressionTypeNeedsParentheses(expression)) { return false; } if (!locationNeedsParentheses(locationInParent)) { return false; } if (parent instanceof Expression) { Expression parentExpression= (Expression)parent; if (expression instanceof PrefixExpression) { // see bug 405096 return needsParenthesesForPrefixExpression(parentExpression, ((PrefixExpression) expression).getOperator()); } if (expression instanceof ArrayCreation) { // see bug 394721 return parentExpression instanceof ArrayAccess && ((ArrayCreation) expression).getInitializer() == null; } int expressionPrecedence= OperatorPrecedence.getExpressionPrecedence(expression); int parentPrecedence= OperatorPrecedence.getExpressionPrecedence(parentExpression); if (expressionPrecedence > parentPrecedence) { //(opEx) opParent and opEx binds more -> parentheses not needed return false; } if (expressionPrecedence < parentPrecedence) { //(opEx) opParent and opEx binds less -> parentheses needed return true; } //(opEx) opParent binds equal if (parentExpression instanceof InfixExpression) { return needsParenthesesInInfixExpression(expression, (InfixExpression) parentExpression, locationInParent, leftOperandType); } if (parentExpression instanceof ConditionalExpression && locationInParent == ConditionalExpression.EXPRESSION_PROPERTY) { return true; } return false; } return true; }
/** {@inheritDoc} */ @Override public boolean visit(ArrayCreation arrayCreation) { return true; }
/** {@inheritDoc} */ @Override public void endVisit(ArrayCreation node) { logger.warn("Method endVisitArrayCreation for " + node + " for " + node + " not implemented!"); super.endVisit(node); }
/** {@inheritDoc} */ @Override public boolean visit(ArrayCreation node) { logger.warn("Method visitArrayCreation for " + node + " for " + node + " not implemented!"); return super.visit(node); }
@Override public boolean visit(final ArrayCreation node) { return false; }
@Override public boolean visit(final ArrayCreation node) { return this.visitInstrumentable(node); }
private FieldDeclaration createParameterObjectField(ParameterObjectFactory pof, TypeDeclaration typeNode, int modifier) { AST ast= fBaseCURewrite.getAST(); ClassInstanceCreation creation= ast.newClassInstanceCreation(); creation.setType(pof.createType(fDescriptor.isCreateTopLevel(), fBaseCURewrite, typeNode.getStartPosition())); ListRewrite listRewrite= fBaseCURewrite.getASTRewrite().getListRewrite(creation, ClassInstanceCreation.ARGUMENTS_PROPERTY); for (Iterator<FieldInfo> iter= fVariables.values().iterator(); iter.hasNext();) { FieldInfo fi= iter.next(); if (isCreateField(fi)) { Expression expression= fi.initializer; if (expression != null && !fi.hasFieldReference()) { importNodeTypes(expression, fBaseCURewrite); ASTNode createMoveTarget= fBaseCURewrite.getASTRewrite().createMoveTarget(expression); if (expression instanceof ArrayInitializer) { ArrayInitializer ai= (ArrayInitializer) expression; ITypeBinding type= ai.resolveTypeBinding(); Type addImport= fBaseCURewrite.getImportRewrite().addImport(type, ast); fBaseCURewrite.getImportRemover().registerAddedImports(addImport); ArrayCreation arrayCreation= ast.newArrayCreation(); arrayCreation.setType((ArrayType) addImport); arrayCreation.setInitializer((ArrayInitializer) createMoveTarget); listRewrite.insertLast(arrayCreation, null); } else { listRewrite.insertLast(createMoveTarget, null); } } } } VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment(); fragment.setName(ast.newSimpleName(fDescriptor.getFieldName())); fragment.setInitializer(creation); ModifierKeyword acc= null; if (Modifier.isPublic(modifier)) { acc= ModifierKeyword.PUBLIC_KEYWORD; } else if (Modifier.isProtected(modifier)) { acc= ModifierKeyword.PROTECTED_KEYWORD; } else if (Modifier.isPrivate(modifier)) { acc= ModifierKeyword.PRIVATE_KEYWORD; } FieldDeclaration fieldDeclaration= ast.newFieldDeclaration(fragment); fieldDeclaration.setType(pof.createType(fDescriptor.isCreateTopLevel(), fBaseCURewrite, typeNode.getStartPosition())); if (acc != null) fieldDeclaration.modifiers().add(ast.newModifier(acc)); return fieldDeclaration; }
@Override public boolean visit(ArrayCreation node) { if (node.subtreeMatch(fMatcher, fNodeToMatch)) return matches(node); return super.visit(node); }
@Override public boolean visit(ArrayCreation node) { add(fCreator.create(node)); return true; }
@Override public void endVisit(ArrayCreation node) { endVisitNode(node); }
@Override public boolean visit(ArrayCreation node) { return visitNode(node); }
private FieldDeclaration createParameterObjectField(ParameterObjectFactory pof, TypeDeclaration typeNode, int modifier) { AST ast= fBaseCURewrite.getAST(); ClassInstanceCreation creation= ast.newClassInstanceCreation(); creation.setType(pof.createType(fDescriptor.isCreateTopLevel(), fBaseCURewrite, typeNode.getStartPosition())); ListRewrite listRewrite= fBaseCURewrite.getASTRewrite().getListRewrite(creation, ClassInstanceCreation.ARGUMENTS_PROPERTY); for (Iterator<FieldInfo> iter= fVariables.values().iterator(); iter.hasNext();) { FieldInfo fi= iter.next(); if (isCreateField(fi)) { Expression expression= fi.initializer; if (expression != null && !fi.hasFieldReference()) { importNodeTypes(expression, fBaseCURewrite); ASTNode createMoveTarget= fBaseCURewrite.getASTRewrite().createMoveTarget(expression); if (expression instanceof ArrayInitializer) { ArrayInitializer ai= (ArrayInitializer) expression; ITypeBinding componentType= ai.resolveTypeBinding().getComponentType(); ArrayCreation arrayCreation= ast.newArrayCreation(); Type addImport= fBaseCURewrite.getImportRewrite().addImport(componentType, ast); fBaseCURewrite.getImportRemover().registerAddedImports(addImport); arrayCreation.setType(ast.newArrayType(addImport)); arrayCreation.setInitializer((ArrayInitializer) createMoveTarget); listRewrite.insertLast(arrayCreation, null); } else { listRewrite.insertLast(createMoveTarget, null); } } } } VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment(); fragment.setName(ast.newSimpleName(fDescriptor.getFieldName())); fragment.setInitializer(creation); ModifierKeyword acc= null; if (Modifier.isPublic(modifier)) { acc= ModifierKeyword.PUBLIC_KEYWORD; } else if (Modifier.isProtected(modifier)) { acc= ModifierKeyword.PROTECTED_KEYWORD; } else if (Modifier.isPrivate(modifier)) { acc= ModifierKeyword.PRIVATE_KEYWORD; } FieldDeclaration fieldDeclaration= ast.newFieldDeclaration(fragment); fieldDeclaration.setType(pof.createType(fDescriptor.isCreateTopLevel(), fBaseCURewrite, typeNode.getStartPosition())); if (acc != null) fieldDeclaration.modifiers().add(ast.newModifier(acc)); return fieldDeclaration; }
private Expression getModifiedInitializerSource(CompilationUnitRewrite rewrite, SimpleName reference) throws JavaModelException { VariableDeclaration varDecl= getVariableDeclaration(); Expression initializer= varDecl.getInitializer(); ASTNode referenceContext= reference.getParent(); if (Invocations.isResolvedTypeInferredFromExpectedType(initializer)) { if (! (referenceContext instanceof VariableDeclarationFragment || referenceContext instanceof SingleVariableDeclaration || referenceContext instanceof Assignment)) { ITypeBinding[] typeArguments= Invocations.getInferredTypeArguments(initializer); if (typeArguments != null) { String newSource= createParameterizedInvocation(initializer, typeArguments, rewrite); return (Expression) rewrite.getASTRewrite().createStringPlaceholder(newSource, initializer.getNodeType()); } } } Expression copy= (Expression) rewrite.getASTRewrite().createCopyTarget(initializer); AST ast= rewrite.getAST(); ITypeBinding explicitCast= ASTNodes.getExplicitCast(initializer, reference); if (explicitCast != null) { CastExpression cast= ast.newCastExpression(); if (NecessaryParenthesesChecker.needsParentheses(initializer, cast, CastExpression.EXPRESSION_PROPERTY)) { ParenthesizedExpression parenthesized= ast.newParenthesizedExpression(); parenthesized.setExpression(copy); copy= parenthesized; } cast.setExpression(copy); cast.setType(rewrite.getImportRewrite().addImport(explicitCast, ast)); copy= cast; } else if (initializer instanceof ArrayInitializer && ASTNodes.getDimensions(varDecl) > 0) { ArrayType newType= (ArrayType) ASTNodeFactory.newType(ast, varDecl); ArrayCreation newArrayCreation= ast.newArrayCreation(); newArrayCreation.setType(newType); newArrayCreation.setInitializer((ArrayInitializer) copy); return newArrayCreation; } return copy; }