Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 417923 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java (-3 / +3 lines)
Lines 1657-1670 Link Here
1657
		Expression expression = fragment.getInitializer();
1657
		Expression expression = fragment.getInitializer();
1658
		assertTrue(expression instanceof LambdaExpression);
1658
		assertTrue(expression instanceof LambdaExpression);
1659
		LambdaExpression lambdaExpression = (LambdaExpression)expression;
1659
		LambdaExpression lambdaExpression = (LambdaExpression)expression;
1660
		assertEquals("(int [] ia) -> {\n  return ia.clone();\n}\n", lambdaExpression.toString());
1660
		assertEquals("(int[] ia) -> {\n  return ia.clone();\n}\n", lambdaExpression.toString());
1661
		IMethodBinding binding = lambdaExpression.resolveMethodBinding();
1661
		IMethodBinding binding = lambdaExpression.resolveMethodBinding();
1662
		assertEquals("private static java.lang.Object lambda$0(int[]) ", binding.toString());
1662
		assertEquals("private static java.lang.Object lambda$0(int[]) ", binding.toString());
1663
		assertTrue(lambdaExpression.parameters().size() == 1);
1663
		assertTrue(lambdaExpression.parameters().size() == 1);
1664
		VariableDeclaration variableDeclaration = (VariableDeclaration) lambdaExpression.parameters().get(0);
1664
		VariableDeclaration variableDeclaration = (VariableDeclaration) lambdaExpression.parameters().get(0);
1665
		assertTrue(variableDeclaration instanceof SingleVariableDeclaration);
1665
		assertTrue(variableDeclaration instanceof SingleVariableDeclaration);
1666
		SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration)variableDeclaration;
1666
		SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration)variableDeclaration;
1667
		assertEquals("int [] ia", singleVariableDeclaration.toString());		
1667
		assertEquals("int[] ia", singleVariableDeclaration.toString());
1668
	}
1668
	}
1669
1669
1670
	/**
1670
	/**
Lines 3342-3348 Link Here
3342
		assertEquals("Incorrect no of fragments", 1, fragments.size());
3342
		assertEquals("Incorrect no of fragments", 1, fragments.size());
3343
		VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
3343
		VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
3344
		assertEquals("Unexpected type", fragment.resolveBinding().getType().toString(), "String @Marker{ value = (String)\"Extended\"} [] @Marker{ value = (String)\"i0\"} @Marker2 [] [] @Marker{ value = (String)\"i1\"} []");
3344
		assertEquals("Unexpected type", fragment.resolveBinding().getType().toString(), "String @Marker{ value = (String)\"Extended\"} [] @Marker{ value = (String)\"i0\"} @Marker2 [] [] @Marker{ value = (String)\"i1\"} []");
3345
		assertEquals("Unexpected type", field.getType().toString(), "String @Marker(\"i0\") @Marker2 [] [] @Marker(\"i1\") []");
3345
		assertEquals("Unexpected type", "String @Marker(\"i0\") @Marker2 [][] @Marker(\"i1\") []", field.getType().toString());
3346
	}
3346
	}
3347
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=417669
3347
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=417669
3348
	public void testBug417669() throws JavaModelException {
3348
	public void testBug417669() throws JavaModelException {
(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/TypeAnnotationsConverterTest.java (-8 / +8 lines)
Lines 162-168 Link Here
162
				"class Z<Q> {\n" + 
162
				"class Z<Q> {\n" + 
163
				"    }\n" + 
163
				"    }\n" + 
164
				"  }\n" + 
164
				"  }\n" + 
165
				"  Object o=(@Marker X<@Marker String>.@Marker Y<@Marker Integer>.@Marker Z<@Marker Object> @Marker [] [] @Marker [] [])null;\n" + 
165
				"  Object o=(@Marker X<@Marker String>.@Marker Y<@Marker Integer>.@Marker Z<@Marker Object> @Marker [][] @Marker [][])null;\n" + 
166
				"  @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}\n" + 
166
				"  @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}\n" + 
167
				"}\n";
167
				"}\n";
168
		assertASTNodeEquals(expectedOutput, node);
168
		assertASTNodeEquals(expectedOutput, node);
Lines 191-197 Link Here
191
				"class Z<Q> {\n" + 
191
				"class Z<Q> {\n" + 
192
				"    }\n" + 
192
				"    }\n" + 
193
				"  }\n" + 
193
				"  }\n" + 
194
				"  Object o=(@Marker X<@Marker String>.@Marker Y<@Marker Integer>.@Marker Z<@Marker Object> [] @Marker [] [] @Marker [])null;\n" + 
194
				"  Object o=(@Marker X<@Marker String>.@Marker Y<@Marker Integer>.@Marker Z<@Marker Object>[] @Marker [][] @Marker [])null;\n" + 
195
				"  @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}\n" + 
195
				"  @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}\n" + 
196
				"}\n";
196
				"}\n";
197
		assertASTNodeEquals(expectedOutput, node);
197
		assertASTNodeEquals(expectedOutput, node);
Lines 204-210 Link Here
204
			"        class Z<Q> {\n" +
204
			"        class Z<Q> {\n" +
205
		    "        }\n" +
205
		    "        }\n" +
206
			"    }\n" +
206
			"    }\n" +
207
			"    int [] [] [] [] o = (@One int [] @Two [] [] @Three []) null;\n" +
207
			"    int[][][][] o = (@One int[] @Two [][] @Three []) null;\n" +
208
			
208
			
209
			"    @java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
209
			"    @java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
210
			"    @interface Marker {\n" +
210
			"    @interface Marker {\n" +
Lines 220-226 Link Here
220
				"class Z<Q> {\n" + 
220
				"class Z<Q> {\n" + 
221
				"    }\n" + 
221
				"    }\n" + 
222
				"  }\n" + 
222
				"  }\n" + 
223
				"  int [] [] [] [] o=(@One int [] @Two [] [] @Three [])null;\n" + 
223
				"  int[][][][] o=(@One int[] @Two [][] @Three [])null;\n" + 
224
				"  @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}\n" + 
224
				"  @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}\n" + 
225
				"}\n";
225
				"}\n";
226
		assertASTNodeEquals(expectedOutput, node);
226
		assertASTNodeEquals(expectedOutput, node);
Lines 233-239 Link Here
233
			"        class Z<Q> {\n" +
233
			"        class Z<Q> {\n" +
234
		    "        }\n" +
234
		    "        }\n" +
235
			"    }\n" +
235
			"    }\n" +
236
			"    String [] [] [] [] o = (@One String [] @Two [] [] @Three []) null;\n" +
236
			"    String [][][][] o = (@One String[]@Two [][]@Three []) null;\n" +
237
			
237
			
238
			"    @java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
238
			"    @java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
239
			"    @interface Marker {\n" +
239
			"    @interface Marker {\n" +
Lines 249-255 Link Here
249
				"class Z<Q> {\n" + 
249
				"class Z<Q> {\n" + 
250
				"    }\n" + 
250
				"    }\n" + 
251
				"  }\n" + 
251
				"  }\n" + 
252
				"  String [] [] [] [] o=(@One String [] @Two [] [] @Three [])null;\n" + 
252
				"  String[][][][] o=(@One String[] @Two [][] @Three [])null;\n" + 
253
				"  @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}\n" + 
253
				"  @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}\n" + 
254
				"}\n";
254
				"}\n";
255
		assertASTNodeEquals(expectedOutput, node);
255
		assertASTNodeEquals(expectedOutput, node);
Lines 262-268 Link Here
262
			"        class Z<Q> {\n" +
262
			"        class Z<Q> {\n" +
263
		    "        }\n" +
263
		    "        }\n" +
264
			"    }\n" +
264
			"    }\n" +
265
			"    Object o = (@One X<String> [] @Two [] [] @Three []) null;\n" +
265
			"    Object o = (@One X<String> [] @Two [][]@Three []) null;\n" +
266
			
266
			
267
			"    @java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
267
			"    @java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
268
			"    @interface Marker {\n" +
268
			"    @interface Marker {\n" +
Lines 278-284 Link Here
278
				"class Z<Q> {\n" + 
278
				"class Z<Q> {\n" + 
279
				"    }\n" + 
279
				"    }\n" + 
280
				"  }\n" + 
280
				"  }\n" + 
281
				"  Object o=(@One X<String> [] @Two [] [] @Three [])null;\n" + 
281
				"  Object o=(@One X<String>[] @Two [][] @Three [])null;\n" + 
282
				"  @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}\n" + 
282
				"  @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}\n" + 
283
				"}\n";
283
				"}\n";
284
		assertASTNodeEquals(expectedOutput, node);
284
		assertASTNodeEquals(expectedOutput, node);
(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingMethodDeclTest.java (-3 / +3 lines)
Lines 3248-3256 Link Here
3248
		buf.append("package test1;\n");
3248
		buf.append("package test1;\n");
3249
		buf.append("import java.lang.annotation.ElementType;\n");
3249
		buf.append("import java.lang.annotation.ElementType;\n");
3250
		buf.append("public abstract class E {\n");
3250
		buf.append("public abstract class E {\n");
3251
		buf.append("    public Object foo1()[] @Annot1 [] @Annot2 [] { return null; }\n");
3251
		buf.append("    public Object foo1()[]@Annot1 []@Annot2 [] { return null; }\n");
3252
		buf.append("    public Object foo2()[] @Annot1 [] throws ArrayStoreException { return null; }\n");
3252
		buf.append("    public Object foo2()[]@Annot1 [] throws ArrayStoreException { return null; }\n");
3253
		buf.append("    public Object foo3() @Annot1 [] @Annot1 @Annot2 [] @Annot2 [] { return null; }\n");
3253
		buf.append("    public Object foo3() @Annot1 [] @Annot1 @Annot2 []@Annot2 [] { return null; }\n");
3254
		buf.append("    public Object foo4()@Annot2 @Annot1 [] @Annot2 @Annot1 [] throws IllegalArgumentException { return null; }\n");
3254
		buf.append("    public Object foo4()@Annot2 @Annot1 [] @Annot2 @Annot1 [] throws IllegalArgumentException { return null; }\n");
3255
		buf.append("    public Object foo5()  []   @Annot2 @Annot1 [] { return null; }\n");
3255
		buf.append("    public Object foo5()  []   @Annot2 @Annot1 [] { return null; }\n");
3256
		buf.append("    public Object foo6(int i)   []  [] throws IllegalArgumentException { return null; }\n");
3256
		buf.append("    public Object foo6(int i)   []  [] throws IllegalArgumentException { return null; }\n");
(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java (-5 / +732 lines)
Lines 6039-6045 Link Here
6039
		buf.append("import java.lang.annotation.ElementType;\n");
6039
		buf.append("import java.lang.annotation.ElementType;\n");
6040
		buf.append("public class E {\n");
6040
		buf.append("public class E {\n");
6041
		buf.append("    public void foo() {\n");
6041
		buf.append("    public void foo() {\n");
6042
		buf.append("    	int [] i [] @Annot1 @Annot2 [] @Annot1 @Annot3 [] = new int @Annot1 @Annot2  [2] @Annot2 @Annot3 [size()] @Annot2 @Annot1 [][]@Annot3 @Annot2 @Annot1 [];\n");
6042
		buf.append("    	int [] i []@Annot1 @Annot2 [] @Annot1 @Annot3 [] = new int @Annot1 @Annot2 [2] @Annot2 @Annot3 [size()] @Annot2 @Annot1 [][] @Annot3 @Annot2 @Annot1 [];\n");
6043
		buf.append("    	int [] j [][] = new int @Annot2 [2] @Annot2 [] @Annot1 [], k [][] = new int [2] [10] [size()];\n");
6043
		buf.append("    	int [] j [][] = new int @Annot2 [2] @Annot2 [] @Annot1 [], k [][] = new int [2] [10] [size()];\n");
6044
		buf.append("    }\n");
6044
		buf.append("    }\n");
6045
		buf.append("    public int size() { return 2; }\n");
6045
		buf.append("    public int size() { return 2; }\n");
Lines 6059-6065 Link Here
6059
		buf.append("import java.lang.annotation.ElementType;\n");
6059
		buf.append("import java.lang.annotation.ElementType;\n");
6060
		buf.append("public class E {\n");
6060
		buf.append("public class E {\n");
6061
		buf.append("    public void foo() {\n");
6061
		buf.append("    public void foo() {\n");
6062
		buf.append("    	int [] i [][] = new int @Annot1 @Annot2  [2] @Annot2 @Annot3 [size(new int[][]{})] [];\n");
6062
		buf.append("    	int [] i [][] = new int @Annot1 @Annot2  [2]@Annot2 @Annot3[size(new int[][]{})] [];\n");
6063
		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");
6063
		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");
6064
		buf.append("    }\n");
6064
		buf.append("    }\n");
6065
		buf.append("    public int size(Object obj) { return 2; }\n");
6065
		buf.append("    public int size(Object obj) { return 2; }\n");
Lines 6094-6100 Link Here
6094
			ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
6094
			ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
6095
			listRewrite.remove((ASTNode)dim.annotations().get(0), null);
6095
			listRewrite.remove((ASTNode)dim.annotations().get(0), null);
6096
			listRewrite.remove((ASTNode)dim.annotations().get(1), null);
6096
			listRewrite.remove((ASTNode)dim.annotations().get(1), null);
6097
			rewrite.set(creation, ArrayCreation.TYPE_PROPERTY, arrayType, null);
6098
		}
6097
		}
6099
		{
6098
		{
6100
			statement = (VariableDeclarationStatement) statements.get(1);
6099
			statement = (VariableDeclarationStatement) statements.get(1);
Lines 6120-6126 Link Here
6120
		buf.append("import java.lang.annotation.ElementType;\n");
6119
		buf.append("import java.lang.annotation.ElementType;\n");
6121
		buf.append("public class E {\n");
6120
		buf.append("public class E {\n");
6122
		buf.append("    public void foo() {\n");
6121
		buf.append("    public void foo() {\n");
6123
		buf.append("    	int [] i [][] = new int @Annot1 @Annot2  [2]  [size(new int[][]{})] [];\n");
6122
		buf.append("    	int [] i [][] = new int @Annot1 @Annot2  [2][size(new int[][]{})] [];\n");
6124
		buf.append("    	int [] j [][] = new int @Annot1 @Annot2 [2] @Annot2 @Annot3 [size(new int[]{})], k [][] = new int @Annot1 @Annot2 [2] @Annot2 @Annot3 [10];\n");
6123
		buf.append("    	int [] j [][] = new int @Annot1 @Annot2 [2] @Annot2 @Annot3 [size(new int[]{})], k [][] = new int @Annot1 @Annot2 [2] @Annot2 @Annot3 [10];\n");
6125
		buf.append("    }\n");
6124
		buf.append("    }\n");
6126
		buf.append("    public int size(Object obj) { return 2; }\n");
6125
		buf.append("    public int size(Object obj) { return 2; }\n");
Lines 6156-6162 Link Here
6156
		assertTrue("Incorrect Formatting", doc.get().equals(formattedString));
6155
		assertTrue("Incorrect Formatting", doc.get().equals(formattedString));
6157
	}
6156
	}
6158
6157
6159
}
6158
	public void testBug417923a_since_8() throws Exception {
6159
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
6160
		StringBuffer buf= new StringBuffer();
6161
		buf.append("package test1;\n");
6162
		buf.append("import java.lang.annotation.ElementType;\n");
6163
		buf.append("public class X {\n");
6164
		buf.append("    public void foo() {\n");
6165
		buf.append("    	int [] i [][] = new int @Annot1[][][];\n");
6166
		buf.append("    	int [] j [][] = new int @Annot1 [][][];\n");
6167
		buf.append("    	int [] k [][] = new int   @Annot1 [][][];\n");
6168
		buf.append("    	int [] l [][] = new int /* comment @ [] */@Annot1[][][];\n");
6169
		buf.append("    	int [] m [][] = new int /* comment @ [] */ @Annot1[][][];\n");
6170
		buf.append("    	int [] n [][] = new int /* comment @ [] */ @Annot1   [][][];\n");
6171
		buf.append("    	int [] o [][] = new int @Annot1/* comment @ [] */[][][];\n");
6172
		buf.append("    	int [] p [][] = new int @Annot1 /* comment @ [] */  [][][];\n");
6173
		buf.append("    	int [] q [][] = new int @Annot1   /* comment @ [] */[][][];\n");
6174
		buf.append("    }\n");
6175
		buf.append("}\n");
6176
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6177
		buf.append("@interface Annot1 {}\n");
6178
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
6160
6179
6180
		CompilationUnit astRoot= createAST(cu);
6181
		AST ast = astRoot.getAST();
6182
		ASTRewrite rewrite= ASTRewrite.create(ast);
6161
6183
6184
		TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
6185
		MethodDeclaration methodDecl= typeDecl.getMethods()[0];
6186
		Block block= methodDecl.getBody();
6187
		List statements= block.statements();
6162
6188
6189
		for (int i = 0; i < 9; ++i) {
6190
			VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
6191
			List fragments = statement.fragments();
6192
			VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
6193
			ArrayCreation creation = (ArrayCreation) fragment.getInitializer();
6194
			ArrayType arrayType = ast.newArrayType(ast.newPrimitiveType(PrimitiveType.INT), 3);
6195
			rewrite.set(creation, ArrayCreation.TYPE_PROPERTY, arrayType, null);
6196
		}
6197
6198
		String preview= evaluateRewrite(cu, rewrite);
6199
		buf= new StringBuffer();
6200
		buf.append("package test1;\n");
6201
		buf.append("import java.lang.annotation.ElementType;\n");
6202
		buf.append("public class X {\n");
6203
		buf.append("    public void foo() {\n");
6204
		buf.append("    	int [] i [][] = new int[][][];\n");
6205
		buf.append("    	int [] j [][] = new int[][][];\n");
6206
		buf.append("    	int [] k [][] = new int[][][];\n");
6207
		buf.append("    	int [] l [][] = new int[][][];\n");
6208
		buf.append("    	int [] m [][] = new int[][][];\n");
6209
		buf.append("    	int [] n [][] = new int[][][];\n");
6210
		buf.append("    	int [] o [][] = new int[][][];\n");
6211
		buf.append("    	int [] p [][] = new int[][][];\n");
6212
		buf.append("    	int [] q [][] = new int[][][];\n");
6213
		buf.append("    }\n");
6214
		buf.append("}\n");
6215
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6216
		buf.append("@interface Annot1 {}\n");
6217
		assertEqualString(preview, buf.toString());
6218
	}
6219
	public void testBug417923b_since_8() throws Exception {
6220
		IPackageFragment pack1 = this.sourceFolder.createPackageFragment("test1", false, null);
6221
		StringBuffer buf= new StringBuffer();
6222
		buf.append("package test1;\n");
6223
		buf.append("import java.lang.annotation.ElementType;\n");
6224
		buf.append("public class X {\n");
6225
		buf.append("    public void foo() {\n");
6226
		buf.append("    	int [] i [][] = new int[] @Annot1[][];\n");
6227
		buf.append("    	int [] j [][] = new int[] @Annot1 [][];\n");
6228
		buf.append("    	int [] k [][] = new int[]   @Annot1 [][];\n");
6229
		buf.append("    	int [] l [][] = new int[] /* comment @ [] */@Annot1[][];\n");
6230
		buf.append("    	int [] m [][] = new int[] /* comment @ [] */ @Annot1[][];\n");
6231
		buf.append("    	int [] n [][] = new int[] /* comment @ [] */ @Annot1   [][];\n");
6232
		buf.append("    	int [] o [][] = new int[] @Annot1/* comment @ [] */[][];\n");
6233
		buf.append("    	int [] p [][] = new int[] @Annot1 /* comment @ [] */  [][];\n");
6234
		buf.append("    	int [] q [][] = new int[] @Annot1   /* comment @ [] */[][];\n");
6235
		buf.append("    }\n");
6236
		buf.append("}\n");
6237
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6238
		buf.append("@interface Annot1 {}\n");
6239
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
6240
6241
		CompilationUnit astRoot= createAST(cu);
6242
		AST ast = astRoot.getAST();
6243
		ASTRewrite rewrite= ASTRewrite.create(ast);
6244
6245
		TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
6246
		MethodDeclaration methodDecl= typeDecl.getMethods()[0];
6247
		Block block= methodDecl.getBody();
6248
		List statements= block.statements();
6249
6250
		for (int i = 0; i < 9; ++i) {
6251
			VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
6252
			List fragments = statement.fragments();
6253
			VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
6254
			ArrayCreation creation = (ArrayCreation) fragment.getInitializer();
6255
			ArrayType arrayType = ast.newArrayType(ast.newPrimitiveType(PrimitiveType.INT), 3);
6256
			rewrite.set(creation, ArrayCreation.TYPE_PROPERTY, arrayType, null);
6257
		}
6258
6259
		String preview= evaluateRewrite(cu, rewrite);
6260
		buf= new StringBuffer();
6261
		buf.append("package test1;\n");
6262
		buf.append("import java.lang.annotation.ElementType;\n");
6263
		buf.append("public class X {\n");
6264
		buf.append("    public void foo() {\n");
6265
		buf.append("    	int [] i [][] = new int[][][];\n");
6266
		buf.append("    	int [] j [][] = new int[][][];\n");
6267
		buf.append("    	int [] k [][] = new int[][][];\n");
6268
		buf.append("    	int [] l [][] = new int[][][];\n");
6269
		buf.append("    	int [] m [][] = new int[][][];\n");
6270
		buf.append("    	int [] n [][] = new int[][][];\n");
6271
		buf.append("    	int [] o [][] = new int[][][];\n");
6272
		buf.append("    	int [] p [][] = new int[][][];\n");
6273
		buf.append("    	int [] q [][] = new int[][][];\n");
6274
		buf.append("    }\n");
6275
		buf.append("}\n");
6276
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6277
		buf.append("@interface Annot1 {}\n");
6278
		assertEqualString(preview, buf.toString());
6279
	}
6280
6281
	public void testBug417923c_since_8() throws Exception {
6282
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
6283
		StringBuffer buf= new StringBuffer();
6284
		buf.append("package test1;\n");
6285
		buf.append("import java.lang.annotation.ElementType;\n");
6286
		buf.append("public class X {\n");
6287
		buf.append("    public void foo() {\n");
6288
		buf.append("    	int [] i [][] = new int @Annot1[][][];\n");
6289
		buf.append("    	int [] j [][] = new int @Annot1 [][][];\n");
6290
		buf.append("    	int [] k [][] = new int   @Annot1  [][][];\n");
6291
		buf.append("    	int [] l [][] = new int /* comment @ [] */@Annot1[][][];\n");
6292
		buf.append("    	int [] m [][] = new int /* comment @ [] */ @Annot1[][][];\n");
6293
		buf.append("    	int [] n [][] = new int /* comment @ [] */ @Annot1   [][][];\n");
6294
		buf.append("    	int [] o [][] = new int @Annot1/* comment @ [] */[][][];\n");
6295
		buf.append("    	int [] p [][] = new int @Annot1 /* comment @ [] */  [][][];\n");
6296
		buf.append("    	int [] q [][] = new int @Annot1   /* comment @ [] */[][][];\n");
6297
		buf.append("    }\n");
6298
		buf.append("}\n");
6299
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6300
		buf.append("@interface Annot1 {}\n");
6301
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
6302
6303
		CompilationUnit astRoot= createAST(cu);
6304
		AST ast = astRoot.getAST();
6305
		ASTRewrite rewrite= ASTRewrite.create(ast);
6306
6307
		TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
6308
		MethodDeclaration methodDecl= typeDecl.getMethods()[0];
6309
		Block block= methodDecl.getBody();
6310
		List statements= block.statements();
6311
6312
		for (int i = 0; i < 9; ++i) {
6313
			VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
6314
			List fragments = statement.fragments();
6315
			VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
6316
			ArrayCreation creation = (ArrayCreation) fragment.getInitializer();
6317
			ArrayType arrayType = creation.getType();
6318
6319
			Dimension dim = (Dimension) arrayType.dimensions().get(0);
6320
			ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
6321
			listRewrite.remove((ASTNode)dim.annotations().get(0), null);
6322
		}
6323
6324
		String preview= evaluateRewrite(cu, rewrite);
6325
		buf= new StringBuffer();
6326
		buf.append("package test1;\n");
6327
		buf.append("import java.lang.annotation.ElementType;\n");
6328
		buf.append("public class X {\n");
6329
		buf.append("    public void foo() {\n");
6330
		buf.append("    	int [] i [][] = new int[][][];\n");
6331
		buf.append("    	int [] j [][] = new int[][][];\n");
6332
		buf.append("    	int [] k [][] = new int[][][];\n");
6333
		buf.append("    	int [] l [][] = new int [][][];\n");
6334
		buf.append("    	int [] m [][] = new int /* comment @ [] */[][][];\n");
6335
		buf.append("    	int [] n [][] = new int /* comment @ [] */[][][];\n");
6336
		buf.append("    	int [] o [][] = new int/* comment @ [] */[][][];\n");
6337
		buf.append("    	int [] p [][] = new int/* comment @ [] */  [][][];\n");
6338
		buf.append("    	int [] q [][] = new int/* comment @ [] */[][][];\n");
6339
		buf.append("    }\n");
6340
		buf.append("}\n");
6341
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6342
		buf.append("@interface Annot1 {}\n");
6343
		assertEqualString(preview, buf.toString());
6344
	}
6345
6346
	public void testBug417923d_since_8() throws Exception {
6347
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
6348
		StringBuffer buf= new StringBuffer();
6349
		buf.append("package test1;\n");
6350
		buf.append("import java.lang.annotation.ElementType;\n");
6351
		buf.append("public class X {\n");
6352
		buf.append("    public void foo() {\n");
6353
		buf.append("    	int [] i [][] = new int[] @Annot1[][];\n");
6354
		buf.append("    	int [] j [][] = new int[] @Annot1 [][];\n");
6355
		buf.append("    	int [] k [][] = new int[]   @Annot1  [][];\n");
6356
		buf.append("    	int [] l [][] = new int[] /* comment @ [] */@Annot1[][];\n");
6357
		buf.append("    	int [] m [][] = new int[] /* comment @ [] */ @Annot1[][];\n");
6358
		buf.append("    	int [] n [][] = new int[] /* comment @ [] */ @Annot1   [][];\n");
6359
		buf.append("    	int [] o [][] = new int[] @Annot1/* comment @ [] */[][];\n");
6360
		buf.append("    	int [] p [][] = new int[] @Annot1 /* comment @ [] */  [][];\n");
6361
		buf.append("    	int [] q [][] = new int[] @Annot1   /* comment @ [] */[][];\n");
6362
		buf.append("    }\n");
6363
		buf.append("}\n");
6364
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6365
		buf.append("@interface Annot1 {}\n");
6366
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
6367
6368
		CompilationUnit astRoot= createAST(cu);
6369
		AST ast = astRoot.getAST();
6370
		ASTRewrite rewrite= ASTRewrite.create(ast);
6371
6372
		TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
6373
		MethodDeclaration methodDecl= typeDecl.getMethods()[0];
6374
		Block block= methodDecl.getBody();
6375
		List statements= block.statements();
6376
6377
		for (int i = 0; i < 9; ++i) {
6378
			VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
6379
			List fragments = statement.fragments();
6380
			VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
6381
			ArrayCreation creation = (ArrayCreation) fragment.getInitializer();
6382
			ArrayType arrayType = creation.getType();
6383
6384
			Dimension dim = (Dimension) arrayType.dimensions().get(1);
6385
			ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
6386
			listRewrite.remove((ASTNode)dim.annotations().get(0), null);
6387
		}
6388
6389
		String preview= evaluateRewrite(cu, rewrite);
6390
		buf= new StringBuffer();
6391
		buf.append("package test1;\n");
6392
		buf.append("import java.lang.annotation.ElementType;\n");
6393
		buf.append("public class X {\n");
6394
		buf.append("    public void foo() {\n");
6395
		buf.append("    	int [] i [][] = new int[][][];\n");
6396
		buf.append("    	int [] j [][] = new int[][][];\n");
6397
		buf.append("    	int [] k [][] = new int[][][];\n");
6398
		buf.append("    	int [] l [][] = new int[] [][];\n");
6399
		buf.append("    	int [] m [][] = new int[] /* comment @ [] */[][];\n");
6400
		buf.append("    	int [] n [][] = new int[] /* comment @ [] */[][];\n");
6401
		buf.append("    	int [] o [][] = new int[]/* comment @ [] */[][];\n");
6402
		buf.append("    	int [] p [][] = new int[]/* comment @ [] */  [][];\n");
6403
		buf.append("    	int [] q [][] = new int[]/* comment @ [] */[][];\n");
6404
		buf.append("    }\n");
6405
		buf.append("}\n");
6406
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6407
		buf.append("@interface Annot1 {}\n");
6408
		assertEqualString(preview, buf.toString());
6409
	}
6410
6411
	public void testBug417923e_since_8() throws Exception {
6412
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
6413
		StringBuffer buf= new StringBuffer();
6414
		buf.append("package test1;\n");
6415
		buf.append("import java.lang.annotation.ElementType;\n");
6416
		buf.append("public class X {\n");
6417
		buf.append("    public void foo() {\n");
6418
		buf.append("    	int[][][] i = new int[][][];\n");
6419
		buf.append("    	int[][][] j = new int [][][];\n");
6420
		buf.append("    	int[][][] k = new int  [][][];\n");
6421
		buf.append("    	int[][][] l = new int/* comment */[][][];\n");
6422
		buf.append("    	int[][][] m = new int /* comment [] */ [][][];\n");
6423
		buf.append("    	int[][][] n = new int  /* comment [] */  [][][];\n");
6424
		buf.append("    }\n");
6425
		buf.append("}\n");
6426
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6427
		buf.append("@interface Annot1 {}\n");
6428
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
6429
6430
		CompilationUnit astRoot= createAST(cu);
6431
		AST ast = astRoot.getAST();
6432
		ASTRewrite rewrite= ASTRewrite.create(ast);
6433
6434
		TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
6435
		MethodDeclaration methodDecl= typeDecl.getMethods()[0];
6436
		Block block= methodDecl.getBody();
6437
		List statements= block.statements();
6438
6439
		for (int i = 0; i < 6; ++i) {
6440
			VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
6441
			List fragments = statement.fragments();
6442
			VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
6443
			ArrayCreation creation = (ArrayCreation) fragment.getInitializer();
6444
			ArrayType arrayType = creation.getType();
6445
6446
			Dimension dim = (Dimension) arrayType.dimensions().get(0);
6447
			ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
6448
			MarkerAnnotation markerAnnotation= ast.newMarkerAnnotation();
6449
			markerAnnotation.setTypeName(ast.newSimpleName("Annot1"));
6450
			listRewrite.insertAt(markerAnnotation, 0, null);
6451
		}
6452
		
6453
		String preview= evaluateRewrite(cu, rewrite);
6454
		buf= new StringBuffer();
6455
		buf.append("package test1;\n");
6456
		buf.append("import java.lang.annotation.ElementType;\n");
6457
		buf.append("public class X {\n");
6458
		buf.append("    public void foo() {\n");
6459
		buf.append("    	int[][][] i = new int @Annot1 [][][];\n");
6460
		buf.append("    	int[][][] j = new int @Annot1 [][][];\n");
6461
		buf.append("    	int[][][] k = new int  @Annot1 [][][];\n");
6462
		buf.append("    	int[][][] l = new int @Annot1 /* comment */[][][];\n");
6463
		buf.append("    	int[][][] m = new int @Annot1 /* comment [] */ [][][];\n");
6464
		buf.append("    	int[][][] n = new int  @Annot1 /* comment [] */  [][][];\n");
6465
		buf.append("    }\n");
6466
		buf.append("}\n");
6467
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6468
		buf.append("@interface Annot1 {}\n");
6469
		assertEqualString(preview, buf.toString());
6470
	}
6471
6472
	public void testBug417923f_since_8() throws Exception {
6473
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
6474
		StringBuffer buf= new StringBuffer();
6475
		buf.append("package test1;\n");
6476
		buf.append("import java.lang.annotation.ElementType;\n");
6477
		buf.append("public class X {\n");
6478
		buf.append("    public void foo() {\n");
6479
		buf.append("    	int[][][] i = new int[][][];\n");
6480
		buf.append("    	int[][][] j = new int[] [][];\n");
6481
		buf.append("    	int[][][] k = new int[]  [][];\n");
6482
		buf.append("    	int[][][] l = new int[]/* comment */[][];\n");
6483
		buf.append("    	int[][][] m = new int[] /* comment [] */ [][];\n");
6484
		buf.append("    	int[][][] n = new int[]  /* comment [] */  [][];\n");
6485
		buf.append("    }\n");
6486
		buf.append("}\n");
6487
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6488
		buf.append("@interface Annot1 {}\n");
6489
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
6490
6491
		CompilationUnit astRoot= createAST(cu);
6492
		AST ast = astRoot.getAST();
6493
		ASTRewrite rewrite= ASTRewrite.create(ast);
6494
6495
		TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
6496
		MethodDeclaration methodDecl= typeDecl.getMethods()[0];
6497
		Block block= methodDecl.getBody();
6498
		List statements= block.statements();
6499
6500
		for (int i = 0; i < 6; ++i) {
6501
			VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
6502
			List fragments = statement.fragments();
6503
			VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
6504
			ArrayCreation creation = (ArrayCreation) fragment.getInitializer();
6505
			ArrayType arrayType = creation.getType();
6506
6507
			Dimension dim = (Dimension) arrayType.dimensions().get(1);
6508
			ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
6509
			MarkerAnnotation markerAnnotation= ast.newMarkerAnnotation();
6510
			markerAnnotation.setTypeName(ast.newSimpleName("Annot1"));
6511
			listRewrite.insertAt(markerAnnotation, 0, null);
6512
		}
6513
		
6514
		String preview= evaluateRewrite(cu, rewrite);
6515
		buf= new StringBuffer();
6516
		buf.append("package test1;\n");
6517
		buf.append("import java.lang.annotation.ElementType;\n");
6518
		buf.append("public class X {\n");
6519
		buf.append("    public void foo() {\n");
6520
		buf.append("    	int[][][] i = new int[] @Annot1 [][];\n");
6521
		buf.append("    	int[][][] j = new int[] @Annot1 [][];\n");
6522
		buf.append("    	int[][][] k = new int[]  @Annot1 [][];\n");
6523
		buf.append("    	int[][][] l = new int[] @Annot1 /* comment */[][];\n");
6524
		buf.append("    	int[][][] m = new int[] @Annot1 /* comment [] */ [][];\n");
6525
		buf.append("    	int[][][] n = new int[]  @Annot1 /* comment [] */  [][];\n");
6526
		buf.append("    }\n");
6527
		buf.append("}\n");
6528
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6529
		buf.append("@interface Annot1 {}\n");
6530
		assertEqualString(preview, buf.toString());
6531
	}
6532
6533
	public void testBug417923g_since_8() throws Exception {
6534
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
6535
		StringBuffer buf= new StringBuffer();
6536
		buf.append("package test1;\n");
6537
		buf.append("import java.lang.annotation.ElementType;\n");
6538
		buf.append("public class X {\n");
6539
		buf.append("    public void foo() {\n");
6540
		buf.append("    	int[][][] i;\n");
6541
		buf.append("    	int [][][] j;\n");
6542
		buf.append("    	int  [][][] k;\n");
6543
		buf.append("    	int/* comment */[][][] l;\n");
6544
		buf.append("    	int /* comment [] */ [][][] m;\n");
6545
		buf.append("    	int  /* comment [] */  [][][] n;\n");
6546
		buf.append("    }\n");
6547
		buf.append("}\n");
6548
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6549
		buf.append("@interface Annot1 {}\n");
6550
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
6551
6552
		CompilationUnit astRoot= createAST(cu);
6553
		AST ast = astRoot.getAST();
6554
		ASTRewrite rewrite= ASTRewrite.create(ast);
6555
6556
		TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
6557
		MethodDeclaration methodDecl= typeDecl.getMethods()[0];
6558
		Block block= methodDecl.getBody();
6559
		List statements= block.statements();
6560
6561
		for (int i = 0; i < 6; ++i) {
6562
			VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
6563
			ArrayType arrayType = (ArrayType) statement.getType();
6564
			Dimension dim = (Dimension) arrayType.dimensions().get(0);
6565
			ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
6566
			MarkerAnnotation markerAnnotation= ast.newMarkerAnnotation();
6567
			markerAnnotation.setTypeName(ast.newSimpleName("Annot1"));
6568
			listRewrite.insertAt(markerAnnotation, 0, null);
6569
		}
6570
		String preview= evaluateRewrite(cu, rewrite);
6571
		buf= new StringBuffer();
6572
		buf.append("package test1;\n");
6573
		buf.append("import java.lang.annotation.ElementType;\n");
6574
		buf.append("public class X {\n");
6575
		buf.append("    public void foo() {\n");
6576
		buf.append("    	int @Annot1 [][][] i;\n");
6577
		buf.append("    	int @Annot1 [][][] j;\n");
6578
		buf.append("    	int  @Annot1 [][][] k;\n");
6579
		buf.append("    	int @Annot1 /* comment */[][][] l;\n");
6580
		buf.append("    	int @Annot1 /* comment [] */ [][][] m;\n");
6581
		buf.append("    	int  @Annot1 /* comment [] */  [][][] n;\n");
6582
		buf.append("    }\n");
6583
		buf.append("}\n");
6584
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6585
		buf.append("@interface Annot1 {}\n");
6586
		assertEqualString(preview, buf.toString());
6587
	}
6588
	public void testBug417923h_since_8() throws Exception {
6589
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
6590
		StringBuffer buf= new StringBuffer();
6591
		buf.append("package test1;\n");
6592
		buf.append("import java.lang.annotation.ElementType;\n");
6593
		buf.append("public class X {\n");
6594
		buf.append("    public void foo() {\n");
6595
		buf.append("    	int[][][] i;\n");
6596
		buf.append("    	int[] [][] j;\n");
6597
		buf.append("    	int[]  [][] k;\n");
6598
		buf.append("    	int[]/* comment */[][] l;\n");
6599
		buf.append("    	int[] /* comment [] */ [][] m;\n");
6600
		buf.append("    	int[]  /* comment [] */  [][] n;\n");
6601
		buf.append("    }\n");
6602
		buf.append("}\n");
6603
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6604
		buf.append("@interface Annot1 {}\n");
6605
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
6606
6607
		CompilationUnit astRoot= createAST(cu);
6608
		AST ast = astRoot.getAST();
6609
		ASTRewrite rewrite= ASTRewrite.create(ast);
6610
6611
		TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
6612
		MethodDeclaration methodDecl= typeDecl.getMethods()[0];
6613
		Block block= methodDecl.getBody();
6614
		List statements= block.statements();
6615
6616
		for (int i = 0; i < 6; ++i) {
6617
			VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
6618
			ArrayType arrayType = (ArrayType) statement.getType();
6619
			Dimension dim = (Dimension) arrayType.dimensions().get(1);
6620
			ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
6621
			MarkerAnnotation markerAnnotation= ast.newMarkerAnnotation();
6622
			markerAnnotation.setTypeName(ast.newSimpleName("Annot1"));
6623
			listRewrite.insertAt(markerAnnotation, 0, null);
6624
		}
6625
		String preview= evaluateRewrite(cu, rewrite);
6626
		buf= new StringBuffer();
6627
		buf.append("package test1;\n");
6628
		buf.append("import java.lang.annotation.ElementType;\n");
6629
		buf.append("public class X {\n");
6630
		buf.append("    public void foo() {\n");
6631
		buf.append("    	int[] @Annot1 [][] i;\n");
6632
		buf.append("    	int[] @Annot1 [][] j;\n");
6633
		buf.append("    	int[]  @Annot1 [][] k;\n");
6634
		buf.append("    	int[] @Annot1 /* comment */[][] l;\n");
6635
		buf.append("    	int[] @Annot1 /* comment [] */ [][] m;\n");
6636
		buf.append("    	int[]  @Annot1 /* comment [] */  [][] n;\n");
6637
		buf.append("    }\n");
6638
		buf.append("}\n");
6639
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6640
		buf.append("@interface Annot1 {}\n");
6641
		assertEqualString(preview, buf.toString());
6642
	}
6643
	
6644
	public void testBug417923i_since_8() throws Exception {
6645
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
6646
		StringBuffer buf= new StringBuffer();
6647
		buf.append("package test1;\n");
6648
		buf.append("import java.lang.annotation.ElementType;\n");
6649
		buf.append("public class X {\n");
6650
		buf.append("    public void foo() {\n");
6651
		buf.append("    	int @Annot1[][][] i;\n");
6652
		buf.append("    	int @Annot1 [][][] j;\n");
6653
		buf.append("    	int   @Annot1  [][][] k;\n");
6654
		buf.append("    	int/* comment @ [] */@Annot1[][][] l;\n");
6655
		buf.append("    	int /* comment @ [] */ @Annot1[][][] m;\n");
6656
		buf.append("    	int /* comment @ [] */ @Annot1   [][][] n;\n");
6657
		buf.append("    	int @Annot1/* comment @ [] */[][][] o;\n");
6658
		buf.append("    	int @Annot1 /* comment @ [] */  [][][] p;\n");
6659
		buf.append("    	int @Annot1   /* comment @ [] */[][][] q;\n");
6660
		buf.append("    }\n");
6661
		buf.append("}\n");
6662
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6663
		buf.append("@interface Annot1 {}\n");
6664
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
6665
6666
		CompilationUnit astRoot= createAST(cu);
6667
		AST ast = astRoot.getAST();
6668
		ASTRewrite rewrite= ASTRewrite.create(ast);
6669
6670
		TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
6671
		MethodDeclaration methodDecl= typeDecl.getMethods()[0];
6672
		Block block= methodDecl.getBody();
6673
		List statements= block.statements();
6674
6675
		for (int i = 0; i < 9; ++i) {
6676
			VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
6677
			ArrayType arrayType = (ArrayType) statement.getType();
6678
			Dimension dim = (Dimension) arrayType.dimensions().get(0);
6679
			ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
6680
			listRewrite.remove((ASTNode) dim.annotations().get(0), null);
6681
		}
6682
		String preview= evaluateRewrite(cu, rewrite);
6683
		buf= new StringBuffer();
6684
		buf.append("package test1;\n");
6685
		buf.append("import java.lang.annotation.ElementType;\n");
6686
		buf.append("public class X {\n");
6687
		buf.append("    public void foo() {\n");
6688
		buf.append("    	int[][][] i;\n");
6689
		buf.append("    	int[][][] j;\n");
6690
		buf.append("    	int[][][] k;\n");
6691
		buf.append("    	int[][][] l;\n");
6692
		buf.append("    	int /* comment @ [] */[][][] m;\n");
6693
		buf.append("    	int /* comment @ [] */[][][] n;\n");
6694
		buf.append("    	int/* comment @ [] */[][][] o;\n");
6695
		buf.append("    	int/* comment @ [] */  [][][] p;\n");
6696
		buf.append("    	int/* comment @ [] */[][][] q;\n");
6697
		buf.append("    }\n");
6698
		buf.append("}\n");
6699
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6700
		buf.append("@interface Annot1 {}\n");
6701
		assertEqualString(preview, buf.toString());
6702
	}
6703
	
6704
	public void testBug417923j_since_8() throws Exception {
6705
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
6706
		StringBuffer buf= new StringBuffer();
6707
		buf.append("package test1;\n");
6708
		buf.append("import java.lang.annotation.ElementType;\n");
6709
		buf.append("public class X {\n");
6710
		buf.append("    public void foo() {\n");
6711
		buf.append("    	int[] @Annot1[][] i;\n");
6712
		buf.append("    	int[] @Annot1 [][] j;\n");
6713
		buf.append("    	int[]   @Annot1  [][] k;\n");
6714
		buf.append("    	int[]/* comment @ [] */@Annot1[][] l;\n");
6715
		buf.append("    	int[] /* comment @ [] */ @Annot1[][] m;\n");
6716
		buf.append("    	int[] /* comment @ [] */ @Annot1   [][] n;\n");
6717
		buf.append("    	int[] @Annot1/* comment @ [] */[][] o;\n");
6718
		buf.append("    	int[] @Annot1 /* comment @ [] */  [][] p;\n");
6719
		buf.append("    	int[] @Annot1   /* comment @ [] */[][] q;\n");
6720
		buf.append("    }\n");
6721
		buf.append("}\n");
6722
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6723
		buf.append("@interface Annot1 {}\n");
6724
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
6725
6726
		CompilationUnit astRoot= createAST(cu);
6727
		AST ast = astRoot.getAST();
6728
		ASTRewrite rewrite= ASTRewrite.create(ast);
6729
6730
		TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
6731
		MethodDeclaration methodDecl= typeDecl.getMethods()[0];
6732
		Block block= methodDecl.getBody();
6733
		List statements= block.statements();
6734
6735
		for (int i = 0; i < 9; ++i) {
6736
			VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
6737
			ArrayType arrayType = (ArrayType) statement.getType();
6738
			Dimension dim = (Dimension) arrayType.dimensions().get(1);
6739
			ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
6740
			listRewrite.remove((ASTNode) dim.annotations().get(0), null);
6741
		}
6742
		String preview= evaluateRewrite(cu, rewrite);
6743
		buf= new StringBuffer();
6744
		buf.append("package test1;\n");
6745
		buf.append("import java.lang.annotation.ElementType;\n");
6746
		buf.append("public class X {\n");
6747
		buf.append("    public void foo() {\n");
6748
		buf.append("    	int[][][] i;\n");
6749
		buf.append("    	int[][][] j;\n");
6750
		buf.append("    	int[][][] k;\n");
6751
		buf.append("    	int[][][] l;\n");
6752
		buf.append("    	int[] /* comment @ [] */[][] m;\n");
6753
		buf.append("    	int[] /* comment @ [] */[][] n;\n");
6754
		buf.append("    	int[]/* comment @ [] */[][] o;\n");
6755
		buf.append("    	int[]/* comment @ [] */  [][] p;\n");
6756
		buf.append("    	int[]/* comment @ [] */[][] q;\n");
6757
		buf.append("    }\n");
6758
		buf.append("}\n");
6759
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6760
		buf.append("@interface Annot1 {}\n");
6761
		assertEqualString(preview, buf.toString());
6762
	}
6763
6764
	public void testBug417923k_since_8() throws Exception {
6765
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
6766
		StringBuffer buf= new StringBuffer();
6767
		buf.append("package test1;\n");
6768
		buf.append("import java.lang.annotation.ElementType;\n");
6769
		buf.append("public class X {\n");
6770
		buf.append("    public void foo() {\n");
6771
		buf.append("    	int [] i [][] = new int[] @Annot1 @Annot2[][];\n");
6772
		buf.append("    	int [] j [][] = new int[] @Annot1 @Annot2[][];\n");
6773
		buf.append("    	int [] k [][] = new int[]   @Annot1  @Annot2 [][];\n");
6774
		buf.append("    	int [] l [][] = new int[] /* comment @ [] */@Annot1 @Annot2[][];\n");
6775
		buf.append("    	int [] m [][] = new int[] /* comment @ [] */ @Annot1 @Annot2 [][];\n");
6776
		buf.append("    	int [] n [][] = new int[] /* comment @ [] */ @Annot1 @Annot2  [][];\n");
6777
		buf.append("    	int [] o [][] = new int[] @Annot1 @Annot2/* comment @ [] */[][];\n");
6778
		buf.append("    	int [] p [][] = new int[] @Annot1 @Annot2/* comment @ [] */  [][];\n");
6779
		buf.append("    	int [] q [][] = new int[] @Annot1   @Annot2/* comment @ [] */[][];\n");
6780
		buf.append("    }\n");
6781
		buf.append("}\n");
6782
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6783
		buf.append("@interface Annot1 {}\n");
6784
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
6785
6786
		CompilationUnit astRoot= createAST(cu);
6787
		AST ast = astRoot.getAST();
6788
		ASTRewrite rewrite= ASTRewrite.create(ast);
6789
6790
		TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
6791
		MethodDeclaration methodDecl= typeDecl.getMethods()[0];
6792
		Block block= methodDecl.getBody();
6793
		List statements= block.statements();
6794
6795
		for (int i = 0; i < 9; ++i) {
6796
			VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
6797
			List fragments = statement.fragments();
6798
			VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
6799
			ArrayCreation creation = (ArrayCreation) fragment.getInitializer();
6800
			ArrayType arrayType = creation.getType();
6801
6802
			Dimension dim = (Dimension) arrayType.dimensions().get(1);
6803
			ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
6804
			listRewrite.remove((ASTNode)dim.annotations().get(1), null);
6805
		}
6806
6807
		String preview= evaluateRewrite(cu, rewrite);
6808
		buf= new StringBuffer();
6809
		buf.append("package test1;\n");
6810
		buf.append("import java.lang.annotation.ElementType;\n");
6811
		buf.append("public class X {\n");
6812
		buf.append("    public void foo() {\n");
6813
		buf.append("    	int [] i [][] = new int[] @Annot1[][];\n");
6814
		buf.append("    	int [] j [][] = new int[] @Annot1[][];\n");
6815
		buf.append("    	int [] k [][] = new int[]   @Annot1 [][];\n");
6816
		buf.append("    	int [] l [][] = new int[] /* comment @ [] */@Annot1[][];\n");
6817
		buf.append("    	int [] m [][] = new int[] /* comment @ [] */ @Annot1 [][];\n");
6818
		buf.append("    	int [] n [][] = new int[] /* comment @ [] */ @Annot1  [][];\n");
6819
		buf.append("    	int [] o [][] = new int[] @Annot1/* comment @ [] */[][];\n");
6820
		buf.append("    	int [] p [][] = new int[] @Annot1/* comment @ [] */  [][];\n");
6821
		buf.append("    	int [] q [][] = new int[] @Annot1/* comment @ [] */[][];\n");
6822
		buf.append("    }\n");
6823
		buf.append("}\n");
6824
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6825
		buf.append("@interface Annot1 {}\n");
6826
		assertEqualString(preview, buf.toString());
6827
	}
6828
6829
	public void testBug417923l_since_8() throws Exception {
6830
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
6831
		StringBuffer buf= new StringBuffer();
6832
		buf.append("package test1;\n");
6833
		buf.append("import java.lang.annotation.ElementType;\n");
6834
		buf.append("public class X {\n");
6835
		buf.append("    public void foo() {\n");
6836
		buf.append("    	int[] @Annot1 @Annot2[][] i;\n");
6837
		buf.append("    	int[] @Annot1 @Annot2 [][] j;\n");
6838
		buf.append("    	int[]   @Annot1  @Annot2 [][] k;\n");
6839
		buf.append("    	int[]/* comment @ [] */@Annot1 @Annot2[][] l;\n");
6840
		buf.append("    	int[] /* comment @ [] */ @Annot1 @Annot2 [][] m;\n");
6841
		buf.append("    	int[] /* comment @ [] */ @Annot1   @Annot2 [][] n;\n");
6842
		buf.append("    	int[] @Annot1 @Annot2/* comment @ [] */[][] o;\n");
6843
		buf.append("    	int[] @Annot1 @Annot2/* comment @ [] */  [][] p;\n");
6844
		buf.append("    	int[] @Annot1   @Annot2/* comment @ [] */[][] q;\n");
6845
		buf.append("    }\n");
6846
		buf.append("}\n");
6847
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6848
		buf.append("@interface Annot1 {}\n");
6849
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
6850
6851
		CompilationUnit astRoot= createAST(cu);
6852
		AST ast = astRoot.getAST();
6853
		ASTRewrite rewrite= ASTRewrite.create(ast);
6854
6855
		TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
6856
		MethodDeclaration methodDecl= typeDecl.getMethods()[0];
6857
		Block block= methodDecl.getBody();
6858
		List statements= block.statements();
6859
6860
		for (int i = 0; i < 9; ++i) {
6861
			VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(i);
6862
			ArrayType arrayType = (ArrayType) statement.getType();
6863
			Dimension dim = (Dimension) arrayType.dimensions().get(1);
6864
			ListRewrite listRewrite= rewrite.getListRewrite(dim, Dimension.ANNOTATIONS_PROPERTY);
6865
			listRewrite.remove((ASTNode) dim.annotations().get(1), null);
6866
		}
6867
		String preview= evaluateRewrite(cu, rewrite);
6868
		buf= new StringBuffer();
6869
		buf.append("package test1;\n");
6870
		buf.append("import java.lang.annotation.ElementType;\n");
6871
		buf.append("public class X {\n");
6872
		buf.append("    public void foo() {\n");
6873
		buf.append("    	int[] @Annot1[][] i;\n");
6874
		buf.append("    	int[] @Annot1 [][] j;\n");
6875
		buf.append("    	int[]   @Annot1 [][] k;\n");
6876
		buf.append("    	int[]/* comment @ [] */@Annot1[][] l;\n");
6877
		buf.append("    	int[] /* comment @ [] */ @Annot1 [][] m;\n");
6878
		buf.append("    	int[] /* comment @ [] */ @Annot1 [][] n;\n");
6879
		buf.append("    	int[] @Annot1/* comment @ [] */[][] o;\n");
6880
		buf.append("    	int[] @Annot1/* comment @ [] */  [][] p;\n");
6881
		buf.append("    	int[] @Annot1/* comment @ [] */[][] q;\n");
6882
		buf.append("    }\n");
6883
		buf.append("}\n");
6884
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
6885
		buf.append("@interface Annot1 {}\n");
6886
		assertEqualString(preview, buf.toString());
6887
	}
6888
6889
}
(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java (-2 / +2 lines)
Lines 1738-1744 Link Here
1738
		buf.append("import java.lang.annotation.ElementType;\n");
1738
		buf.append("import java.lang.annotation.ElementType;\n");
1739
		buf.append("public class E {\n");
1739
		buf.append("public class E {\n");
1740
		buf.append("    public void foo() {\n");
1740
		buf.append("    public void foo() {\n");
1741
		buf.append("        int i, j, k = 0, x, y [] [] [], z @Annot1 [], zz @Annot2 @Annot2[] = {0, 1};\n");
1741
		buf.append("        int i, j, k = 0, x, y[][][], z @Annot1 [], zz @Annot2 @Annot2[] = {0, 1};\n");
1742
		buf.append("    }\n");
1742
		buf.append("    }\n");
1743
		buf.append("}\n");
1743
		buf.append("}\n");
1744
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
1744
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
Lines 1849-1855 Link Here
1849
		buf.append("import java.lang.annotation.ElementType;\n");
1849
		buf.append("import java.lang.annotation.ElementType;\n");
1850
		buf.append("public class E {\n");
1850
		buf.append("public class E {\n");
1851
		buf.append("    public void foo() {\n");
1851
		buf.append("    public void foo() {\n");
1852
		buf.append("        int a @Annot1 @Annot2 [], j = 1, k @Annot1 @Annot2 [], x @Annot1 @Annot2 [] = null, y @Annot1[] @Annot2[], zz @Annot2 @Annot2[] = {0, 1};\n");
1852
		buf.append("        int a @Annot1 @Annot2 [], j = 1, k @Annot1 @Annot2 [], x @Annot1 @Annot2 [] = null, y @Annot1 [] @Annot2 [], zz @Annot2 @Annot2[] = {0, 1};\n");
1853
		buf.append("    }\n");
1853
		buf.append("    }\n");
1854
		buf.append("}\n");
1854
		buf.append("}\n");
1855
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
1855
		buf.append("@java.lang.annotation.Target(value= {ElementType.TYPE_USE})\n");
(-)a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java (-2 / +4 lines)
Lines 620-627 Link Here
620
	}
620
	}
621
621
622
	public boolean visit(Dimension node) {
622
	public boolean visit(Dimension node) {
623
		this.buffer.append(" ");//$NON-NLS-1$
623
		List annotations = node.annotations();
624
		visitAnnotationsList(node.annotations());
624
		if (annotations.size() > 0)
625
			this.buffer.append(' ');
626
		visitAnnotationsList(annotations);
625
		this.buffer.append("[]"); //$NON-NLS-1$
627
		this.buffer.append("[]"); //$NON-NLS-1$
626
		return false;
628
		return false;
627
	}
629
	}
(-)a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java (-15 / +101 lines)
Lines 1266-1272 Link Here
1266
	}
1266
	}
1267
1267
1268
	protected int rewriteExtraDimensionsInfo(ASTNode node, int pos, ChildListPropertyDescriptor property) {
1268
	protected int rewriteExtraDimensionsInfo(ASTNode node, int pos, ChildListPropertyDescriptor property) {
1269
		return rewriteNodeList(node, property, pos, " ", " "); //$NON-NLS-1$ //$NON-NLS-2$
1269
		return rewriteNodeList(node, property, pos, " ", ""); //$NON-NLS-1$ //$NON-NLS-2$
1270
	}
1270
	}
1271
1271
1272
	private int rewriteExtraDimensions(ASTNode parent, StructuralPropertyDescriptor property, int pos) {
1272
	private int rewriteExtraDimensions(ASTNode parent, StructuralPropertyDescriptor property, int pos) {
Lines 1913-1923 Link Here
1913
		return offset;
1913
		return offset;
1914
	}
1914
	}
1915
1915
1916
	private ASTNode getPreviousNode(ASTNode node) {
1917
		ArrayType arrayType = (ArrayType) node.getParent();
1918
		ASTNode prev = arrayType.getElementType();
1919
		List l = (List) node.getParent().getStructuralProperty(node.getLocationInParent());
1920
		int size = l.size();
1921
		int i = 0;
1922
		for (; i < size; i++) {
1923
			ASTNode currNode = (ASTNode) l.get(i);
1924
			if (node.equals(currNode))
1925
				break;
1926
			prev = currNode;
1927
		}
1928
		return i < size ? prev : null;
1929
	}
1930
	
1931
	private int getPreviousTokenEndOffset(ASTNode node, int token) {
1932
		int offset = -1;
1933
		ASTNode prev = getPreviousNode(node);
1934
		if (prev != null) {
1935
			offset = prev.getStartPosition() + prev.getLength();
1936
			try {
1937
				offset = getScanner().getPreviousTokenEndOffset(token, offset);
1938
			} catch (CoreException e1) {
1939
				e1.printStackTrace();
1940
			}
1941
		}
1942
		return offset;
1943
	}
1944
	
1916
	public boolean visit(Dimension node) {
1945
	public boolean visit(Dimension node) {
1917
		if (!hasChildrenChanges(node)) {
1946
		if (!hasChildrenChanges(node)) {
1918
			return doVisitUnchangedChildren(node);
1947
			return doVisitUnchangedChildren(node);
1919
		}
1948
		}
1920
		rewriteNodeList(node, Dimension.ANNOTATIONS_PROPERTY, node.getStartPosition(), Util.EMPTY_STRING, " "); //$NON-NLS-1$
1949
		
1950
		boolean keywordSpace = true;
1951
		ASTNode parent = node.getParent();
1952
		if (parent.getNodeType() == ASTNode.ARRAY_TYPE) {
1953
			List oldAnnotations = (List) getOriginalValue(node, Dimension.ANNOTATIONS_PROPERTY);
1954
			List newAnnotations = (List) getNewValue(node, Dimension.ANNOTATIONS_PROPERTY);
1955
			int oldAnnotationSize = oldAnnotations.size();
1956
			int newAnnotationSize = newAnnotations.size();
1957
			if (oldAnnotationSize > 0 && newAnnotationSize == 0) { /* removed all annotations */
1958
				int delStart = getPreviousTokenEndOffset(node, TerminalTokens.TokenNameAT);
1959
				int delEnd = ((ASTNode) oldAnnotations.get(0)).getStartPosition();
1960
				if (delStart >= 0 && delEnd > delStart) {
1961
					doTextRemove(delStart, delEnd - delStart, null); /* remove spaces before the annotation */
1962
				}
1963
1964
				ASTNode currNode = (ASTNode) oldAnnotations.get(oldAnnotationSize - 1);
1965
				delStart = currNode.getStartPosition() + currNode.getLength();
1966
				try {
1967
					delEnd = getScanner().getNextStartOffset(delStart, false);
1968
					doTextRemove(delStart, delEnd - delStart, null); /* remove spaces after the annotation */
1969
				} catch (CoreException e) {
1970
					e.printStackTrace();
1971
				}
1972
			} else if (oldAnnotationSize == 0 && newAnnotationSize > 0) { /* inserting first annotation */
1973
				if (ScannerHelper.isWhitespace(this.content[node.getStartPosition() - 1])) {
1974
					keywordSpace = false; /* space exists already */
1975
				}
1976
			}
1977
		}
1978
		rewriteNodeList(node, Dimension.ANNOTATIONS_PROPERTY, node.getStartPosition(), keywordSpace ? String.valueOf(' ') : Util.EMPTY_STRING, String.valueOf(' '), String.valueOf(' '));
1921
		return false;
1979
		return false;
1922
	}
1980
	}
1923
1981
Lines 2058-2067 Link Here
2058
		ArrayType arrayType= (ArrayType) getOriginalValue(node, ArrayCreation.TYPE_PROPERTY);
2116
		ArrayType arrayType= (ArrayType) getOriginalValue(node, ArrayCreation.TYPE_PROPERTY);
2059
		ArrayType replacingType= arrayType;
2117
		ArrayType replacingType= arrayType;
2060
		int nOldBrackets= getDimensions(arrayType); // number of total brackets
2118
		int nOldBrackets= getDimensions(arrayType); // number of total brackets
2119
		boolean astLevelGTE8 = node.getAST().apiLevel() >= AST.JLS8;
2120
		boolean typeReplaced = false;
2061
2121
2062
		TextEditGroup editGroup= null;
2122
		TextEditGroup editGroup= null;
2063
		RewriteEvent typeEvent= getEvent(node, ArrayCreation.TYPE_PROPERTY);
2123
		RewriteEvent typeEvent= getEvent(node, ArrayCreation.TYPE_PROPERTY);
2064
		if (typeEvent != null && typeEvent.getChangeKind() == RewriteEvent.REPLACED) { // changed arraytype can have different dimension or type name
2124
		if (typeEvent != null && typeEvent.getChangeKind() == RewriteEvent.REPLACED) { // changed arraytype can have different dimension or type name
2125
			typeReplaced = true;
2065
			replacingType= (ArrayType) typeEvent.getNewValue();
2126
			replacingType= (ArrayType) typeEvent.getNewValue();
2066
			editGroup= getEditGroup(typeEvent);
2127
			editGroup= getEditGroup(typeEvent);
2067
			Type newType= replacingType.getElementType();
2128
			Type newType= replacingType.getElementType();
Lines 2080-2095 Link Here
2080
			RewriteEvent dimEvent= getEvent(node, ArrayCreation.DIMENSIONS_PROPERTY);
2141
			RewriteEvent dimEvent= getEvent(node, ArrayCreation.DIMENSIONS_PROPERTY);
2081
			boolean hasDimensionChanges= (dimEvent != null && dimEvent.getChangeKind() != RewriteEvent.UNCHANGED);
2142
			boolean hasDimensionChanges= (dimEvent != null && dimEvent.getChangeKind() != RewriteEvent.UNCHANGED);
2082
			RewriteEvent[] events= hasDimensionChanges ? dimEvent.getChildren() : null;
2143
			RewriteEvent[] events= hasDimensionChanges ? dimEvent.getChildren() : null;
2083
			boolean astLevelGTE8 = node.getAST().apiLevel() >= AST.JLS8;
2084
			ArrayType currentLevel = astLevelGTE8 ? null : (ArrayType) replacingType.getElementType().getParent();
2144
			ArrayType currentLevel = astLevelGTE8 ? null : (ArrayType) replacingType.getElementType().getParent();
2085
			int replacingTypeDimensions = replacingType.getDimensions();
2145
			int replacingTypeDimensions = replacingType.getDimensions();
2086
			int i=0, dimSize= (events == null) ? 0 : events.length;
2146
			int i=0, dimSize= (events == null) ? 0 : events.length;
2087
			Type elementType= arrayType.getElementType();
2147
			Type elementType= arrayType.getElementType();
2088
			int offset= elementType.getStartPosition() + elementType.getLength();
2148
			int offset= elementType.getStartPosition() + elementType.getLength();
2149
			editGroup = null;
2089
			while(currentLevel != null || astLevelGTE8) {
2150
			while(currentLevel != null || astLevelGTE8) {
2090
				if (i < dimSize) {
2151
				if (i < dimSize) {
2091
					if (astLevelGTE8) rewriteAnnotationsOnDimension(replacingType, i, offset);
2152
					if (astLevelGTE8)
2092
					 offset= getScanner().getTokenEndOffset(TerminalTokens.TokenNameLBRACKET, offset);
2153
						rewriteAnnotationsOnDimension(arrayType, replacingType, i, offset, typeReplaced, editGroup);
2154
					offset= getScanner().getTokenEndOffset(TerminalTokens.TokenNameLBRACKET, offset);
2093
					if (hasDimensionChanges) {
2155
					if (hasDimensionChanges) {
2094
						RewriteEvent event= events[i];
2156
						RewriteEvent event= events[i];
2095
						int changeKind= event.getChangeKind();
2157
						int changeKind= event.getChangeKind();
Lines 2123-2129 Link Here
2123
						offset= retrieveRightBracketEndPosition(offset, 1, true);
2185
						offset= retrieveRightBracketEndPosition(offset, 1, true);
2124
					}
2186
					}
2125
				} else if (i < nOldBrackets) {
2187
				} else if (i < nOldBrackets) {
2126
					if (astLevelGTE8) rewriteAnnotationsOnDimension(replacingType, i, offset);
2188
					if (astLevelGTE8)
2189
						rewriteAnnotationsOnDimension(arrayType, replacingType, i, offset, typeReplaced, editGroup);
2127
					offset= retrieveRightBracketEndPosition(offset, 1, false);
2190
					offset= retrieveRightBracketEndPosition(offset, 1, false);
2128
				} else {
2191
				} else {
2129
					insertAnnotationsOnDimension(replacingType, i, offset, editGroup, astLevelGTE8);
2192
					insertAnnotationsOnDimension(replacingType, i, offset, editGroup, astLevelGTE8);
Lines 2162-2179 Link Here
2162
			List annotations = dim.annotations();
2225
			List annotations = dim.annotations();
2163
			if (annotations != null) {
2226
			if (annotations != null) {
2164
				int size = annotations.size();
2227
				int size = annotations.size();
2165
				for (int j = 0; j < size; j++) {
2228
				if (size > 0) {
2166
					Annotation annotation = (Annotation) annotations.get(j);
2229
					doTextInsert(pos, " ", editGroup); //$NON-NLS-1$
2167
					doTextInsert(pos, annotation.toString() + " ", editGroup); //$NON-NLS-1$
2230
					for (int j = 0; j < size; j++) {
2231
						Annotation annotation = (Annotation) annotations.get(j);
2232
						doTextInsert(pos, annotation.toString() + " ", editGroup); //$NON-NLS-1$
2233
					}
2168
				}
2234
				}
2169
				
2170
			}
2235
			}
2171
		}
2236
		}
2172
	}
2237
	}
2173
2238
2174
	private void rewriteAnnotationsOnDimension(ArrayType replacingType, int index, int pos) {
2239
	private void rewriteAnnotationsOnDimension(ArrayType oldArrayType, ArrayType replacingType, int index, int pos, boolean typeReplaced, TextEditGroup editGroup) throws CoreException {
2175
		Dimension dim = (Dimension) replacingType.dimensions().get(index);
2240
		if (typeReplaced) {
2176
		rewriteTypeAnnotations(dim, Dimension.ANNOTATIONS_PROPERTY, pos);
2241
			List dimensions = oldArrayType.dimensions();
2242
			Dimension oldDim = index < dimensions.size() ? (Dimension) dimensions.get(index) : null;
2243
			if (oldDim != null) {
2244
				List oldAnnotations = oldDim.annotations();
2245
				int size = oldAnnotations.size();
2246
				if (size > 0) {
2247
					ASTNode prev = getPreviousNode(oldDim);
2248
					Annotation annotation = (Annotation) oldAnnotations.get(0);
2249
					int start = prev != null ? prev.getStartPosition() + prev.getLength() : annotation.getStartPosition();
2250
					annotation = (Annotation) oldAnnotations.get(size - 1);
2251
					int end = annotation.getStartPosition() + annotation.getLength();
2252
					end = getScanner().getTokenEndOffset(TerminalTokens.TokenNameLBRACKET, end) - 1;
2253
					doTextRemove(start, end - start, editGroup);
2254
				}
2255
			}
2256
			insertAnnotationsOnDimension(replacingType, index, pos, editGroup, true);
2257
		} else {
2258
			Dimension dim = (Dimension) replacingType.dimensions().get(index);
2259
			rewriteNodeList(dim, Dimension.ANNOTATIONS_PROPERTY, pos, String.valueOf(' '), String.valueOf(' '), String.valueOf(' '));
2260
		}
2177
	}
2261
	}
2178
2262
2179
	/**
2263
	/**
Lines 2241-2247 Link Here
2241
		return false;
2325
		return false;
2242
	}
2326
	}
2243
2327
2244
2328
	private int rewriteArrayTypeDimensions(ArrayType node, int pos) {
2329
		return rewriteNodeList(node, ArrayType.DIMENSIONS_PROPERTY, pos, Util.EMPTY_STRING, ""); //$NON-NLS-1$
2330
	}
2245
2331
2246
	/* (non-Javadoc)
2332
	/* (non-Javadoc)
2247
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(ArrayType)
2333
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(ArrayType)
Lines 2254-2260 Link Here
2254
			rewriteRequiredNode(node, INTERNAL_ARRAY_COMPONENT_TYPE_PROPERTY);
2340
			rewriteRequiredNode(node, INTERNAL_ARRAY_COMPONENT_TYPE_PROPERTY);
2255
		} else {
2341
		} else {
2256
			int pos = rewriteRequiredNode(node, ArrayType.ELEMENT_TYPE_PROPERTY);
2342
			int pos = rewriteRequiredNode(node, ArrayType.ELEMENT_TYPE_PROPERTY);
2257
			rewriteNodeList(node, ArrayType.DIMENSIONS_PROPERTY, pos, Util.EMPTY_STRING, " "); //$NON-NLS-1$
2343
			rewriteArrayTypeDimensions(node, pos);
2258
		}
2344
		}
2259
		return false;
2345
		return false;
2260
	}
2346
	}
(-)a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java (-1 / +1 lines)
Lines 305-311 Link Here
305
			this.result.append("[]"); //$NON-NLS-1$
305
			this.result.append("[]"); //$NON-NLS-1$
306
		} else {
306
		} else {
307
			getChildNode(node, ArrayType.ELEMENT_TYPE_PROPERTY).accept(this);
307
			getChildNode(node, ArrayType.ELEMENT_TYPE_PROPERTY).accept(this);
308
			visitList(node, ArrayType.DIMENSIONS_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
308
			visitList(node, ArrayType.DIMENSIONS_PROPERTY, Util.EMPTY_STRING, Util.EMPTY_STRING, Util.EMPTY_STRING);
309
		}
309
		}
310
		return false;
310
		return false;
311
	}
311
	}

Return to bug 417923