下面列出了怎么用org.eclipse.jdt.core.dom.ArrayInitializer的API类实例代码及写法,或者点击链接到github查看源代码。
@SuppressWarnings("unchecked")
private static boolean containsAnnotationValue(Expression annotationValue,
String value) {
if (annotationValue.getNodeType() == ASTNode.STRING_LITERAL) {
String valueString = ((StringLiteral) annotationValue).getLiteralValue();
return value.equals(valueString);
} else if (annotationValue.getNodeType() == ASTNode.ARRAY_INITIALIZER) {
// If the annotation value is actually an array, check each element
List<Expression> warningTypes = ((ArrayInitializer) annotationValue).expressions();
for (Expression warningType : warningTypes) {
if (containsAnnotationValue(warningType, value)) {
return true;
}
}
}
return false;
}
@SuppressWarnings("unchecked")
private void validateUiHandlerFieldExistenceInUiXml(
MethodDeclaration uiHandlerDecl) {
Annotation annotation = JavaASTUtils.findAnnotation(uiHandlerDecl,
UiBinderConstants.UI_HANDLER_TYPE_NAME);
if (annotation instanceof SingleMemberAnnotation) {
SingleMemberAnnotation uiHandlerAnnotation = (SingleMemberAnnotation) annotation;
Expression exp = uiHandlerAnnotation.getValue();
if (exp instanceof StringLiteral) {
validateFieldExistenceInUiXml(
(TypeDeclaration) uiHandlerDecl.getParent(), exp,
((StringLiteral) exp).getLiteralValue());
} else if (exp instanceof ArrayInitializer) {
for (Expression element : (List<Expression>) ((ArrayInitializer) exp).expressions()) {
if (element instanceof StringLiteral) {
validateFieldExistenceInUiXml(
(TypeDeclaration) uiHandlerDecl.getParent(), element,
((StringLiteral) element).getLiteralValue());
}
}
}
}
}
@SuppressWarnings("unchecked")
private void validateSourceAnnotationValues(Annotation annotation) throws JavaModelException {
Expression exp = JavaASTUtils.getAnnotationValue(annotation);
if (exp == null) {
return;
}
// There will usually just be one string value
if (exp instanceof StringLiteral) {
validateSourceAnnotationValue((StringLiteral) exp);
}
// But there could be multiple values; if so, check each one.
if (exp instanceof ArrayInitializer) {
ArrayInitializer array = (ArrayInitializer) exp;
for (Expression item : (List<Expression>) array.expressions()) {
if (item instanceof StringLiteral) {
validateSourceAnnotationValue((StringLiteral) item);
}
}
}
}
@Override
public final void endVisit(final ArrayInitializer node) {
final ITypeBinding binding= node.resolveTypeBinding();
if (binding != null && binding.isArray()) {
final ConstraintVariable2 ancestor= fModel.createIndependentTypeVariable(binding.getElementType());
if (ancestor != null) {
node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, ancestor);
Expression expression= null;
ConstraintVariable2 descendant= null;
final List<Expression> expressions= node.expressions();
for (int index= 0; index < expressions.size(); index++) {
expression= expressions.get(index);
descendant= (ConstraintVariable2) expression.getProperty(PROPERTY_CONSTRAINT_VARIABLE);
if (descendant != null)
fModel.createSubtypeConstraint(descendant, ancestor);
}
}
}
}
private RefactoringStatus checkExpression() throws JavaModelException {
Expression selectedExpression= getSelectedExpression().getAssociatedExpression();
if (selectedExpression != null) {
final ASTNode parent= selectedExpression.getParent();
if (selectedExpression instanceof NullLiteral) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
} else if (selectedExpression instanceof ArrayInitializer) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
} else if (selectedExpression instanceof Assignment) {
if (parent instanceof Expression && !(parent instanceof ParenthesizedExpression))
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
else
return null;
} else if (selectedExpression instanceof SimpleName) {
if ((((SimpleName) selectedExpression)).isDeclaration())
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
if (parent instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || parent instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
} else if (selectedExpression instanceof VariableDeclarationExpression && parent instanceof TryStatement) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_resource_in_try_with_resources);
}
}
return null;
}
@Override
public ITypeConstraint[] create(ArrayInitializer arrayInitializer){
ITypeBinding arrayBinding= arrayInitializer.resolveTypeBinding();
Assert.isTrue(arrayBinding.isArray());
List<Expression> expressions= arrayInitializer.expressions();
List<ITypeConstraint> constraints= new ArrayList<ITypeConstraint>();
Type type= getTypeParent(arrayInitializer);
ConstraintVariable typeVariable= fConstraintVariableFactory.makeTypeVariable(type);
for (int i= 0; i < expressions.size(); i++) {
Expression each= expressions.get(i);
ITypeConstraint[] c= fTypeConstraintFactory.createSubtypeConstraint(
fConstraintVariableFactory.makeExpressionOrTypeVariable(each, getContext()),
typeVariable);
constraints.addAll(Arrays.asList(c));
}
return constraints.toArray(new ITypeConstraint[constraints.size()]);
}
@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);
}
private Expression newDefaultExpression(AST ast, ITypeBinding type, ImportRewriteContext context) {
if (type.isPrimitive()) {
String name= type.getName();
if ("boolean".equals(name)) { //$NON-NLS-1$
return ast.newBooleanLiteral(false);
} else {
return ast.newNumberLiteral("0"); //$NON-NLS-1$
}
}
if (type == ast.resolveWellKnownType("java.lang.String")) { //$NON-NLS-1$
return ast.newStringLiteral();
}
if (type.isArray()) {
ArrayInitializer initializer= ast.newArrayInitializer();
initializer.expressions().add(newDefaultExpression(ast, type.getElementType(), context));
return initializer;
}
if (type.isAnnotation()) {
MarkerAnnotation annotation= ast.newMarkerAnnotation();
annotation.setTypeName(ast.newName(getImportRewrite().addImport(type, context)));
return annotation;
}
return ast.newNullLiteral();
}
public boolean visit(ArrayInitializer expr) {
/*
* ArrayInitializer: { [ Expression { , Expression} [ , ]] }
*/
activateDiffStyle(expr);
appendOpenCurlyBracket();
for (int i = 0; i < expr.expressions().size(); i++) {
handleExpression((Expression) expr.expressions().get(i));
if (i < expr.expressions().size() - 1) {
appendComma();
}
}
appendClosedCurlyBracket();
deactivateDiffStyle(expr);
return false;
}
private ArrayInitial visit(ArrayInitializer node) {
int startLine = _cunit.getLineNumber(node.getStartPosition());
int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
ArrayInitial arrayInitial = new ArrayInitial(startLine, endLine, node);
List<Expr> expressions = new ArrayList<>();
for(Object object : node.expressions()){
Expr expr = (Expr) process((ASTNode) object);
expr.setParent(arrayInitial);
expressions.add(expr);
}
arrayInitial.setExpressions(expressions);
return arrayInitial;
}
@Override
public void endVisit(ArrayInitializer node) {
if (skipNode(node)) {
return;
}
processSequential(node, node.expressions());
}
private RefactoringStatus checkExpression() throws JavaModelException {
Expression selectedExpression = getSelectedExpression().getAssociatedExpression();
if (selectedExpression != null) {
final ASTNode parent = selectedExpression.getParent();
if (selectedExpression instanceof NullLiteral) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
} else if (selectedExpression instanceof ArrayInitializer) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
} else if (selectedExpression instanceof Assignment) {
if (parent instanceof Expression && !(parent instanceof ParenthesizedExpression)) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
} else {
return null;
}
} else if (selectedExpression instanceof SimpleName) {
if ((((SimpleName) selectedExpression)).isDeclaration()) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
}
if (parent instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || parent instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
}
} else if (selectedExpression instanceof VariableDeclarationExpression && parent instanceof TryStatement) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_resource_in_try_with_resources);
}
}
return null;
}
private RefactoringStatus checkExpression() throws JavaModelException {
Expression selectedExpression = getSelectedExpression().getAssociatedExpression();
if (selectedExpression != null) {
final ASTNode parent = selectedExpression.getParent();
if (selectedExpression instanceof NullLiteral) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
} else if (selectedExpression instanceof ArrayInitializer) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
} else if (selectedExpression instanceof Assignment) {
if (parent instanceof Expression && !(parent instanceof ParenthesizedExpression)) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
} else {
return null;
}
} else if (selectedExpression instanceof SimpleName) {
if ((((SimpleName) selectedExpression)).isDeclaration()) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
}
if (parent instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || parent instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
}
} else if (selectedExpression instanceof VariableDeclarationExpression && parent instanceof TryStatement) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_resource_in_try_with_resources);
}
}
return null;
}
@Override
public boolean visit(final ArrayInitializer node) {
this.appendToBuffer("#[");
this.visitAllSeparatedByComma(node.expressions());
this.appendToBuffer("]");
return false;
}
@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);
}
}
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 RefactoringStatus checkExpression() {
//TODO: adjust error messages (or generalize for all refactorings on expression-selections?)
Expression selectedExpression= fSelectedExpression;
if (selectedExpression instanceof Name && selectedExpression.getParent() instanceof ClassInstanceCreation)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_name_in_new);
//TODO: let's just take the CIC automatically (no ambiguity -> no problem -> no dialog ;-)
if (selectedExpression instanceof NullLiteral) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
} else if (selectedExpression instanceof ArrayInitializer) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
} else if (selectedExpression instanceof Assignment) {
if (selectedExpression.getParent() instanceof Expression)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
else
return null;
} else if (selectedExpression instanceof SimpleName){
if ((((SimpleName)selectedExpression)).isDeclaration())
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
if (selectedExpression.getParent() instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY
|| selectedExpression.getParent() instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
}
return null;
}
@Override
protected final void checkSelectedNodes() {
super.checkSelectedNodes();
RefactoringStatus status= getStatus();
if (status.hasFatalError())
return;
ASTNode node= getFirstSelectedNode();
if (node instanceof ArrayInitializer) {
status.addFatalError(RefactoringCoreMessages.CodeAnalyzer_array_initializer, JavaStatusContext.create(fCUnit, node));
}
}
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;
}
private static boolean addSuppressArgument(ASTRewrite rewrite, Expression value, StringLiteral newStringLiteral) {
if (value instanceof ArrayInitializer) {
ListRewrite listRewrite= rewrite.getListRewrite(value, ArrayInitializer.EXPRESSIONS_PROPERTY);
listRewrite.insertLast(newStringLiteral, null);
} else if (value instanceof StringLiteral) {
ArrayInitializer newArr= rewrite.getAST().newArrayInitializer();
newArr.expressions().add(rewrite.createMoveTarget(value));
newArr.expressions().add(newStringLiteral);
rewrite.replace(value, newArr, null);
} else {
return false;
}
return true;
}
public static void addRemoveUnusedSuppressWarningProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode coveringNode= problem.getCoveringNode(context.getASTRoot());
if (!(coveringNode instanceof StringLiteral))
return;
StringLiteral literal= (StringLiteral) coveringNode;
if (coveringNode.getParent() instanceof MemberValuePair) {
coveringNode= coveringNode.getParent();
}
ASTNode parent= coveringNode.getParent();
ASTRewrite rewrite= ASTRewrite.create(coveringNode.getAST());
if (parent instanceof SingleMemberAnnotation) {
rewrite.remove(parent, null);
} else if (parent instanceof NormalAnnotation) {
NormalAnnotation annot= (NormalAnnotation) parent;
if (annot.values().size() == 1) {
rewrite.remove(annot, null);
} else {
rewrite.remove(coveringNode, null);
}
} else if (parent instanceof ArrayInitializer) {
rewrite.remove(coveringNode, null);
} else {
return;
}
String label= Messages.format(CorrectionMessages.SuppressWarningsSubProcessor_remove_annotation_label, literal.getLiteralValue());
Image image= JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REMOVE_ANNOTATION, image);
proposals.add(proposal);
}
public boolean visit(ArrayInitializer expr) {
List expressions = expr.expressions();
for (int i = 0; i < expressions.size(); i++) {
handleExpression((Expression) expressions.get(i));
}
return false;
}
@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);
}
}
private void parseExpression(MethodInfo methodInfo, Expression expression) {
if (expression == null) {
return;
}//System.out.println(expression.toString()+" "+Annotation.nodeClassForType(expression.getNodeType()));
if (expression.getNodeType() == ASTNode.ARRAY_INITIALIZER) {
List<Expression> expressions = ((ArrayInitializer) expression).expressions();
for (Expression expression2 : expressions) {
parseExpression(methodInfo, expression2);
}
}
if (expression.getNodeType() == ASTNode.CAST_EXPRESSION) {
parseExpression(methodInfo, ((CastExpression) expression).getExpression());
}
if (expression.getNodeType() == ASTNode.CONDITIONAL_EXPRESSION) {
parseExpression(methodInfo, ((ConditionalExpression) expression).getExpression());
parseExpression(methodInfo, ((ConditionalExpression) expression).getElseExpression());
parseExpression(methodInfo, ((ConditionalExpression) expression).getThenExpression());
}
if (expression.getNodeType() == ASTNode.INFIX_EXPRESSION) {
parseExpression(methodInfo, ((InfixExpression) expression).getLeftOperand());
parseExpression(methodInfo, ((InfixExpression) expression).getRightOperand());
}
if (expression.getNodeType() == ASTNode.INSTANCEOF_EXPRESSION) {
parseExpression(methodInfo, ((InstanceofExpression) expression).getLeftOperand());
}
if (expression.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION) {
parseExpression(methodInfo, ((ParenthesizedExpression) expression).getExpression());
}
if (expression.getNodeType() == ASTNode.POSTFIX_EXPRESSION) {
parseExpression(methodInfo, ((PostfixExpression) expression).getOperand());
}
if (expression.getNodeType() == ASTNode.PREFIX_EXPRESSION) {
parseExpression(methodInfo, ((PrefixExpression) expression).getOperand());
}
if (expression.getNodeType() == ASTNode.THIS_EXPRESSION) {
parseExpression(methodInfo, ((ThisExpression) expression).getQualifier());
}
if (expression.getNodeType() == ASTNode.METHOD_INVOCATION) {
List<Expression> arguments = ((MethodInvocation) expression).arguments();
IMethodBinding methodBinding = ((MethodInvocation) expression).resolveMethodBinding();
if (methodBinding != null)
methodInfo.methodCalls.add(methodBinding);
for (Expression exp : arguments)
parseExpression(methodInfo, exp);
parseExpression(methodInfo, ((MethodInvocation) expression).getExpression());
}
if (expression.getNodeType() == ASTNode.ASSIGNMENT) {
parseExpression(methodInfo, ((Assignment) expression).getLeftHandSide());
parseExpression(methodInfo, ((Assignment) expression).getRightHandSide());
}
if (expression.getNodeType() == ASTNode.QUALIFIED_NAME) {
if (((QualifiedName) expression).getQualifier().resolveTypeBinding() != null) {
String name = ((QualifiedName) expression).getQualifier().resolveTypeBinding().getQualifiedName() + "." + ((QualifiedName) expression).getName().getIdentifier();
methodInfo.fieldUsesSet.add(name);
}
parseExpression(methodInfo, ((QualifiedName) expression).getQualifier());
}
}
@Override
public boolean visit(final ArrayCreation node) {
ArrayType at = node.getType();
int dims = at.getDimensions();
if ((dims > 1)) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("/* FIXME Only one dimensional arrays are supported. ");
_builder.append(node);
_builder.append("*/");
this.appendToBuffer(_builder.toString());
this.addProblem(node, "Only one dimension arrays are supported.");
return false;
}
ArrayInitializer _initializer = node.getInitializer();
boolean _tripleNotEquals = (_initializer != null);
if (_tripleNotEquals) {
if (this.fallBackStrategy) {
this.appendToBuffer("(");
}
node.getInitializer().accept(this);
if (this.fallBackStrategy) {
this.appendToBuffer(" as ");
at.accept(this);
this.appendToBuffer(")");
}
} else {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("new");
String _xifexpression = null;
boolean _isPrimitiveType = node.getType().getElementType().isPrimitiveType();
if (_isPrimitiveType) {
Type _elementType = node.getType().getElementType();
_xifexpression = StringExtensions.toFirstUpper(((PrimitiveType) _elementType).getPrimitiveTypeCode().toString());
}
_builder_1.append(_xifexpression);
_builder_1.append("ArrayOfSize(");
this.appendToBuffer(_builder_1.toString());
List _dimensions = node.dimensions();
(((Expression[])Conversions.unwrapArray(((Iterable<Expression>) _dimensions), Expression.class))[0]).accept(this);
this.appendToBuffer(")");
}
return false;
}
@Override
public boolean visit(ArrayInitializer node) {
if (node.expressions().size() > 10)
return false;
return super.visit(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 void endVisit(ArrayInitializer node) {
if (skipNode(node))
return;
processSequential(node, node.expressions());
}
@Override
public boolean visit(ArrayInitializer node) {
if (node.subtreeMatch(fMatcher, fNodeToMatch))
return matches(node);
return super.visit(node);
}
@Override
public boolean visit(ArrayInitializer node) {
add(fCreator.create(node));
return true;
}