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 (-6 / +6 lines)
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 (-3 / +50 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 6120-6126 Link Here
6120
		buf.append("import java.lang.annotation.ElementType;\n");
6120
		buf.append("import java.lang.annotation.ElementType;\n");
6121
		buf.append("public class E {\n");
6121
		buf.append("public class E {\n");
6122
		buf.append("    public void foo() {\n");
6122
		buf.append("    public void foo() {\n");
6123
		buf.append("    	int [] i [][] = new int @Annot1 @Annot2  [2]  [size(new int[][]{})] [];\n");
6123
		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");
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");
6125
		buf.append("    }\n");
6125
		buf.append("    }\n");
6126
		buf.append("    public int size(Object obj) { return 2; }\n");
6126
		buf.append("    public int size(Object obj) { return 2; }\n");
Lines 6155-6160 Link Here
6155
		edit.apply(doc);
6155
		edit.apply(doc);
6156
		assertTrue("Incorrect Formatting", doc.get().equals(formattedString));
6156
		assertTrue("Incorrect Formatting", doc.get().equals(formattedString));
6157
	}
6157
	}
6158
	public void testBug419723a_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 E {\n");
6164
		buf.append("    public void foo() {\n");
6165
		buf.append("    	int i [][];\n");
6166
		buf.append("    }\n");
6167
		buf.append("}\n");
6168
		ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
6169
6170
		CompilationUnit astRoot= createAST(cu);
6171
		AST ast= astRoot.getAST();
6172
		ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
6173
6174
		// Get while statement block
6175
		TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(0);
6176
		MethodDeclaration methodDecl= typeDecl.getMethods()[0];
6177
		Block block= methodDecl.getBody();
6178
		List statements= block.statements();
6179
6180
		VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(0);
6181
		List fragments = statement.fragments();
6182
		VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
6183
6184
		{
6185
			// Add new dimension with and without annotations
6186
6187
			ListRewrite listRewrite= rewrite.getListRewrite(fragment, VariableDeclarationFragment.EXTRA_DIMENSIONS2_PROPERTY);
6188
			Dimension dim = ast.newDimension();
6189
			listRewrite.insertFirst(dim, null);
6190
			
6191
		}
6192
		// Get new code
6193
		String preview= evaluateRewrite(cu, rewrite);
6194
6195
		buf= new StringBuffer();
6196
		buf.append("package test1;\n");
6197
		buf.append("import java.lang.annotation.ElementType;\n");
6198
		buf.append("public class E {\n");
6199
		buf.append("    public void foo() {\n");
6200
		buf.append("    	int i [][][];\n");
6201
		buf.append("    }\n");
6202
		buf.append("}\n");
6203
		assertEqualString(preview, buf.toString());
6204
	}
6158
6205
6159
}
6206
}
6160
6207
(-)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 (-2 / +2 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 2254-2260 Link Here
2254
			rewriteRequiredNode(node, INTERNAL_ARRAY_COMPONENT_TYPE_PROPERTY);
2254
			rewriteRequiredNode(node, INTERNAL_ARRAY_COMPONENT_TYPE_PROPERTY);
2255
		} else {
2255
		} else {
2256
			int pos = rewriteRequiredNode(node, ArrayType.ELEMENT_TYPE_PROPERTY);
2256
			int pos = rewriteRequiredNode(node, ArrayType.ELEMENT_TYPE_PROPERTY);
2257
			rewriteNodeList(node, ArrayType.DIMENSIONS_PROPERTY, pos, Util.EMPTY_STRING, " "); //$NON-NLS-1$
2257
			rewriteNodeList(node, ArrayType.DIMENSIONS_PROPERTY, pos, Util.EMPTY_STRING, ""); //$NON-NLS-1$
2258
		}
2258
		}
2259
		return false;
2259
		return false;
2260
	}
2260
	}
(-)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