Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorM N Palat2013-11-22 04:53:14 +0000
committerM N Palat2013-11-22 04:53:14 +0000
commitcd7ab76e97bbde2dfa388ac94141efed3a1c5385 (patch)
treef52057b23efea3bd48f437594975495070e0ffdf
parent55189ed648ac780e2783a409705c9c8b61eeced6 (diff)
downloadeclipse.jdt.core-cd7ab76e97bbde2dfa388ac94141efed3a1c5385.tar.gz
eclipse.jdt.core-cd7ab76e97bbde2dfa388ac94141efed3a1c5385.tar.xz
eclipse.jdt.core-cd7ab76e97bbde2dfa388ac94141efed3a1c5385.zip
Fix for Bug 417923 [1.8][dom ast] white space requirements for ArrayType
NASTFlattener and ASTRFlattener
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java6
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/TypeAnnotationsConverterTest.java16
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingMethodDeclTest.java6
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java830
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java4
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java6
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java115
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java2
8 files changed, 946 insertions, 39 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
index 1b53555a83..beb13e5486 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
@@ -1657,14 +1657,14 @@ public class ASTConverter18Test extends ConverterTestSetup {
Expression expression = fragment.getInitializer();
assertTrue(expression instanceof LambdaExpression);
LambdaExpression lambdaExpression = (LambdaExpression)expression;
- assertEquals("(int [] ia) -> {\n return ia.clone();\n}\n", lambdaExpression.toString());
+ assertEquals("(int[] ia) -> {\n return ia.clone();\n}\n", lambdaExpression.toString());
IMethodBinding binding = lambdaExpression.resolveMethodBinding();
assertEquals("private static java.lang.Object lambda$0(int[]) ", binding.toString());
assertTrue(lambdaExpression.parameters().size() == 1);
VariableDeclaration variableDeclaration = (VariableDeclaration) lambdaExpression.parameters().get(0);
assertTrue(variableDeclaration instanceof SingleVariableDeclaration);
SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration)variableDeclaration;
- assertEquals("int [] ia", singleVariableDeclaration.toString());
+ assertEquals("int[] ia", singleVariableDeclaration.toString());
}
/**
@@ -3342,7 +3342,7 @@ public class ASTConverter18Test extends ConverterTestSetup {
assertEquals("Incorrect no of fragments", 1, fragments.size());
VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
assertEquals("Unexpected type", fragment.resolveBinding().getType().toString(), "String @Marker{ value = (String)\"Extended\"} [] @Marker{ value = (String)\"i0\"} @Marker2 [] [] @Marker{ value = (String)\"i1\"} []");
- assertEquals("Unexpected type", field.getType().toString(), "String @Marker(\"i0\") @Marker2 [] [] @Marker(\"i1\") []");
+ assertEquals("Unexpected type", "String @Marker(\"i0\") @Marker2 [][] @Marker(\"i1\") []", field.getType().toString());
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=417669
public void testBug417669() throws JavaModelException {
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/TypeAnnotationsConverterTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/TypeAnnotationsConverterTest.java
index c7efeb04bd..c5d4c7557a 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/TypeAnnotationsConverterTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/TypeAnnotationsConverterTest.java
@@ -162,7 +162,7 @@ public class TypeAnnotationsConverterTest extends ConverterTestSetup {
"class Z<Q> {\n" +
" }\n" +
" }\n" +
- " Object o=(@Marker X<@Marker String>.@Marker Y<@Marker Integer>.@Marker Z<@Marker Object> @Marker [] [] @Marker [] [])null;\n" +
+ " Object o=(@Marker X<@Marker String>.@Marker Y<@Marker Integer>.@Marker Z<@Marker Object> @Marker [][] @Marker [][])null;\n" +
" @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}\n" +
"}\n";
assertASTNodeEquals(expectedOutput, node);
@@ -191,7 +191,7 @@ public class TypeAnnotationsConverterTest extends ConverterTestSetup {
"class Z<Q> {\n" +
" }\n" +
" }\n" +
- " Object o=(@Marker X<@Marker String>.@Marker Y<@Marker Integer>.@Marker Z<@Marker Object> [] @Marker [] [] @Marker [])null;\n" +
+ " Object o=(@Marker X<@Marker String>.@Marker Y<@Marker Integer>.@Marker Z<@Marker Object>[] @Marker [][] @Marker [])null;\n" +
" @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}\n" +
"}\n";
assertASTNodeEquals(expectedOutput, node);
@@ -204,7 +204,7 @@ public class TypeAnnotationsConverterTest extends ConverterTestSetup {
" class Z<Q> {\n" +
" }\n" +
" }\n" +
- " int [] [] [] [] o = (@One int [] @Two [] [] @Three []) null;\n" +
+ " int[][][][] o = (@One int[] @Two [][] @Three []) null;\n" +
" @java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
" @interface Marker {\n" +
@@ -220,7 +220,7 @@ public class TypeAnnotationsConverterTest extends ConverterTestSetup {
"class Z<Q> {\n" +
" }\n" +
" }\n" +
- " int [] [] [] [] o=(@One int [] @Two [] [] @Three [])null;\n" +
+ " int[][][][] o=(@One int[] @Two [][] @Three [])null;\n" +
" @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}\n" +
"}\n";
assertASTNodeEquals(expectedOutput, node);
@@ -233,7 +233,7 @@ public class TypeAnnotationsConverterTest extends ConverterTestSetup {
" class Z<Q> {\n" +
" }\n" +
" }\n" +
- " String [] [] [] [] o = (@One String [] @Two [] [] @Three []) null;\n" +
+ " String [][][][] o = (@One String[]@Two [][]@Three []) null;\n" +
" @java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
" @interface Marker {\n" +
@@ -249,7 +249,7 @@ public class TypeAnnotationsConverterTest extends ConverterTestSetup {
"class Z<Q> {\n" +
" }\n" +
" }\n" +
- " String [] [] [] [] o=(@One String [] @Two [] [] @Three [])null;\n" +
+ " String[][][][] o=(@One String[] @Two [][] @Three [])null;\n" +
" @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}\n" +
"}\n";
assertASTNodeEquals(expectedOutput, node);
@@ -262,7 +262,7 @@ public class TypeAnnotationsConverterTest extends ConverterTestSetup {
" class Z<Q> {\n" +
" }\n" +
" }\n" +
- " Object o = (@One X<String> [] @Two [] [] @Three []) null;\n" +
+ " Object o = (@One X<String> [] @Two [][]@Three []) null;\n" +
" @java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
" @interface Marker {\n" +
@@ -278,7 +278,7 @@ public class TypeAnnotationsConverterTest extends ConverterTestSetup {
"class Z<Q> {\n" +
" }\n" +
" }\n" +
- " Object o=(@One X<String> [] @Two [] [] @Three [])null;\n" +
+ " Object o=(@One X<String>[] @Two [][] @Three [])null;\n" +
" @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}\n" +
"}\n";
assertASTNodeEquals(expectedOutput, node);
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingMethodDeclTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingMethodDeclTest.java
index c92313a7d9..a3f4a006bf 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingMethodDeclTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingMethodDeclTest.java
@@ -3248,9 +3248,9 @@ public class ASTRewritingMethodDeclTest extends ASTRewritingTest {
buf.append("package test1;\n");
buf.append("import java.lang.annotation.ElementType;\n");
buf.append("public abstract class E {\n");
- buf.append(" public Object foo1()[] @Annot1 [] @Annot2 [] { return null; }\n");
- buf.append(" public Object foo2()[] @Annot1 [] throws ArrayStoreException { return null; }\n");
- buf.append(" public Object foo3() @Annot1 [] @Annot1 @Annot2 [] @Annot2 [] { return null; }\n");
+ buf.append(" public Object foo1()[]@Annot1 []@Annot2 [] { return null; }\n");
+ buf.append(" public Object foo2()[]@Annot1 [] throws ArrayStoreException { return null; }\n");
+ buf.append(" public Object foo3() @Annot1 [] @Annot1 @Annot2 []@Annot2 [] { return null; }\n");
buf.append(" public Object foo4()@Annot2 @Annot1 [] @Annot2 @Annot1 [] throws IllegalArgumentException { return null; }\n");
buf.append(" public Object foo5() [] @Annot2 @Annot1 [] { return null; }\n");
buf.append(" public Object foo6(int i) [] [] throws IllegalArgumentException { return null; }\n");
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java
index fe13150849..e8d0a163d4 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java
@@ -57,6 +57,7 @@ import org.eclipse.jdt.core.dom.ReturnStatement;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SimplePropertyDescriptor;
import org.eclipse.jdt.core.dom.SimpleType;
+import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.Statement;
import org.eclipse.jdt.core.dom.StringLiteral;
@@ -68,6 +69,7 @@ import org.eclipse.jdt.core.dom.TryStatement;
import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.TypeDeclarationStatement;
+import org.eclipse.jdt.core.dom.TypeLiteral;
import org.eclipse.jdt.core.dom.UnionType;
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
@@ -6039,7 +6041,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
buf.append("import java.lang.annotation.ElementType;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
- buf.append(" int [] i [] @Annot1 @Annot2 [] @Annot1 @Annot3 [] = new int @Annot1 @Annot2 [2] @Annot2 @Annot3 [size()] @Annot2 @Annot1 [][]@Annot3 @Annot2 @Annot1 [];\n");
+ buf.append(" int [] i []@Annot1 @Annot2 [] @Annot1 @Annot3 [] = new int @Annot1 @Annot2 [2] @Annot2 @Annot3 [size()] @Annot2 @Annot1 [][] @Annot3 @Annot2 @Annot1 [];\n");
buf.append(" int [] j [][] = new int @Annot2 [2] @Annot2 [] @Annot1 [], k [][] = new int [2] [10] [size()];\n");
buf.append(" }\n");
buf.append(" public int size() { return 2; }\n");
@@ -6059,7 +6061,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
buf.append("import java.lang.annotation.ElementType;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
- buf.append(" int [] i [][] = new int @Annot1 @Annot2 [2] @Annot2 @Annot3 [size(new int[][]{})] [];\n");
+ buf.append(" int [] i [][] = new int @Annot1 @Annot2 [2]@Annot2 @Annot3[size(new int[][]{})] [];\n");
buf.append(" int [] j [][] = new int @Annot1 @Annot2 [2] @Annot2 @Annot3 [size(new int[]{})] @Annot1 @Annot3 [], k [][] = new int @Annot1 @Annot2 [2] @Annot2 @Annot3 [10] @Annot1 @Annot3 [size(new int[][]{})];\n");
buf.append(" }\n");
buf.append(" public int size(Object obj) { return 2; }\n");
@@ -6094,7 +6096,6 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
listRewrite.remove((ASTNode)dim.annotations().get(0), null);
listRewrite.remove((ASTNode)dim.annotations().get(1), null);
- rewrite.set(creation, ArrayCreation.TYPE_PROPERTY, arrayType, null);
}
{
statement = (VariableDeclarationStatement) statements.get(1);
@@ -6120,7 +6121,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
buf.append("import java.lang.annotation.ElementType;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
- buf.append(" int [] i [][] = new int @Annot1 @Annot2 [2] [size(new int[][]{})] [];\n");
+ buf.append(" int [] i [][] = new int @Annot1 @Annot2 [2][size(new int[][]{})] [];\n");
buf.append(" int [] j [][] = new int @Annot1 @Annot2 [2] @Annot2 @Annot3 [size(new int[]{})], k [][] = new int @Annot1 @Annot2 [2] @Annot2 @Annot3 [10];\n");
buf.append(" }\n");
buf.append(" public int size(Object obj) { return 2; }\n");
@@ -6156,7 +6157,826 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
assertTrue("Incorrect Formatting", doc.get().equals(formattedString));
}
-}
+ public void testBug417923a_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int [] i [][] = new int @Annot1[][][];\n");
+ buf.append(" int [] j [][] = new int @Annot1 [][][];\n");
+ buf.append(" int [] k [][] = new int @Annot1 [][][];\n");
+ buf.append(" int [] l [][] = new int /* comment @ [] */@Annot1[][][];\n");
+ buf.append(" int [] m [][] = new int /* comment @ [] */ @Annot1[][][];\n");
+ buf.append(" int [] n [][] = new int /* comment @ [] */ @Annot1 [][][];\n");
+ buf.append(" int [] o [][] = new int @Annot1/* comment @ [] */[][][];\n");
+ buf.append(" int [] p [][] = new int @Annot1 /* comment @ [] */ [][][];\n");
+ buf.append(" int [] q [][] = new int @Annot1 /* comment @ [] */[][][];\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ AST ast = astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+
+ TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
+ MethodDeclaration methodDecl= typeDecl.getMethods()[0];
+ Block block= methodDecl.getBody();
+ List statements= block.statements();
+
+ for (int i = 0; i < 9; ++i) {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ ArrayCreation creation = (ArrayCreation) fragment.getInitializer();
+ ArrayType arrayType = ast.newArrayType(ast.newPrimitiveType(PrimitiveType.INT), 3);
+ rewrite.set(creation, ArrayCreation.TYPE_PROPERTY, arrayType, null);
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int [] i [][] = new int[][][];\n");
+ buf.append(" int [] j [][] = new int[][][];\n");
+ buf.append(" int [] k [][] = new int[][][];\n");
+ buf.append(" int [] l [][] = new int[][][];\n");
+ buf.append(" int [] m [][] = new int[][][];\n");
+ buf.append(" int [] n [][] = new int[][][];\n");
+ buf.append(" int [] o [][] = new int[][][];\n");
+ buf.append(" int [] p [][] = new int[][][];\n");
+ buf.append(" int [] q [][] = new int[][][];\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ assertEqualString(preview, buf.toString());
+ }
+ public void testBug417923b_since_8() throws Exception {
+ IPackageFragment pack1 = this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int [] i [][] = new int[] @Annot1[][];\n");
+ buf.append(" int [] j [][] = new int[] @Annot1 [][];\n");
+ buf.append(" int [] k [][] = new int[] @Annot1 [][];\n");
+ buf.append(" int [] l [][] = new int[] /* comment @ [] */@Annot1[][];\n");
+ buf.append(" int [] m [][] = new int[] /* comment @ [] */ @Annot1[][];\n");
+ buf.append(" int [] n [][] = new int[] /* comment @ [] */ @Annot1 [][];\n");
+ buf.append(" int [] o [][] = new int[] @Annot1/* comment @ [] */[][];\n");
+ buf.append(" int [] p [][] = new int[] @Annot1 /* comment @ [] */ [][];\n");
+ buf.append(" int [] q [][] = new int[] @Annot1 /* comment @ [] */[][];\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ AST ast = astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+
+ TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
+ MethodDeclaration methodDecl= typeDecl.getMethods()[0];
+ Block block= methodDecl.getBody();
+ List statements= block.statements();
+
+ for (int i = 0; i < 9; ++i) {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ ArrayCreation creation = (ArrayCreation) fragment.getInitializer();
+ ArrayType arrayType = ast.newArrayType(ast.newPrimitiveType(PrimitiveType.INT), 3);
+ rewrite.set(creation, ArrayCreation.TYPE_PROPERTY, arrayType, null);
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int [] i [][] = new int[][][];\n");
+ buf.append(" int [] j [][] = new int[][][];\n");
+ buf.append(" int [] k [][] = new int[][][];\n");
+ buf.append(" int [] l [][] = new int[][][];\n");
+ buf.append(" int [] m [][] = new int[][][];\n");
+ buf.append(" int [] n [][] = new int[][][];\n");
+ buf.append(" int [] o [][] = new int[][][];\n");
+ buf.append(" int [] p [][] = new int[][][];\n");
+ buf.append(" int [] q [][] = new int[][][];\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ public void testBug417923c_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int [] i [][] = new int @Annot1[][][];\n");
+ buf.append(" int [] j [][] = new int @Annot1 [][][];\n");
+ buf.append(" int [] k [][] = new int @Annot1 [][][];\n");
+ buf.append(" int [] l [][] = new int /* comment @ [] */@Annot1[][][];\n");
+ buf.append(" int [] m [][] = new int /* comment @ [] */ @Annot1[][][];\n");
+ buf.append(" int [] n [][] = new int /* comment @ [] */ @Annot1 [][][];\n");
+ buf.append(" int [] o [][] = new int @Annot1/* comment @ [] */[][][];\n");
+ buf.append(" int [] p [][] = new int @Annot1 /* comment @ [] */ [][][];\n");
+ buf.append(" int [] q [][] = new int @Annot1 /* comment @ [] */[][][];\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ AST ast = astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+
+ TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
+ MethodDeclaration methodDecl= typeDecl.getMethods()[0];
+ Block block= methodDecl.getBody();
+ List statements= block.statements();
+
+ for (int i = 0; i < 9; ++i) {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ ArrayCreation creation = (ArrayCreation) fragment.getInitializer();
+ ArrayType arrayType = creation.getType();
+
+ Dimension dim = (Dimension) arrayType.dimensions().get(0);
+ ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
+ listRewrite.remove((ASTNode)dim.annotations().get(0), null);
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int [] i [][] = new int[][][];\n");
+ buf.append(" int [] j [][] = new int[][][];\n");
+ buf.append(" int [] k [][] = new int[][][];\n");
+ buf.append(" int [] l [][] = new int [][][];\n");
+ buf.append(" int [] m [][] = new int /* comment @ [] */[][][];\n");
+ buf.append(" int [] n [][] = new int /* comment @ [] */[][][];\n");
+ buf.append(" int [] o [][] = new int/* comment @ [] */[][][];\n");
+ buf.append(" int [] p [][] = new int/* comment @ [] */ [][][];\n");
+ buf.append(" int [] q [][] = new int/* comment @ [] */[][][];\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ public void testBug417923d_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int [] i [][] = new int[] @Annot1[][];\n");
+ buf.append(" int [] j [][] = new int[] @Annot1 [][];\n");
+ buf.append(" int [] k [][] = new int[] @Annot1 [][];\n");
+ buf.append(" int [] l [][] = new int[] /* comment @ [] */@Annot1[][];\n");
+ buf.append(" int [] m [][] = new int[] /* comment @ [] */ @Annot1[][];\n");
+ buf.append(" int [] n [][] = new int[] /* comment @ [] */ @Annot1 [][];\n");
+ buf.append(" int [] o [][] = new int[] @Annot1/* comment @ [] */[][];\n");
+ buf.append(" int [] p [][] = new int[] @Annot1 /* comment @ [] */ [][];\n");
+ buf.append(" int [] q [][] = new int[] @Annot1 /* comment @ [] */[][];\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ AST ast = astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+
+ TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
+ MethodDeclaration methodDecl= typeDecl.getMethods()[0];
+ Block block= methodDecl.getBody();
+ List statements= block.statements();
+
+ for (int i = 0; i < 9; ++i) {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ ArrayCreation creation = (ArrayCreation) fragment.getInitializer();
+ ArrayType arrayType = creation.getType();
+
+ Dimension dim = (Dimension) arrayType.dimensions().get(1);
+ ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
+ listRewrite.remove((ASTNode)dim.annotations().get(0), null);
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int [] i [][] = new int[][][];\n");
+ buf.append(" int [] j [][] = new int[][][];\n");
+ buf.append(" int [] k [][] = new int[][][];\n");
+ buf.append(" int [] l [][] = new int[] [][];\n");
+ buf.append(" int [] m [][] = new int[] /* comment @ [] */[][];\n");
+ buf.append(" int [] n [][] = new int[] /* comment @ [] */[][];\n");
+ buf.append(" int [] o [][] = new int[]/* comment @ [] */[][];\n");
+ buf.append(" int [] p [][] = new int[]/* comment @ [] */ [][];\n");
+ buf.append(" int [] q [][] = new int[]/* comment @ [] */[][];\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ public void testBug417923e_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int[][][] i = new int[][][];\n");
+ buf.append(" int[][][] j = new int [][][];\n");
+ buf.append(" int[][][] k = new int [][][];\n");
+ buf.append(" int[][][] l = new int/* comment */[][][];\n");
+ buf.append(" int[][][] m = new int /* comment [] */ [][][];\n");
+ buf.append(" int[][][] n = new int /* comment [] */ [][][];\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ AST ast = astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+
+ TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
+ MethodDeclaration methodDecl= typeDecl.getMethods()[0];
+ Block block= methodDecl.getBody();
+ List statements= block.statements();
+
+ for (int i = 0; i < 6; ++i) {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ ArrayCreation creation = (ArrayCreation) fragment.getInitializer();
+ ArrayType arrayType = creation.getType();
+
+ Dimension dim = (Dimension) arrayType.dimensions().get(0);
+ ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
+ MarkerAnnotation markerAnnotation= ast.newMarkerAnnotation();
+ markerAnnotation.setTypeName(ast.newSimpleName("Annot1"));
+ listRewrite.insertAt(markerAnnotation, 0, null);
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int[][][] i = new int @Annot1 [][][];\n");
+ buf.append(" int[][][] j = new int @Annot1 [][][];\n");
+ buf.append(" int[][][] k = new int @Annot1 [][][];\n");
+ buf.append(" int[][][] l = new int @Annot1 /* comment */[][][];\n");
+ buf.append(" int[][][] m = new int @Annot1 /* comment [] */ [][][];\n");
+ buf.append(" int[][][] n = new int @Annot1 /* comment [] */ [][][];\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ public void testBug417923f_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int[][][] i = new int[][][];\n");
+ buf.append(" int[][][] j = new int[] [][];\n");
+ buf.append(" int[][][] k = new int[] [][];\n");
+ buf.append(" int[][][] l = new int[]/* comment */[][];\n");
+ buf.append(" int[][][] m = new int[] /* comment [] */ [][];\n");
+ buf.append(" int[][][] n = new int[] /* comment [] */ [][];\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ AST ast = astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+
+ TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
+ MethodDeclaration methodDecl= typeDecl.getMethods()[0];
+ Block block= methodDecl.getBody();
+ List statements= block.statements();
+
+ for (int i = 0; i < 6; ++i) {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ ArrayCreation creation = (ArrayCreation) fragment.getInitializer();
+ ArrayType arrayType = creation.getType();
+
+ Dimension dim = (Dimension) arrayType.dimensions().get(1);
+ ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
+ MarkerAnnotation markerAnnotation= ast.newMarkerAnnotation();
+ markerAnnotation.setTypeName(ast.newSimpleName("Annot1"));
+ listRewrite.insertAt(markerAnnotation, 0, null);
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int[][][] i = new int[] @Annot1 [][];\n");
+ buf.append(" int[][][] j = new int[] @Annot1 [][];\n");
+ buf.append(" int[][][] k = new int[] @Annot1 [][];\n");
+ buf.append(" int[][][] l = new int[] @Annot1 /* comment */[][];\n");
+ buf.append(" int[][][] m = new int[] @Annot1 /* comment [] */ [][];\n");
+ buf.append(" int[][][] n = new int[] @Annot1 /* comment [] */ [][];\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ public void testBug417923g_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int[][][] i;\n");
+ buf.append(" int [][][] j;\n");
+ buf.append(" int [][][] k;\n");
+ buf.append(" int/* comment */[][][] l;\n");
+ buf.append(" int /* comment [] */ [][][] m;\n");
+ buf.append(" int /* comment [] */ [][][] n;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ AST ast = astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+
+ TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
+ MethodDeclaration methodDecl= typeDecl.getMethods()[0];
+ Block block= methodDecl.getBody();
+ List statements= block.statements();
+
+ for (int i = 0; i < 6; ++i) {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
+ ArrayType arrayType = (ArrayType) statement.getType();
+ Dimension dim = (Dimension) arrayType.dimensions().get(0);
+ ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
+ MarkerAnnotation markerAnnotation= ast.newMarkerAnnotation();
+ markerAnnotation.setTypeName(ast.newSimpleName("Annot1"));
+ listRewrite.insertAt(markerAnnotation, 0, null);
+ }
+ String preview= evaluateRewrite(cu, rewrite);
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int @Annot1 [][][] i;\n");
+ buf.append(" int @Annot1 [][][] j;\n");
+ buf.append(" int @Annot1 [][][] k;\n");
+ buf.append(" int @Annot1 /* comment */[][][] l;\n");
+ buf.append(" int @Annot1 /* comment [] */ [][][] m;\n");
+ buf.append(" int @Annot1 /* comment [] */ [][][] n;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ assertEqualString(preview, buf.toString());
+ }
+ public void testBug417923h_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int[][][] i;\n");
+ buf.append(" int[] [][] j;\n");
+ buf.append(" int[] [][] k;\n");
+ buf.append(" int[]/* comment */[][] l;\n");
+ buf.append(" int[] /* comment [] */ [][] m;\n");
+ buf.append(" int[] /* comment [] */ [][] n;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ AST ast = astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+
+ TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
+ MethodDeclaration methodDecl= typeDecl.getMethods()[0];
+ Block block= methodDecl.getBody();
+ List statements= block.statements();
+
+ for (int i = 0; i < 6; ++i) {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
+ ArrayType arrayType = (ArrayType) statement.getType();
+ Dimension dim = (Dimension) arrayType.dimensions().get(1);
+ ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
+ MarkerAnnotation markerAnnotation= ast.newMarkerAnnotation();
+ markerAnnotation.setTypeName(ast.newSimpleName("Annot1"));
+ listRewrite.insertAt(markerAnnotation, 0, null);
+ }
+ String preview= evaluateRewrite(cu, rewrite);
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int[] @Annot1 [][] i;\n");
+ buf.append(" int[] @Annot1 [][] j;\n");
+ buf.append(" int[] @Annot1 [][] k;\n");
+ buf.append(" int[] @Annot1 /* comment */[][] l;\n");
+ buf.append(" int[] @Annot1 /* comment [] */ [][] m;\n");
+ buf.append(" int[] @Annot1 /* comment [] */ [][] n;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ public void testBug417923i_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int @Annot1[][][] i;\n");
+ buf.append(" int @Annot1 [][][] j;\n");
+ buf.append(" int @Annot1 [][][] k;\n");
+ buf.append(" int/* comment @ [] */@Annot1[][][] l;\n");
+ buf.append(" int /* comment @ [] */ @Annot1[][][] m;\n");
+ buf.append(" int /* comment @ [] */ @Annot1 [][][] n;\n");
+ buf.append(" int @Annot1/* comment @ [] */[][][] o;\n");
+ buf.append(" int @Annot1 /* comment @ [] */ [][][] p;\n");
+ buf.append(" int @Annot1 /* comment @ [] */[][][] q;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ AST ast = astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+
+ TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
+ MethodDeclaration methodDecl= typeDecl.getMethods()[0];
+ Block block= methodDecl.getBody();
+ List statements= block.statements();
+
+ for (int i = 0; i < 9; ++i) {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
+ ArrayType arrayType = (ArrayType) statement.getType();
+ Dimension dim = (Dimension) arrayType.dimensions().get(0);
+ ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
+ listRewrite.remove((ASTNode) dim.annotations().get(0), null);
+ }
+ String preview= evaluateRewrite(cu, rewrite);
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int[][][] i;\n");
+ buf.append(" int[][][] j;\n");
+ buf.append(" int[][][] k;\n");
+ buf.append(" int[][][] l;\n");
+ buf.append(" int /* comment @ [] */[][][] m;\n");
+ buf.append(" int /* comment @ [] */[][][] n;\n");
+ buf.append(" int/* comment @ [] */[][][] o;\n");
+ buf.append(" int/* comment @ [] */ [][][] p;\n");
+ buf.append(" int/* comment @ [] */[][][] q;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ public void testBug417923j_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int[] @Annot1[][] i;\n");
+ buf.append(" int[] @Annot1 [][] j;\n");
+ buf.append(" int[] @Annot1 [][] k;\n");
+ buf.append(" int[]/* comment @ [] */@Annot1[][] l;\n");
+ buf.append(" int[] /* comment @ [] */ @Annot1[][] m;\n");
+ buf.append(" int[] /* comment @ [] */ @Annot1 [][] n;\n");
+ buf.append(" int[] @Annot1/* comment @ [] */[][] o;\n");
+ buf.append(" int[] @Annot1 /* comment @ [] */ [][] p;\n");
+ buf.append(" int[] @Annot1 /* comment @ [] */[][] q;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ AST ast = astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+ TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
+ MethodDeclaration methodDecl= typeDecl.getMethods()[0];
+ Block block= methodDecl.getBody();
+ List statements= block.statements();
+ for (int i = 0; i < 9; ++i) {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
+ ArrayType arrayType = (ArrayType) statement.getType();
+ Dimension dim = (Dimension) arrayType.dimensions().get(1);
+ ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
+ listRewrite.remove((ASTNode) dim.annotations().get(0), null);
+ }
+ String preview= evaluateRewrite(cu, rewrite);
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int[][][] i;\n");
+ buf.append(" int[][][] j;\n");
+ buf.append(" int[][][] k;\n");
+ buf.append(" int[][][] l;\n");
+ buf.append(" int[] /* comment @ [] */[][] m;\n");
+ buf.append(" int[] /* comment @ [] */[][] n;\n");
+ buf.append(" int[]/* comment @ [] */[][] o;\n");
+ buf.append(" int[]/* comment @ [] */ [][] p;\n");
+ buf.append(" int[]/* comment @ [] */[][] q;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ assertEqualString(preview, buf.toString());
+ }
+ public void testBug417923k_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int [] i [][] = new int[] @Annot1 @Annot2[][];\n");
+ buf.append(" int [] j [][] = new int[] @Annot1 @Annot2 [][];\n");
+ buf.append(" int [] k [][] = new int[] @Annot1 @Annot2 [][];\n");
+ buf.append(" int [] l [][] = new int[] /* comment @ [] */@Annot1 @Annot2[][];\n");
+ buf.append(" int [] m [][] = new int[] /* comment @ [] */ @Annot1 @Annot2 [][];\n");
+ buf.append(" int [] n [][] = new int[] /* comment @ [] */ @Annot1 @Annot2 [][];\n");
+ buf.append(" int [] o [][] = new int[] @Annot1 @Annot2/* comment @ [] */[][];\n");
+ buf.append(" int [] p [][] = new int[] @Annot1 @Annot2/* comment @ [] */ [][];\n");
+ buf.append(" int [] q [][] = new int[] @Annot1 @Annot2/* comment @ [] */[][];\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ AST ast = astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+
+ TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
+ MethodDeclaration methodDecl= typeDecl.getMethods()[0];
+ Block block= methodDecl.getBody();
+ List statements= block.statements();
+
+ for (int i = 0; i < 9; ++i) {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ ArrayCreation creation = (ArrayCreation) fragment.getInitializer();
+ ArrayType arrayType = creation.getType();
+
+ Dimension dim = (Dimension) arrayType.dimensions().get(1);
+ ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
+ listRewrite.remove((ASTNode)dim.annotations().get(1), null);
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int [] i [][] = new int[] @Annot1[][];\n");
+ buf.append(" int [] j [][] = new int[] @Annot1 [][];\n");
+ buf.append(" int [] k [][] = new int[] @Annot1 [][];\n");
+ buf.append(" int [] l [][] = new int[] /* comment @ [] */@Annot1[][];\n");
+ buf.append(" int [] m [][] = new int[] /* comment @ [] */ @Annot1 [][];\n");
+ buf.append(" int [] n [][] = new int[] /* comment @ [] */ @Annot1 [][];\n");
+ buf.append(" int [] o [][] = new int[] @Annot1/* comment @ [] */[][];\n");
+ buf.append(" int [] p [][] = new int[] @Annot1/* comment @ [] */ [][];\n");
+ buf.append(" int [] q [][] = new int[] @Annot1/* comment @ [] */[][];\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ public void testBug417923l_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int[] @Annot1 @Annot2[][] i;\n");
+ buf.append(" int[] @Annot1 @Annot2 [][] j;\n");
+ buf.append(" int[] @Annot1 @Annot2 [][] k;\n");
+ buf.append(" int[]/* comment @ [] */@Annot1 @Annot2[][] l;\n");
+ buf.append(" int[] /* comment @ [] */ @Annot1 @Annot2 [][] m;\n");
+ buf.append(" int[] /* comment @ [] */ @Annot1 @Annot2 [][] n;\n");
+ buf.append(" int[] @Annot1 @Annot2/* comment @ [] */[][] o;\n");
+ buf.append(" int[] @Annot1 @Annot2/* comment @ [] */ [][] p;\n");
+ buf.append(" int[] @Annot1 @Annot2/* comment @ [] */[][] q;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ AST ast = astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+
+ TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
+ MethodDeclaration methodDecl= typeDecl.getMethods()[0];
+ Block block= methodDecl.getBody();
+ List statements= block.statements();
+
+ for (int i = 0; i < 9; ++i) {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
+ ArrayType arrayType = (ArrayType) statement.getType();
+ Dimension dim = (Dimension) arrayType.dimensions().get(1);
+ ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
+ listRewrite.remove((ASTNode) dim.annotations().get(1), null);
+ }
+ String preview= evaluateRewrite(cu, rewrite);
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int[] @Annot1[][] i;\n");
+ buf.append(" int[] @Annot1 [][] j;\n");
+ buf.append(" int[] @Annot1 [][] k;\n");
+ buf.append(" int[]/* comment @ [] */@Annot1[][] l;\n");
+ buf.append(" int[] /* comment @ [] */ @Annot1 [][] m;\n");
+ buf.append(" int[] /* comment @ [] */ @Annot1 [][] n;\n");
+ buf.append(" int[] @Annot1/* comment @ [] */[][] o;\n");
+ buf.append(" int[] @Annot1/* comment @ [] */ [][] p;\n");
+ buf.append(" int[] @Annot1/* comment @ [] */[][] q;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ public void testBug417923m_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int @Annot1(value1 = 2, value2 = 10) [][] i;\n");
+ buf.append(" int[] @Annot2(float[].class) [] j;\n");
+ buf.append(" int[][] k;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {\n");
+ buf.append(" int value1() default 1;\n");
+ buf.append(" int value2();\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot2 {\n");
+ buf.append(" @SuppressWarnings(\"rawtypes\")\n");
+ buf.append(" Class value() default int[].class;\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ AST ast = astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+
+ TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
+ MethodDeclaration methodDecl= typeDecl.getMethods()[0];
+ Block block= methodDecl.getBody();
+ List statements= block.statements();
+
+ {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(0);
+ ArrayType arrayType = (ArrayType) statement.getType();
+ Dimension dim = (Dimension) arrayType.dimensions().get(0);
+ ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
+ listRewrite.remove((ASTNode) dim.annotations().get(0), null);
+ }
+ {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(1);
+ ArrayType arrayType = (ArrayType) statement.getType();
+ Dimension dim = (Dimension) arrayType.dimensions().get(1);
+ ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
+ listRewrite.remove((ASTNode) dim.annotations().get(0), null);
+ }
+ {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(1);
+ ArrayType arrayType = (ArrayType) statement.getType();
+ Dimension dim = (Dimension) arrayType.dimensions().get(1);
+ ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
+ listRewrite.remove((ASTNode) dim.annotations().get(0), null);
+ }
+ {
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(2);
+ ArrayType arrayType = (ArrayType) statement.getType();
+
+ SingleMemberAnnotation annotation = ast.newSingleMemberAnnotation();
+ annotation.setTypeName(ast.newSimpleName("Annot2"));
+ ArrayType type = ast.newArrayType(ast.newPrimitiveType(PrimitiveType.FLOAT), 1);
+ TypeLiteral literal = ast.newTypeLiteral();
+ literal.setType(type);
+ annotation.setValue(literal);
+ Dimension dim = (Dimension) arrayType.dimensions().get(1);
+ ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
+ listRewrite.insertFirst(annotation, null);
+ }
+ String preview= evaluateRewrite(cu, rewrite);
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("import java.lang.annotation.ElementType;\n");
+ buf.append("public class X {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" int[][] i;\n");
+ buf.append(" int[][] j;\n");
+ buf.append(" int[] @Annot2(float[].class) [] k;\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot1 {\n");
+ buf.append(" int value1() default 1;\n");
+ buf.append(" int value2();\n");
+ buf.append("}\n");
+ buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
+ buf.append("@interface Annot2 {\n");
+ buf.append(" @SuppressWarnings(\"rawtypes\")\n");
+ buf.append(" Class value() default int[].class;\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java
index 9ca40c574a..af51d8c808 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java
@@ -1738,7 +1738,7 @@ public class ASTRewritingTypeDeclTest extends ASTRewritingTest {
buf.append("import java.lang.annotation.ElementType;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
- buf.append(" int i, j, k = 0, x, y [] [] [], z @Annot1 [], zz @Annot2 @Annot2[] = {0, 1};\n");
+ buf.append(" int i, j, k = 0, x, y[][][], z @Annot1 [], zz @Annot2 @Annot2[] = {0, 1};\n");
buf.append(" }\n");
buf.append("}\n");
buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
@@ -1849,7 +1849,7 @@ public class ASTRewritingTypeDeclTest extends ASTRewritingTest {
buf.append("import java.lang.annotation.ElementType;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
- buf.append(" int a @Annot1 @Annot2 [], j = 1, k @Annot1 @Annot2 [], x @Annot1 @Annot2 [] = null, y @Annot1[] @Annot2[], zz @Annot2 @Annot2[] = {0, 1};\n");
+ buf.append(" int a @Annot1 @Annot2 [], j = 1, k @Annot1 @Annot2 [], x @Annot1 @Annot2 [] = null, y @Annot1 [] @Annot2 [], zz @Annot2 @Annot2[] = {0, 1};\n");
buf.append(" }\n");
buf.append("}\n");
buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java
index a09f0a4f4b..c31466615e 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java
@@ -620,8 +620,10 @@ public class NaiveASTFlattener extends ASTVisitor {
}
public boolean visit(Dimension node) {
- this.buffer.append(" ");//$NON-NLS-1$
- visitAnnotationsList(node.annotations());
+ List annotations = node.annotations();
+ if (annotations.size() > 0)
+ this.buffer.append(' ');
+ visitAnnotationsList(annotations);
this.buffer.append("[]"); //$NON-NLS-1$
return false;
}
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
index 669e4c44da..749c2f2e8f 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
@@ -1266,7 +1266,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor {
}
protected int rewriteExtraDimensionsInfo(ASTNode node, int pos, ChildListPropertyDescriptor property) {
- return rewriteNodeList(node, property, pos, " ", " "); //$NON-NLS-1$ //$NON-NLS-2$
+ return rewriteNodeList(node, property, pos, " ", ""); //$NON-NLS-1$ //$NON-NLS-2$
}
private int rewriteExtraDimensions(ASTNode parent, StructuralPropertyDescriptor property, int pos) {
@@ -1913,11 +1913,68 @@ public final class ASTRewriteAnalyzer extends ASTVisitor {
return offset;
}
+ private ASTNode getPreviousNode(ASTNode node) {
+ ArrayType arrayType = (ArrayType) node.getParent();
+ ASTNode prev = arrayType.getElementType();
+ List l = (List) node.getParent().getStructuralProperty(node.getLocationInParent());
+ int size = l.size();
+ int i = 0;
+ for (; i < size; i++) {
+ ASTNode currNode = (ASTNode) l.get(i);
+ if (node == currNode) break;
+ prev = currNode;
+ }
+ return i < size ? prev : null;
+ }
+
+ private int getPreviousTokenEndOffset(ASTNode node, int token) {
+ int offset = -1;
+ ASTNode prev = getPreviousNode(node);
+ if (prev != null) {
+ offset = prev.getStartPosition() + prev.getLength();
+ try {
+ offset = getScanner().getPreviousTokenEndOffset(token, offset);
+ } catch (CoreException e1) {
+ e1.printStackTrace();
+ }
+ }
+ return offset;
+ }
+
public boolean visit(Dimension node) {
if (!hasChildrenChanges(node)) {
return doVisitUnchangedChildren(node);
}
- rewriteNodeList(node, Dimension.ANNOTATIONS_PROPERTY, node.getStartPosition(), Util.EMPTY_STRING, " "); //$NON-NLS-1$
+
+ boolean keywordSpace = true;
+ ASTNode parent = node.getParent();
+ if (parent.getNodeType() == ASTNode.ARRAY_TYPE) {
+ List oldAnnotations = (List) getOriginalValue(node, Dimension.ANNOTATIONS_PROPERTY);
+ List newAnnotations = (List) getNewValue(node, Dimension.ANNOTATIONS_PROPERTY);
+ int oldAnnotationSize = oldAnnotations.size();
+ int newAnnotationSize = newAnnotations.size();
+ if (oldAnnotationSize > 0 && newAnnotationSize == 0) { /* removed all annotations */
+ int delStart = getPreviousTokenEndOffset(node, TerminalTokens.TokenNameAT);
+ int delEnd = ((ASTNode) oldAnnotations.get(0)).getStartPosition();
+ if (delStart >= 0 && delEnd > delStart) {
+ doTextRemove(delStart, delEnd - delStart, null); /* remove spaces before the annotation */
+ }
+
+ ASTNode currNode = (ASTNode) oldAnnotations.get(oldAnnotationSize - 1);
+ delStart = currNode.getStartPosition() + currNode.getLength();
+ try {
+ delEnd = getScanner().getNextStartOffset(delStart, false);
+ doTextRemove(delStart, delEnd - delStart, null); /* remove spaces after the annotation */
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ } else if (oldAnnotationSize == 0 && newAnnotationSize > 0) { /* inserting first annotation */
+ if (ScannerHelper.isWhitespace(this.content[node.getStartPosition() - 1])) {
+ keywordSpace = false; /* space exists already */
+ }
+ }
+ }
+ rewriteNodeList(node, Dimension.ANNOTATIONS_PROPERTY, node.getStartPosition(), keywordSpace ? String.valueOf(' ') : Util.EMPTY_STRING, String.valueOf(' '), String.valueOf(' '));
return false;
}
@@ -2058,10 +2115,13 @@ public final class ASTRewriteAnalyzer extends ASTVisitor {
ArrayType arrayType= (ArrayType) getOriginalValue(node, ArrayCreation.TYPE_PROPERTY);
ArrayType replacingType= arrayType;
int nOldBrackets= getDimensions(arrayType); // number of total brackets
+ boolean astLevelGTE8 = node.getAST().apiLevel() >= AST.JLS8;
+ boolean typeReplaced = false;
TextEditGroup editGroup= null;
RewriteEvent typeEvent= getEvent(node, ArrayCreation.TYPE_PROPERTY);
if (typeEvent != null && typeEvent.getChangeKind() == RewriteEvent.REPLACED) { // changed arraytype can have different dimension or type name
+ typeReplaced = true;
replacingType= (ArrayType) typeEvent.getNewValue();
editGroup= getEditGroup(typeEvent);
Type newType= replacingType.getElementType();
@@ -2080,16 +2140,17 @@ public final class ASTRewriteAnalyzer extends ASTVisitor {
RewriteEvent dimEvent= getEvent(node, ArrayCreation.DIMENSIONS_PROPERTY);
boolean hasDimensionChanges= (dimEvent != null && dimEvent.getChangeKind() != RewriteEvent.UNCHANGED);
RewriteEvent[] events= hasDimensionChanges ? dimEvent.getChildren() : null;
- boolean astLevelGTE8 = node.getAST().apiLevel() >= AST.JLS8;
ArrayType currentLevel = astLevelGTE8 ? null : (ArrayType) replacingType.getElementType().getParent();
int replacingTypeDimensions = replacingType.getDimensions();
int i=0, dimSize= (events == null) ? 0 : events.length;
Type elementType= arrayType.getElementType();
int offset= elementType.getStartPosition() + elementType.getLength();
+ editGroup = null;
while(currentLevel != null || astLevelGTE8) {
if (i < dimSize) {
- if (astLevelGTE8) rewriteAnnotationsOnDimension(replacingType, i, offset);
- offset= getScanner().getTokenEndOffset(TerminalTokens.TokenNameLBRACKET, offset);
+ if (astLevelGTE8)
+ rewriteAnnotationsOnDimension(arrayType, replacingType, i, offset, typeReplaced, editGroup);
+ offset= getScanner().getTokenEndOffset(TerminalTokens.TokenNameLBRACKET, offset);
if (hasDimensionChanges) {
RewriteEvent event= events[i];
int changeKind= event.getChangeKind();
@@ -2123,7 +2184,8 @@ public final class ASTRewriteAnalyzer extends ASTVisitor {
offset= retrieveRightBracketEndPosition(offset, 1, true);
}
} else if (i < nOldBrackets) {
- if (astLevelGTE8) rewriteAnnotationsOnDimension(replacingType, i, offset);
+ if (astLevelGTE8)
+ rewriteAnnotationsOnDimension(arrayType, replacingType, i, offset, typeReplaced, editGroup);
offset= retrieveRightBracketEndPosition(offset, 1, false);
} else {
insertAnnotationsOnDimension(replacingType, i, offset, editGroup, astLevelGTE8);
@@ -2162,18 +2224,39 @@ public final class ASTRewriteAnalyzer extends ASTVisitor {
List annotations = dim.annotations();
if (annotations != null) {
int size = annotations.size();
- for (int j = 0; j < size; j++) {
- Annotation annotation = (Annotation) annotations.get(j);
- doTextInsert(pos, annotation.toString() + " ", editGroup); //$NON-NLS-1$
+ if (size > 0) {
+ doTextInsert(pos, " ", editGroup); //$NON-NLS-1$
+ for (int j = 0; j < size; j++) {
+ Annotation annotation = (Annotation) annotations.get(j);
+ doTextInsert(pos, annotation.toString() + " ", editGroup); //$NON-NLS-1$
+ }
}
-
}
}
}
- private void rewriteAnnotationsOnDimension(ArrayType replacingType, int index, int pos) {
- Dimension dim = (Dimension) replacingType.dimensions().get(index);
- rewriteTypeAnnotations(dim, Dimension.ANNOTATIONS_PROPERTY, pos);
+ private void rewriteAnnotationsOnDimension(ArrayType oldArrayType, ArrayType replacingType, int index, int pos, boolean typeReplaced, TextEditGroup editGroup) throws CoreException {
+ if (typeReplaced) {
+ List dimensions = oldArrayType.dimensions();
+ Dimension oldDim = index < dimensions.size() ? (Dimension) dimensions.get(index) : null;
+ if (oldDim != null) {
+ List oldAnnotations = oldDim.annotations();
+ int size = oldAnnotations.size();
+ if (size > 0) {
+ ASTNode prev = getPreviousNode(oldDim);
+ Annotation annotation = (Annotation) oldAnnotations.get(0);
+ int start = prev != null ? prev.getStartPosition() + prev.getLength() : annotation.getStartPosition();
+ annotation = (Annotation) oldAnnotations.get(size - 1);
+ int end = annotation.getStartPosition() + annotation.getLength();
+ end = getScanner().getTokenEndOffset(TerminalTokens.TokenNameLBRACKET, end) - 1;
+ doTextRemove(start, end - start, editGroup);
+ }
+ }
+ insertAnnotationsOnDimension(replacingType, index, pos, editGroup, true);
+ } else {
+ Dimension dim = (Dimension) replacingType.dimensions().get(index);
+ rewriteNodeList(dim, Dimension.ANNOTATIONS_PROPERTY, pos, String.valueOf(' '), String.valueOf(' '), String.valueOf(' '));
+ }
}
/**
@@ -2241,7 +2324,9 @@ public final class ASTRewriteAnalyzer extends ASTVisitor {
return false;
}
-
+ private int rewriteArrayTypeDimensions(ArrayType node, int pos) {
+ return rewriteNodeList(node, ArrayType.DIMENSIONS_PROPERTY, pos, Util.EMPTY_STRING, ""); //$NON-NLS-1$
+ }
/* (non-Javadoc)
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(ArrayType)
@@ -2254,7 +2339,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor {
rewriteRequiredNode(node, INTERNAL_ARRAY_COMPONENT_TYPE_PROPERTY);
} else {
int pos = rewriteRequiredNode(node, ArrayType.ELEMENT_TYPE_PROPERTY);
- rewriteNodeList(node, ArrayType.DIMENSIONS_PROPERTY, pos, Util.EMPTY_STRING, " "); //$NON-NLS-1$
+ rewriteArrayTypeDimensions(node, pos);
}
return false;
}
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java
index 74f0b23c35..09fda332c7 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java
@@ -305,7 +305,7 @@ public class ASTRewriteFlattener extends ASTVisitor {
this.result.append("[]"); //$NON-NLS-1$
} else {
getChildNode(node, ArrayType.ELEMENT_TYPE_PROPERTY).accept(this);
- visitList(node, ArrayType.DIMENSIONS_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
+ visitList(node, ArrayType.DIMENSIONS_PROPERTY, Util.EMPTY_STRING, Util.EMPTY_STRING, Util.EMPTY_STRING);
}
return false;
}

Back to the top