View | Details | Raw Unified | Return to bug 426967 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/PromoteTempToField/canPromote/A_testTypeAnnotations1_in.java (+15 lines)
Added Link Here
1
//9, 34, 9, 35
2
package p;
3
4
import java.lang.annotation.ElementType;
5
import java.lang.annotation.Target;
6
7
public class C1 {
8
	private void foo() {
9
		@TA1 int @TA2 [] @TA3 [] v= null;
10
	}
11
}
12
13
@Target(ElementType.TYPE_USE) @interface TA1 {}
14
@Target(ElementType.TYPE_USE) @interface TA2 {}
15
@Target(ElementType.TYPE_USE) @interface TA3 {}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/PromoteTempToField/canPromote/A_testTypeAnnotations1_out.java (+17 lines)
Added Link Here
1
//9, 34, 9, 35
2
package p;
3
4
import java.lang.annotation.ElementType;
5
import java.lang.annotation.Target;
6
7
public class C1 {
8
	private @TA1 int @TA2 [] @TA3 [] i;
9
10
	private void foo() {
11
		i= null;
12
	}
13
}
14
15
@Target(ElementType.TYPE_USE) @interface TA1 {}
16
@Target(ElementType.TYPE_USE) @interface TA2 {}
17
@Target(ElementType.TYPE_USE) @interface TA3 {}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/SefWorkSpace/SefTests/object_in/TestTypeUseAnnotations.java (+16 lines)
Added Link Here
1
package object_in;
2
3
import java.lang.annotation.ElementType;
4
import java.lang.annotation.Target;
5
6
public class C1 {
7
	@TA1 int @TA2 [] field @TA3 [];
8
	
9
	private void fun() {
10
		System.out.println(field=null);
11
	}
12
}
13
14
@Target(ElementType.TYPE_USE) @interface TA1 {}
15
@Target(ElementType.TYPE_USE) @interface TA2 {}
16
@Target(ElementType.TYPE_USE) @interface TA3 {}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/SefWorkSpace/SefTests/object_out/TestTypeUseAnnotations.java (+25 lines)
Added Link Here
1
package object_in;
2
3
import java.lang.annotation.ElementType;
4
import java.lang.annotation.Target;
5
6
public class C1 {
7
	private @TA1 int @TA2 [] field @TA3 [];
8
	
9
	private void fun() {
10
		System.out.println(setField(null));
11
	}
12
13
	@TA1 int @TA3 [] @TA2 [] getField() {
14
		return field;
15
	}
16
17
	@TA1 int @TA3 [] @TA2 [] setField(@TA1 int @TA2 [] field @TA3 []) {
18
		this.field = field;
19
		return field;
20
	}
21
}
22
23
@Target(ElementType.TYPE_USE) @interface TA1 {}
24
@Target(ElementType.TYPE_USE) @interface TA2 {}
25
@Target(ElementType.TYPE_USE) @interface TA3 {}
(-)a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/AllRefactoringTests.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 32-37 Link Here
32
		suite.addTest(InlineMethodTests.suite());
32
		suite.addTest(InlineMethodTests.suite());
33
		suite.addTest(ReplaceInvocationsTests.suite());
33
		suite.addTest(ReplaceInvocationsTests.suite());
34
		suite.addTest(SefTests.suite());
34
		suite.addTest(SefTests.suite());
35
		suite.addTest(SefTests18.suite());
35
		suite.addTest(InlineTempTests.suite());
36
		suite.addTest(InlineTempTests.suite());
36
		suite.addTest(InlineTempTests17.suite());
37
		suite.addTest(InlineTempTests17.suite());
37
		suite.addTest(ExtractTempTests.suite());
38
		suite.addTest(ExtractTempTests.suite());
Lines 39-44 Link Here
39
		suite.addTest(RenameTempTests.suite());
40
		suite.addTest(RenameTempTests.suite());
40
		suite.addTest(ExtractConstantTests.suite());
41
		suite.addTest(ExtractConstantTests.suite());
41
		suite.addTest(PromoteTempToFieldTests.suite());
42
		suite.addTest(PromoteTempToFieldTests.suite());
43
		suite.addTest(PromoteTempToFieldTests18.suite());
42
		suite.addTest(ConvertAnonymousToNestedTests.suite());
44
		suite.addTest(ConvertAnonymousToNestedTests.suite());
43
		suite.addTest(InlineConstantTests.suite());
45
		suite.addTest(InlineConstantTests.suite());
44
		suite.addTest(InlineConstantTests17.suite());
46
		suite.addTest(InlineConstantTests17.suite());
(-)a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/PromoteTempToFieldTests18.java (+7 lines)
Lines 45-48 Link Here
45
		failHelper(6, 13, 6, 14, "i", false, false, PromoteTempToFieldRefactoring.INITIALIZE_IN_METHOD, Modifier.PRIVATE, RefactoringStatus.FATAL);
45
		failHelper(6, 13, 6, 14, "i", false, false, PromoteTempToFieldRefactoring.INITIALIZE_IN_METHOD, Modifier.PRIVATE, RefactoringStatus.FATAL);
46
	}
46
	}
47
47
48
	public void testTypeAnnotations1() throws Exception {
49
		int accessModifier= Modifier.PRIVATE;
50
		int initializeIn= PromoteTempToFieldRefactoring.INITIALIZE_IN_METHOD;
51
		boolean declareFinal= false;
52
		boolean declareStatic= false;
53
		passHelper(9, 34, 9, 35, "i", declareStatic, declareFinal, initializeIn, accessModifier);
54
	}
48
}
55
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/test (+39 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and
9
 * is made available for testing and evaluation purposes only.
10
 * The code is not compatible with any specification of the JCP.
11
 *
12
 * Contributors:
13
 *     IBM Corporation - initial API and implementation
14
 *******************************************************************************/
15
package org.eclipse.jdt.ui.tests.refactoring;
16
17
import junit.framework.Test;
18
19
import org.eclipse.jdt.testplugin.JavaProjectHelper;
20
21
import org.eclipse.core.runtime.CoreException;
22
23
import org.eclipse.jdt.core.IJavaProject;
24
import org.eclipse.jdt.core.IPackageFragmentRoot;
25
26
public class SefTestSetup18 extends SefTestSetup {
27
28
	public SefTestSetup18(Test test) {
29
		super(test);
30
	}
31
32
	/*
33
	 * @see org.eclipse.jdt.ui.tests.refactoring.RefactoringTestSetup#addRTJar(org.eclipse.jdt.core.IJavaProject)
34
	 */
35
	@Override
36
	protected IPackageFragmentRoot addRTJar(IJavaProject project) throws CoreException {
37
		return JavaProjectHelper.addRTJar18(project);
38
	}
39
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SefTests.java (-10 / +10 lines)
Lines 1-9 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
Lines 35-41 Link Here
35
39
36
public class SefTests extends AbstractSelectionTestCase {
40
public class SefTests extends AbstractSelectionTestCase {
37
41
38
	private static SefTestSetup fgTestSetup;
42
	protected static SefTestSetup fgTestSetup;
39
43
40
	public SefTests(String name) {
44
	public SefTests(String name) {
41
		super(name);
45
		super(name);
Lines 110-128 Link Here
110
		return result;
114
		return result;
111
	}
115
	}
112
116
113
	private void objectTest(String fieldName) throws Exception {
117
	protected void objectTest(String fieldName) throws Exception {
114
		performTest(fgTestSetup.getObjectPackage(), getName(), "object_out", fieldName);
118
		performTest(fgTestSetup.getObjectPackage(), getName(), "object_out", fieldName);
115
	}
119
	}
116
120
117
	private void baseTest(String fieldName) throws Exception {
121
	protected void baseTest(String fieldName) throws Exception {
118
		performTest(fgTestSetup.getBasePackage(), getName(), "base_out", fieldName);
122
		performTest(fgTestSetup.getBasePackage(), getName(), "base_out", fieldName);
119
	}
123
	}
120
124
121
	private void invalidTest(String fieldName) throws Exception {
125
	protected void invalidTest(String fieldName) throws Exception {
122
		performInvalidTest(fgTestSetup.getInvalidPackage(), getName(), fieldName);
126
		performInvalidTest(fgTestSetup.getInvalidPackage(), getName(), fieldName);
123
	}
127
	}
124
128
125
	private void existingTest(String fieldName) throws Exception {
129
	protected void existingTest(String fieldName) throws Exception {
126
		performTest(fgTestSetup.getExistingMethodPackage(), getName(), "existingmethods_out", fieldName);
130
		performTest(fgTestSetup.getExistingMethodPackage(), getName(), "existingmethods_out", fieldName);
127
	}
131
	}
128
	//=====================================================================================
132
	//=====================================================================================
Lines 255-264 Link Here
255
	}
259
	}
256
260
257
	public void testGenericReadWrite() throws Exception {
261
	public void testGenericReadWrite() throws Exception {
258
		objectTest("field");
259
	}
260
261
	public void testArrayAnnotations() throws Exception {
262
		objectTest("field");
262
		objectTest("field");
263
	}
263
	}
264
264
(-)a/org.eclipse.jdt.ui.tests.refactoring/test (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and
9
 * is made available for testing and evaluation purposes only.
10
 * The code is not compatible with any specification of the JCP.
11
 *
12
 * Contributors:
13
 *     IBM Corporation - initial API and implementation
14
 *******************************************************************************/
15
package org.eclipse.jdt.ui.tests.refactoring;
16
17
import junit.framework.Test;
18
19
public class SefTests18 extends SefTests {
20
21
	public SefTests18(String name) {
22
		super(name);
23
	}
24
25
	public static Test suite() {
26
		fgTestSetup= new SefTestSetup18(new NoSuperTestsSuite(SefTests18.class));
27
		return fgTestSetup;
28
	}
29
30
	public static Test setUpTest(Test test) {
31
		fgTestSetup= new SefTestSetup18(test);
32
		return fgTestSetup;
33
	}
34
35
	public void testArrayAnnotations() throws Exception {
36
		objectTest("field");
37
	}
38
39
	public void testTypeUseAnnotations() throws Exception {
40
		objectTest("field");
41
	}
42
}
(-)a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java (-1 / +418 lines)
Lines 1290-1293 Link Here
1290
		assertCorrectLabels(proposals);
1290
		assertCorrectLabels(proposals);
1291
		assertProposalDoesNotExist(proposals, CorrectionMessages.QuickAssistProcessor_change_lambda_body_to_expression);
1291
		assertProposalDoesNotExist(proposals, CorrectionMessages.QuickAssistProcessor_change_lambda_body_to_expression);
1292
	}
1292
	}
1293
}
1293
1294
	public void testBug426967Comment2() throws Exception {
1295
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
1296
		StringBuffer buf= new StringBuffer();
1297
		buf.append("package test1;\n");
1298
		buf.append("\n");
1299
		buf.append("class E {\n");
1300
		buf.append("    private void foo() {\n");
1301
		buf.append("        for (String str : new String[1]) {\n");
1302
		buf.append("        }\n");
1303
		buf.append("    }\n");
1304
		buf.append("}\n");
1305
		ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
1306
1307
		int offset= buf.toString().indexOf("str");
1308
		AssistContext context= getCorrectionContext(cu, offset, 0);
1309
		assertNoErrors(context);
1310
		List proposals= collectAssists(context, false);
1311
		buf= new StringBuffer();
1312
		buf.append("package test1;\n");
1313
		buf.append("\n");
1314
		buf.append("class E {\n");
1315
		buf.append("    private void foo() {\n");
1316
		buf.append("        String[] strings = new String[1];\n");
1317
		buf.append("        for (int i = 0; i < strings.length; i++) {\n");
1318
		buf.append("            String str = strings[i];\n");
1319
		buf.append("        }\n");
1320
		buf.append("    }\n");
1321
		buf.append("}\n");
1322
		assertNumberOfProposals(proposals, 1);
1323
		assertCorrectLabels(proposals);
1324
1325
		String expected1= buf.toString();
1326
1327
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
1328
	}
1329
1330
	public void testTypeAnnotations1() throws Exception {
1331
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
1332
		StringBuffer buf= new StringBuffer();
1333
		buf.append("package test1;\n");
1334
		buf.append("\n");
1335
		buf.append("import java.lang.annotation.ElementType;\n");
1336
		buf.append("import java.lang.annotation.Target;\n");
1337
		buf.append("\n");
1338
		buf.append("public class C1 {\n");
1339
		buf.append("    private void foo() {\n");
1340
		buf.append("        for(@ReadOnly String s11= \"a\";;) ;\n");
1341
		buf.append("    }\n");
1342
		buf.append("}\n");
1343
		buf.append("\n");
1344
		buf.append("@Target(ElementType.TYPE_USE)\n");
1345
		buf.append("@interface ReadOnly {\n");
1346
		buf.append("}\n");
1347
		ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf.toString(), false, null);
1348
1349
		int offset= buf.toString().indexOf("s11");
1350
		AssistContext context= getCorrectionContext(cu, offset, 0);
1351
		assertNoErrors(context);
1352
		List proposals= collectAssists(context, false);
1353
		buf= new StringBuffer();
1354
		buf.append("package test1;\n");
1355
		buf.append("\n");
1356
		buf.append("import java.lang.annotation.ElementType;\n");
1357
		buf.append("import java.lang.annotation.Target;\n");
1358
		buf.append("\n");
1359
		buf.append("public class C1 {\n");
1360
		buf.append("    private void foo() {\n");
1361
		buf.append("        @ReadOnly String s11;\n");
1362
		buf.append("        for(s11 = \"a\";;) ;\n");
1363
		buf.append("    }\n");
1364
		buf.append("}\n");
1365
		buf.append("\n");
1366
		buf.append("@Target(ElementType.TYPE_USE)\n");
1367
		buf.append("@interface ReadOnly {\n");
1368
		buf.append("}\n");
1369
		assertNumberOfProposals(proposals, 1);
1370
		assertCorrectLabels(proposals);
1371
1372
		String expected1= buf.toString();
1373
1374
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
1375
	}
1376
1377
	public void testTypeAnnotations2() throws Exception {
1378
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
1379
		StringBuffer buf1= new StringBuffer();
1380
		buf1.append("package test1;\n");
1381
		buf1.append("\n");
1382
		buf1.append("import java.lang.annotation.ElementType;\n");
1383
		buf1.append("import java.lang.annotation.Target;\n");
1384
		buf1.append("\n");
1385
		buf1.append("public class C1 {\n");
1386
		buf1.append("    private void foo() {\n");
1387
		buf1.append("        try {\n");
1388
		buf1.append("            if (true)\n");
1389
		buf1.append("                throw new CloneNotSupportedException();\n");
1390
		buf1.append("            else\n");
1391
		buf1.append("                throw new ClassNotFoundException();\n");
1392
		buf1.append("        } catch (@TA1  CloneNotSupportedException | @TA2 ClassNotFoundException e) {\n");
1393
		buf1.append("        }\n");
1394
		buf1.append("    }\n");
1395
		buf1.append("}\n");
1396
		buf1.append("\n");
1397
		buf1.append("@Target(ElementType.TYPE_USE)\n");
1398
		buf1.append("@interface TA1 {}\n");
1399
		buf1.append("\n");
1400
		buf1.append("@Target(ElementType.TYPE_USE)\n");
1401
		buf1.append("@interface TA2 {}\n");
1402
		ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf1.toString(), false, null);
1403
1404
		int offset= buf1.toString().indexOf("CloneNotSupportedException |");
1405
		AssistContext context= getCorrectionContext(cu, offset, 0);
1406
		assertNoErrors(context);
1407
		List proposals= collectAssists(context, false);
1408
		assertNumberOfProposals(proposals, 4);
1409
		assertCorrectLabels(proposals);
1410
1411
		StringBuffer buf= new StringBuffer();
1412
		buf.append("package test1;\n");
1413
		buf.append("\n");
1414
		buf.append("import java.lang.annotation.ElementType;\n");
1415
		buf.append("import java.lang.annotation.Target;\n");
1416
		buf.append("\n");
1417
		buf.append("public class C1 {\n");
1418
		buf.append("    private void foo() {\n");
1419
		buf.append("        try {\n");
1420
		buf.append("            if (true)\n");
1421
		buf.append("                throw new CloneNotSupportedException();\n");
1422
		buf.append("            else\n");
1423
		buf.append("                throw new ClassNotFoundException();\n");
1424
		buf.append("        } catch (@TA2 ClassNotFoundException e) {\n");
1425
		buf.append("        }\n");
1426
		buf.append("    }\n");
1427
		buf.append("}\n");
1428
		buf.append("\n");
1429
		buf.append("@Target(ElementType.TYPE_USE)\n");
1430
		buf.append("@interface TA1 {}\n");
1431
		buf.append("\n");
1432
		buf.append("@Target(ElementType.TYPE_USE)\n");
1433
		buf.append("@interface TA2 {}\n");
1434
		String expected1= buf.toString();
1435
1436
		buf= new StringBuffer();
1437
		buf.append("package test1;\n");
1438
		buf.append("\n");
1439
		buf.append("import java.lang.annotation.ElementType;\n");
1440
		buf.append("import java.lang.annotation.Target;\n");
1441
		buf.append("\n");
1442
		buf.append("public class C1 {\n");
1443
		buf.append("    private void foo() throws @TA1 CloneNotSupportedException {\n");
1444
		buf.append("        try {\n");
1445
		buf.append("            if (true)\n");
1446
		buf.append("                throw new CloneNotSupportedException();\n");
1447
		buf.append("            else\n");
1448
		buf.append("                throw new ClassNotFoundException();\n");
1449
		buf.append("        } catch (@TA2 ClassNotFoundException e) {\n");
1450
		buf.append("        }\n");
1451
		buf.append("    }\n");
1452
		buf.append("}\n");
1453
		buf.append("\n");
1454
		buf.append("@Target(ElementType.TYPE_USE)\n");
1455
		buf.append("@interface TA1 {}\n");
1456
		buf.append("\n");
1457
		buf.append("@Target(ElementType.TYPE_USE)\n");
1458
		buf.append("@interface TA2 {}\n");
1459
		String expected2= buf.toString();
1460
1461
		buf= new StringBuffer();
1462
		buf.append("package test1;\n");
1463
		buf.append("\n");
1464
		buf.append("import java.lang.annotation.ElementType;\n");
1465
		buf.append("import java.lang.annotation.Target;\n");
1466
		buf.append("\n");
1467
		buf.append("public class C1 {\n");
1468
		buf.append("    private void foo() {\n");
1469
		buf.append("        try {\n");
1470
		buf.append("            if (true)\n");
1471
		buf.append("                throw new CloneNotSupportedException();\n");
1472
		buf.append("            else\n");
1473
		buf.append("                throw new ClassNotFoundException();\n");
1474
		buf.append("        } catch (@TA2 ClassNotFoundException e) {\n");
1475
		buf.append("        } catch (@TA1 CloneNotSupportedException e) {\n");
1476
		buf.append("        }\n");
1477
		buf.append("    }\n");
1478
		buf.append("}\n");
1479
		buf.append("\n");
1480
		buf.append("@Target(ElementType.TYPE_USE)\n");
1481
		buf.append("@interface TA1 {}\n");
1482
		buf.append("\n");
1483
		buf.append("@Target(ElementType.TYPE_USE)\n");
1484
		buf.append("@interface TA2 {}\n");
1485
		String expected3= buf.toString();
1486
1487
		assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3 });
1488
1489
		offset= buf1.toString().indexOf("@TA1  CloneNotSupportedException |");
1490
		context= getCorrectionContext(cu, offset, 0);
1491
		assertNoErrors(context);
1492
		proposals= collectAssists(context, false);
1493
		assertNumberOfProposals(proposals, 4);
1494
		assertCorrectLabels(proposals);
1495
1496
		buf= new StringBuffer();
1497
		buf.append("package test1;\n");
1498
		buf.append("\n");
1499
		buf.append("import java.lang.annotation.ElementType;\n");
1500
		buf.append("import java.lang.annotation.Target;\n");
1501
		buf.append("\n");
1502
		buf.append("public class C1 {\n");
1503
		buf.append("    private void foo() throws @TA1 CloneNotSupportedException, @TA2 ClassNotFoundException {\n");
1504
		buf.append("        if (true)\n");
1505
		buf.append("            throw new CloneNotSupportedException();\n");
1506
		buf.append("        else\n");
1507
		buf.append("            throw new ClassNotFoundException();\n");
1508
		buf.append("    }\n");
1509
		buf.append("}\n");
1510
		buf.append("\n");
1511
		buf.append("@Target(ElementType.TYPE_USE)\n");
1512
		buf.append("@interface TA1 {}\n");
1513
		buf.append("\n");
1514
		buf.append("@Target(ElementType.TYPE_USE)\n");
1515
		buf.append("@interface TA2 {}\n");
1516
		String expected4= buf.toString();
1517
1518
		assertExpectedExistInProposals(proposals, new String[] { expected4 });
1519
	}
1520
1521
	public void testTypeAnnotations3() throws Exception {
1522
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
1523
		StringBuffer buf= new StringBuffer();
1524
		buf.append("package test1;\n");
1525
		buf.append("\n");
1526
		buf.append("import java.lang.annotation.ElementType;\n");
1527
		buf.append("import java.lang.annotation.Target;\n");
1528
		buf.append("\n");
1529
		buf.append("public class C1 {\n");
1530
		buf.append("    private void foo() {\n");
1531
		buf.append("        try {\n");
1532
		buf.append("            if (true)\n");
1533
		buf.append("                throw new CloneNotSupportedException();\n");
1534
		buf.append("            else\n");
1535
		buf.append("                throw new ClassNotFoundException();\n");
1536
		buf.append("        } catch (@TA1 CloneNotSupportedException e) {\n");
1537
		buf.append("        } catch (@TA2 ClassNotFoundException e) {\n");
1538
		buf.append("        }\n");
1539
		buf.append("    }\n");
1540
		buf.append("}\n");
1541
		buf.append("\n");
1542
		buf.append("@Target(ElementType.TYPE_USE)\n");
1543
		buf.append("@interface TA1 {}\n");
1544
		buf.append("\n");
1545
		buf.append("@Target(ElementType.TYPE_USE)\n");
1546
		buf.append("@interface TA2 {}\n");
1547
		ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf.toString(), false, null);
1548
1549
		int offset= buf.toString().indexOf("catch");
1550
		AssistContext context= getCorrectionContext(cu, offset, 0);
1551
		assertNoErrors(context);
1552
		List proposals= collectAssists(context, false);
1553
		buf= new StringBuffer();
1554
		buf.append("package test1;\n");
1555
		buf.append("\n");
1556
		buf.append("import java.lang.annotation.ElementType;\n");
1557
		buf.append("import java.lang.annotation.Target;\n");
1558
		buf.append("\n");
1559
		buf.append("public class C1 {\n");
1560
		buf.append("    private void foo() {\n");
1561
		buf.append("        try {\n");
1562
		buf.append("            if (true)\n");
1563
		buf.append("                throw new CloneNotSupportedException();\n");
1564
		buf.append("            else\n");
1565
		buf.append("                throw new ClassNotFoundException();\n");
1566
		buf.append("        } catch (@TA1 CloneNotSupportedException | @TA2 ClassNotFoundException e) {\n");
1567
		buf.append("        }\n");
1568
		buf.append("    }\n");
1569
		buf.append("}\n");
1570
		buf.append("\n");
1571
		buf.append("@Target(ElementType.TYPE_USE)\n");
1572
		buf.append("@interface TA1 {}\n");
1573
		buf.append("\n");
1574
		buf.append("@Target(ElementType.TYPE_USE)\n");
1575
		buf.append("@interface TA2 {}\n");
1576
		assertNumberOfProposals(proposals, 4);
1577
		assertCorrectLabels(proposals);
1578
1579
		String expected1= buf.toString();
1580
1581
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
1582
	}
1583
1584
	public void testTypeAnnotations4() throws Exception {
1585
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
1586
		StringBuffer buf= new StringBuffer();
1587
		buf.append("package test1;\n");
1588
		buf.append("\n");
1589
		buf.append("import java.lang.annotation.ElementType;\n");
1590
		buf.append("import java.lang.annotation.Target;\n");
1591
		buf.append("\n");
1592
		buf.append("public class C1 {\n");
1593
		buf.append("    private void foo() {\n");
1594
		buf.append("        try {\n");
1595
		buf.append("            if (true)\n");
1596
		buf.append("                throw new CloneNotSupportedException();\n");
1597
		buf.append("            else\n");
1598
		buf.append("                throw new ClassNotFoundException();\n");
1599
		buf.append("        } catch (@TA1 CloneNotSupportedException e) {\n");
1600
		buf.append("        } catch (@TA1 ClassCastException | @TA2 ClassNotFoundException e) {\n");
1601
		buf.append("        }\n");
1602
		buf.append("    }\n");
1603
		buf.append("}\n");
1604
		buf.append("\n");
1605
		buf.append("@Target(ElementType.TYPE_USE)\n");
1606
		buf.append("@interface TA1 {}\n");
1607
		buf.append("\n");
1608
		buf.append("@Target(ElementType.TYPE_USE)\n");
1609
		buf.append("@interface TA2 {}\n");
1610
		ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf.toString(), false, null);
1611
1612
		int offset= buf.toString().indexOf("catch");
1613
		AssistContext context= getCorrectionContext(cu, offset, 0);
1614
		assertNoErrors(context);
1615
		List proposals= collectAssists(context, false);
1616
		buf= new StringBuffer();
1617
		buf.append("package test1;\n");
1618
		buf.append("\n");
1619
		buf.append("import java.lang.annotation.ElementType;\n");
1620
		buf.append("import java.lang.annotation.Target;\n");
1621
		buf.append("\n");
1622
		buf.append("public class C1 {\n");
1623
		buf.append("    private void foo() {\n");
1624
		buf.append("        try {\n");
1625
		buf.append("            if (true)\n");
1626
		buf.append("                throw new CloneNotSupportedException();\n");
1627
		buf.append("            else\n");
1628
		buf.append("                throw new ClassNotFoundException();\n");
1629
		buf.append("        } catch (@TA1 CloneNotSupportedException | @TA1 ClassCastException | @TA2 ClassNotFoundException e) {\n");
1630
		buf.append("        }\n");
1631
		buf.append("    }\n");
1632
		buf.append("}\n");
1633
		buf.append("\n");
1634
		buf.append("@Target(ElementType.TYPE_USE)\n");
1635
		buf.append("@interface TA1 {}\n");
1636
		buf.append("\n");
1637
		buf.append("@Target(ElementType.TYPE_USE)\n");
1638
		buf.append("@interface TA2 {}\n");
1639
		assertNumberOfProposals(proposals, 4);
1640
		assertCorrectLabels(proposals);
1641
1642
		String expected1= buf.toString();
1643
1644
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
1645
	}
1646
1647
	public void testTypeAnnotations5() throws Exception {
1648
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
1649
		StringBuffer buf= new StringBuffer();
1650
		buf.append("package test1;\n");
1651
		buf.append("\n");
1652
		buf.append("import java.lang.annotation.ElementType;\n");
1653
		buf.append("import java.lang.annotation.Target;\n");
1654
		buf.append("\n");
1655
		buf.append("public class C1 {\n");
1656
		buf.append("    private void foo() {\n");
1657
		buf.append("        try {\n");
1658
		buf.append("            if (true)\n");
1659
		buf.append("                throw new CloneNotSupportedException();\n");
1660
		buf.append("            else\n");
1661
		buf.append("                throw new ClassNotFoundException();\n");
1662
		buf.append("        } catch (@TA1 CloneNotSupportedException | @TA2 ClassNotFoundException e) {\n");
1663
		buf.append("        }\n");
1664
		buf.append("    }\n");
1665
		buf.append("}\n");
1666
		buf.append("\n");
1667
		buf.append("@Target(ElementType.TYPE_USE)\n");
1668
		buf.append("@interface TA1 {}\n");
1669
		buf.append("\n");
1670
		buf.append("@Target(ElementType.TYPE_USE)\n");
1671
		buf.append("@interface TA2 {}\n");
1672
		ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf.toString(), false, null);
1673
1674
		int offset= buf.toString().indexOf("catch");
1675
		AssistContext context= getCorrectionContext(cu, offset, 0);
1676
		assertNoErrors(context);
1677
		List proposals= collectAssists(context, false);
1678
		buf= new StringBuffer();
1679
		buf.append("package test1;\n");
1680
		buf.append("\n");
1681
		buf.append("import java.lang.annotation.ElementType;\n");
1682
		buf.append("import java.lang.annotation.Target;\n");
1683
		buf.append("\n");
1684
		buf.append("public class C1 {\n");
1685
		buf.append("    private void foo() {\n");
1686
		buf.append("        try {\n");
1687
		buf.append("            if (true)\n");
1688
		buf.append("                throw new CloneNotSupportedException();\n");
1689
		buf.append("            else\n");
1690
		buf.append("                throw new ClassNotFoundException();\n");
1691
		buf.append("        } catch (@TA1 CloneNotSupportedException e) {\n");
1692
		buf.append("        } catch (@TA2 ClassNotFoundException e) {\n");
1693
		buf.append("        }\n");
1694
		buf.append("    }\n");
1695
		buf.append("}\n");
1696
		buf.append("\n");
1697
		buf.append("@Target(ElementType.TYPE_USE)\n");
1698
		buf.append("@interface TA1 {}\n");
1699
		buf.append("\n");
1700
		buf.append("@Target(ElementType.TYPE_USE)\n");
1701
		buf.append("@interface TA2 {}\n");
1702
		assertNumberOfProposals(proposals, 4);
1703
		assertCorrectLabels(proposals);
1704
1705
		String expected1= buf.toString();
1706
1707
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
1708
	}
1709
1710
}
(-)a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest.java (+1 lines)
Lines 75-80 Link Here
75
75
76
	public static Test suite() {
76
	public static Test suite() {
77
		TestSuite suite= new TestSuite(QuickFixTest.class.getName());
77
		TestSuite suite= new TestSuite(QuickFixTest.class.getName());
78
		suite.addTest(QuickFixTest18.suite());
78
		suite.addTest(SerialVersionQuickFixTest.suite());
79
		suite.addTest(SerialVersionQuickFixTest.suite());
79
		suite.addTest(UtilitiesTest.suite());
80
		suite.addTest(UtilitiesTest.suite());
80
		suite.addTest(UnresolvedTypesQuickFixTest.suite());
81
		suite.addTest(UnresolvedTypesQuickFixTest.suite());
(-)a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest18.java (-3 / +56 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2013 IBM Corporation and others.
2
 * Copyright (c) 2013, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 68-75 Link Here
68
		Hashtable options= TestOptions.getDefaultOptions();
68
		Hashtable options= TestOptions.getDefaultOptions();
69
		options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
69
		options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
70
		options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
70
		options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
71
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, JavaCore.DO_NOT_INSERT);
71
		options.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.WARNING);
72
73
72
74
		JavaCore.setOptions(options);
73
		JavaCore.setOptions(options);
75
74
Lines 195-198 Link Here
195
		assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
194
		assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
196
195
197
	}
196
	}
197
198
	public void testTypeAnnotations1() throws Exception {
199
		StringBuffer buf= new StringBuffer();
200
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
201
		buf= new StringBuffer();
202
		buf.append("package test1;\n");
203
		buf.append("import java.lang.annotation.ElementType;\n");
204
		buf.append("import java.lang.annotation.Target;\n");
205
		buf.append("\n");
206
		buf.append("public class C1 {\n");
207
		buf.append("    private void foo() {\n");
208
		buf.append("        @TA1 int @TA2 [] @TA3 [] v1= fun(), v2;\n");
209
		buf.append("    }\n");
210
		buf.append("    private @TA1 int @TA2 [] @TA3 [] fun() {\n");
211
		buf.append("        return null;\n");
212
		buf.append("    }\n");
213
		buf.append("}\n");
214
		buf.append("\n");
215
		buf.append("@Target(ElementType.TYPE_USE) @interface TA1 {}\n");
216
		buf.append("@Target(ElementType.TYPE_USE) @interface TA2 {}\n");
217
		buf.append("@Target(ElementType.TYPE_USE) @interface TA3 {}\n");
218
		ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf.toString(), false, null);
219
220
		CompilationUnit astRoot= getASTRoot(cu);
221
		ArrayList proposals= collectCorrections(cu, astRoot, 2);
222
		assertNumberOfProposals(proposals, 4);
223
		assertCorrectLabels(proposals);
224
225
		CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(0);
226
		String preview1= getPreviewContent(proposal);
227
228
		buf= new StringBuffer();
229
		buf.append("package test1;\n");
230
		buf.append("import java.lang.annotation.ElementType;\n");
231
		buf.append("import java.lang.annotation.Target;\n");
232
		buf.append("\n");
233
		buf.append("public class C1 {\n");
234
		buf.append("    private void foo() {\n");
235
		buf.append("        fun();\n");
236
		buf.append("        @TA1 int @TA2 [] @TA3 [] v2;\n");
237
		buf.append("    }\n");
238
		buf.append("    private @TA1 int @TA2 [] @TA3 [] fun() {\n");
239
		buf.append("        return null;\n");
240
		buf.append("    }\n");
241
		buf.append("}\n");
242
		buf.append("\n");
243
		buf.append("@Target(ElementType.TYPE_USE) @interface TA1 {}\n");
244
		buf.append("@Target(ElementType.TYPE_USE) @interface TA2 {}\n");
245
		buf.append("@Target(ElementType.TYPE_USE) @interface TA3 {}\n");
246
		String expected1= buf.toString();
247
248
		assertEqualStringsIgnoreOrder(new String[] { preview1 }, new String[] { expected1 });
249
250
	}
198
}
251
}
(-)a/org.eclipse.jdt.ui/core (+170 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 *
12
 * Contributors:
13
 *     IBM Corporation - initial API and implementation
14
 *******************************************************************************/
15
package org.eclipse.jdt.internal.corext.dom;
16
17
import java.util.ArrayList;
18
import java.util.Arrays;
19
import java.util.Collections;
20
import java.util.List;
21
22
import org.eclipse.text.edits.TextEditGroup;
23
24
import org.eclipse.jdt.core.dom.ASTNode;
25
import org.eclipse.jdt.core.dom.AnnotatableType;
26
import org.eclipse.jdt.core.dom.Annotation;
27
import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration;
28
import org.eclipse.jdt.core.dom.ArrayType;
29
import org.eclipse.jdt.core.dom.FieldDeclaration;
30
import org.eclipse.jdt.core.dom.IAnnotationBinding;
31
import org.eclipse.jdt.core.dom.IExtendedModifier;
32
import org.eclipse.jdt.core.dom.ITypeBinding;
33
import org.eclipse.jdt.core.dom.MethodDeclaration;
34
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
35
import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
36
import org.eclipse.jdt.core.dom.Type;
37
import org.eclipse.jdt.core.dom.UnionType;
38
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
39
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
40
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
41
42
import org.eclipse.jdt.internal.corext.util.JDTUIHelperClasses;
43
44
/**
45
 * Rewrite helper for type annotations part of the declaration's modifiers of a type reference.
46
 * 
47
 * @see JDTUIHelperClasses
48
 * @since 3.9 BETA_JAVA8
49
 */
50
public class DeclarationRewrite {
51
52
	/**
53
	 * Creates a copy of the given <code>typeNode</code> and adds its type annotations to the copied
54
	 * type by removing them from its declaration's modifiers.
55
	 * 
56
	 * @param typeNode the Type node
57
	 * @param rewrite the ASTRewrite with which to create new nodes
58
	 * @param editGroup the edit group in which to collect the corresponding text edits, or null if
59
	 *            ungrouped
60
	 * @return copy of the type node with added type annotations
61
	 */
62
	public static Type copyTypeAndMoveTypeAnnotations(Type typeNode, ASTRewrite rewrite, TextEditGroup editGroup) {
63
		Type copiedtypeNode= copyTypeAndAddTypeAnnotations(typeNode, rewrite);
64
		removeTypeAnnotationsFromDeclaration(typeNode, rewrite, editGroup);
65
		return copiedtypeNode;
66
	}
67
68
	/**
69
	 * Creates a copy of the given <code>typeNode</code> and adds its type annotations to the copied
70
	 * type by copying them from its declaration's modifiers. The type annotations are not removed
71
	 * from the declaration node.
72
	 * 
73
	 * @param typeNode the Type node
74
	 * @param rewrite the ASTRewrite with which to create new nodes
75
	 * @return copy of the type node with added type annotations
76
	 */
77
	public static Type copyTypeAndAddTypeAnnotations(Type typeNode, ASTRewrite rewrite) {
78
		if (!(typeNode instanceof AnnotatableType || (typeNode instanceof ArrayType && ((ArrayType) typeNode).getElementType() instanceof AnnotatableType)))
79
			return (Type) rewrite.createCopyTarget(typeNode);
80
81
		List<Annotation> typeAnnotations= DeclarationRewrite.getTypeAnnotationsOnDeclaration(typeNode);
82
		if (typeAnnotations.isEmpty())
83
			return (Type) rewrite.createCopyTarget(typeNode);
84
85
		Type copiedTypeNode= (Type) ASTNode.copySubtree(rewrite.getAST(), typeNode);
86
		AnnotatableType copiedAnnotatableType;
87
		if (copiedTypeNode instanceof ArrayType) {
88
			copiedAnnotatableType= (AnnotatableType) ((ArrayType) copiedTypeNode).getElementType();
89
		} else {
90
			copiedAnnotatableType= (AnnotatableType) copiedTypeNode;
91
		}
92
		for (Annotation annotation : typeAnnotations) {
93
			copiedAnnotatableType.annotations().add(rewrite.createCopyTarget(annotation));
94
		}
95
		return copiedTypeNode;
96
	}
97
98
	/**
99
	 * Removes type annotations of the given <code>typeNode</code> from its declaration's modifiers.
100
	 * 
101
	 * @param typeNode the Type node
102
	 * @param rewrite rewrite that removes the nodes
103
	 * @param editGroup the edit group in which to collect the corresponding text edits, or null if
104
	 *            ungrouped
105
	 */
106
	public static void removeTypeAnnotationsFromDeclaration(Type typeNode, ASTRewrite rewrite, TextEditGroup editGroup) {
107
		List<Annotation> typeAnnotations= DeclarationRewrite.getTypeAnnotationsOnDeclaration(typeNode);
108
		for (Annotation annotation : typeAnnotations) {
109
			rewrite.remove(annotation, editGroup);
110
		}
111
	}
112
113
	private static List<Annotation> getTypeAnnotationsOnDeclaration(Type typeNode) {
114
		ITypeBinding typeBinding= typeNode.resolveBinding();
115
		if (typeBinding == null)
116
			return Collections.emptyList();
117
118
		List<IAnnotationBinding> typeAnnotationBindings;
119
		if (typeBinding.isArray()) {
120
			typeAnnotationBindings= Arrays.asList(typeBinding.getElementType().getTypeAnnotations());
121
		} else {
122
			typeAnnotationBindings= Arrays.asList(typeBinding.getTypeAnnotations());
123
		}
124
125
		if (typeAnnotationBindings.size() == 0)
126
			return Collections.emptyList();
127
128
		List<IExtendedModifier> declarationModifiers= new ArrayList<IExtendedModifier>();
129
		StructuralPropertyDescriptor locationInParent= typeNode.getLocationInParent();
130
131
		if (locationInParent == UnionType.TYPES_PROPERTY) {
132
			typeNode= (UnionType) typeNode.getParent();
133
			locationInParent= typeNode.getLocationInParent();
134
		}
135
136
		if (locationInParent == ArrayType.ELEMENT_TYPE_PROPERTY) {
137
			typeNode= (ArrayType) typeNode.getParent();
138
			locationInParent= typeNode.getLocationInParent();
139
		}
140
141
		if (locationInParent == MethodDeclaration.RETURN_TYPE2_PROPERTY) {
142
			declarationModifiers= ((MethodDeclaration) typeNode.getParent()).modifiers();
143
		} else if (locationInParent == FieldDeclaration.TYPE_PROPERTY) {
144
			declarationModifiers= ((FieldDeclaration) typeNode.getParent()).modifiers();
145
		} else if (locationInParent == VariableDeclarationExpression.TYPE_PROPERTY) {
146
			declarationModifiers= ((VariableDeclarationExpression) typeNode.getParent()).modifiers();
147
		} else if (locationInParent == VariableDeclarationStatement.TYPE_PROPERTY) {
148
			declarationModifiers= ((VariableDeclarationStatement) typeNode.getParent()).modifiers();
149
		} else if (locationInParent == SingleVariableDeclaration.TYPE_PROPERTY) {
150
			declarationModifiers= ((SingleVariableDeclaration) typeNode.getParent()).modifiers();
151
		} else if (locationInParent == AnnotationTypeMemberDeclaration.TYPE_PROPERTY) {
152
			declarationModifiers= ((AnnotationTypeMemberDeclaration) typeNode.getParent()).modifiers();
153
		}
154
155
		return getTypeAnnotationsFromModifiers(declarationModifiers, typeAnnotationBindings);
156
	}
157
158
	private static List<Annotation> getTypeAnnotationsFromModifiers(List<IExtendedModifier> modifiers, List<IAnnotationBinding> typeAnnotationBindings) {
159
		List<Annotation> typeAnnotations= new ArrayList<Annotation>();
160
		for (IExtendedModifier modifier : modifiers) {
161
			if (modifier.isAnnotation()) {
162
				IAnnotationBinding modifierAnnotationBinding= ((Annotation) modifier).resolveAnnotationBinding();
163
				if (typeAnnotationBindings.contains(modifierAnnotationBinding)) {
164
					typeAnnotations.add((Annotation) modifier);
165
				}
166
			}
167
		}
168
		return typeAnnotations;
169
	}
170
}
(-)a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/DimensionRewrite.java (-5 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2013 IBM Corporation and others.
2
 * Copyright (c) 2013, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 39-45 Link Here
39
public class DimensionRewrite {
39
public class DimensionRewrite {
40
40
41
	/**
41
	/**
42
	 * Creates a {@link ASTRewrite#createCopyTarget(ASTNode) copy} of <code>type</code>
42
	 * Creates a {@link DeclarationRewrite#copyTypeAndAddTypeAnnotations(Type, ASTRewrite) copy} of <code>type</code>
43
	 * and adds <code>extraDimensions</code> to it.
43
	 * and adds <code>extraDimensions</code> to it.
44
	 * 
44
	 * 
45
	 * @param type the type to copy
45
	 * @param type the type to copy
Lines 50-67 Link Here
50
	public static Type copyTypeAndAddDimensions(Type type, List<Dimension> extraDimensions, ASTRewrite rewrite) {
50
	public static Type copyTypeAndAddDimensions(Type type, List<Dimension> extraDimensions, ASTRewrite rewrite) {
51
		AST ast= rewrite.getAST();
51
		AST ast= rewrite.getAST();
52
		if (extraDimensions.isEmpty()) {
52
		if (extraDimensions.isEmpty()) {
53
			return (Type) rewrite.createCopyTarget(type);
53
			return DeclarationRewrite.copyTypeAndAddTypeAnnotations(type, rewrite);
54
		}
54
		}
55
		
55
		
56
		ArrayType result;
56
		ArrayType result;
57
		if (type instanceof ArrayType) {
57
		if (type instanceof ArrayType) {
58
			ArrayType arrayType= (ArrayType) type;
58
			ArrayType arrayType= (ArrayType) type;
59
			Type varElementType= (Type) rewrite.createCopyTarget(arrayType.getElementType());
59
			Type varElementType= DeclarationRewrite.copyTypeAndAddTypeAnnotations(arrayType.getElementType(), rewrite);
60
			result= ast.newArrayType(varElementType, 0);
60
			result= ast.newArrayType(varElementType, 0);
61
			result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
61
			result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
62
			result.dimensions().addAll(copyDimensions(arrayType.dimensions(), rewrite));
62
			result.dimensions().addAll(copyDimensions(arrayType.dimensions(), rewrite));
63
		} else {
63
		} else {
64
			Type elementType= (Type) rewrite.createCopyTarget(type);
64
			Type elementType= DeclarationRewrite.copyTypeAndAddTypeAnnotations(type, rewrite);
65
			result= ast.newArrayType(elementType, 0);
65
			result= ast.newArrayType(elementType, 0);
66
			result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
66
			result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
67
		}
67
		}
(-)a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/UnusedCodeFix.java (-2 / +7 lines)
Lines 1-9 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
Lines 63-68 Link Here
63
import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
67
import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
64
68
65
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
69
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
70
import org.eclipse.jdt.internal.corext.dom.DeclarationRewrite;
66
import org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder;
71
import org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder;
67
import org.eclipse.jdt.internal.corext.dom.NecessaryParenthesesChecker;
72
import org.eclipse.jdt.internal.corext.dom.NecessaryParenthesesChecker;
68
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
73
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
Lines 392-398 Link Here
392
					VariableDeclarationFragment movedFragment= (VariableDeclarationFragment) rewrite.createMoveTarget(currentFragment);
397
					VariableDeclarationFragment movedFragment= (VariableDeclarationFragment) rewrite.createMoveTarget(currentFragment);
393
					if (newDeclaration == null) {
398
					if (newDeclaration == null) {
394
						newDeclaration= rewrite.getAST().newVariableDeclarationStatement(movedFragment);
399
						newDeclaration= rewrite.getAST().newVariableDeclarationStatement(movedFragment);
395
						Type copiedType= (Type) rewrite.createCopyTarget(originalStatement.getType());
400
						Type copiedType= DeclarationRewrite.copyTypeAndAddTypeAnnotations(originalStatement.getType(), rewrite);
396
						newDeclaration.setType(copiedType);
401
						newDeclaration.setType(copiedType);
397
					} else
402
					} else
398
						newDeclaration.fragments().add(movedFragment);
403
						newDeclaration.fragments().add(movedFragment);
(-)a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/JDTUIHelperClasses.java (-1 / +7 lines)
Lines 1-9 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2013 IBM Corporation and others.
2
 * Copyright (c) 2013, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
Lines 21-26 Link Here
21
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
25
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
22
import org.eclipse.jdt.internal.corext.dom.Bindings;
26
import org.eclipse.jdt.internal.corext.dom.Bindings;
23
import org.eclipse.jdt.internal.corext.dom.BodyDeclarationRewrite;
27
import org.eclipse.jdt.internal.corext.dom.BodyDeclarationRewrite;
28
import org.eclipse.jdt.internal.corext.dom.DeclarationRewrite;
24
import org.eclipse.jdt.internal.corext.dom.DimensionRewrite;
29
import org.eclipse.jdt.internal.corext.dom.DimensionRewrite;
25
import org.eclipse.jdt.internal.corext.dom.GenericVisitor;
30
import org.eclipse.jdt.internal.corext.dom.GenericVisitor;
26
import org.eclipse.jdt.internal.corext.dom.HierarchicalASTVisitor;
31
import org.eclipse.jdt.internal.corext.dom.HierarchicalASTVisitor;
Lines 106-111 Link Here
106
 * <li>{@link CompilationUnitRewrite}</li>
111
 * <li>{@link CompilationUnitRewrite}</li>
107
 * <li>{@link BodyDeclarationRewrite}</li>
112
 * <li>{@link BodyDeclarationRewrite}</li>
108
 * <li>{@link DimensionRewrite}</li>
113
 * <li>{@link DimensionRewrite}</li>
114
 * <li>{@link DeclarationRewrite}</li>
109
 * <li>{@link ModifierRewrite}</li>
115
 * <li>{@link ModifierRewrite}</li>
110
 * <li>{@link ReplaceRewrite}</li>
116
 * <li>{@link ReplaceRewrite}</li>
111
 * <li>{@link StatementRewrite}</li>
117
 * <li>{@link StatementRewrite}</li>
(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/PromoteTempToFieldRefactoring.java (-1 / +2 lines)
Lines 81-86 Link Here
81
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
81
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
82
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
82
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
83
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
83
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
84
import org.eclipse.jdt.internal.corext.dom.DeclarationRewrite;
84
import org.eclipse.jdt.internal.corext.dom.DimensionRewrite;
85
import org.eclipse.jdt.internal.corext.dom.DimensionRewrite;
85
import org.eclipse.jdt.internal.corext.dom.HierarchicalASTVisitor;
86
import org.eclipse.jdt.internal.corext.dom.HierarchicalASTVisitor;
86
import org.eclipse.jdt.internal.corext.dom.ModifierRewrite;
87
import org.eclipse.jdt.internal.corext.dom.ModifierRewrite;
Lines 862-868 Link Here
862
		FieldDeclaration fieldDeclaration= ast.newFieldDeclaration(fragment);
863
		FieldDeclaration fieldDeclaration= ast.newFieldDeclaration(fragment);
863
864
864
		VariableDeclarationStatement vds= getTempDeclarationStatement();
865
		VariableDeclarationStatement vds= getTempDeclarationStatement();
865
		Type type= (Type)rewrite.createCopyTarget(vds.getType());
866
		Type type= DeclarationRewrite.copyTypeAndAddTypeAnnotations(vds.getType(), rewrite);
866
		fieldDeclaration.setType(type);
867
		fieldDeclaration.setType(type);
867
		fieldDeclaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getModifiers()));
868
		fieldDeclaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getModifiers()));
868
		return fieldDeclaration;
869
		return fieldDeclaration;
(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/sef/SelfEncapsulateFieldRefactoring.java (-3 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 93-98 Link Here
93
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
93
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
94
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
94
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
95
import org.eclipse.jdt.internal.corext.dom.Bindings;
95
import org.eclipse.jdt.internal.corext.dom.Bindings;
96
import org.eclipse.jdt.internal.corext.dom.DeclarationRewrite;
96
import org.eclipse.jdt.internal.corext.dom.DimensionRewrite;
97
import org.eclipse.jdt.internal.corext.dom.DimensionRewrite;
97
import org.eclipse.jdt.internal.corext.dom.VariableDeclarationRewrite;
98
import org.eclipse.jdt.internal.corext.dom.VariableDeclarationRewrite;
98
import org.eclipse.jdt.internal.corext.refactoring.Checks;
99
import org.eclipse.jdt.internal.corext.refactoring.Checks;
Lines 625-636 Link Here
625
		result.setName(ast.newSimpleName(fSetterName));
626
		result.setName(ast.newSimpleName(fSetterName));
626
		result.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiers()));
627
		result.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiers()));
627
		if (fSetterMustReturnValue) {
628
		if (fSetterMustReturnValue) {
628
			result.setReturnType2((Type)rewriter.createCopyTarget(type));
629
			Type copiedType= DimensionRewrite.copyTypeAndAddDimensions(type, fFieldDeclaration.extraDimensions(), rewriter);
630
			result.setReturnType2(copiedType);
629
		}
631
		}
630
		SingleVariableDeclaration param= ast.newSingleVariableDeclaration();
632
		SingleVariableDeclaration param= ast.newSingleVariableDeclaration();
631
		result.parameters().add(param);
633
		result.parameters().add(param);
632
		param.setName(ast.newSimpleName(fArgName));
634
		param.setName(ast.newSimpleName(fArgName));
633
		param.setType((Type)rewriter.createCopyTarget(type));
635
		Type copiedType= DeclarationRewrite.copyTypeAndAddTypeAnnotations(type, rewriter);
636
		param.setType(copiedType);
634
		List<Dimension> extraDimensions= DimensionRewrite.copyDimensions(fFieldDeclaration.extraDimensions(), rewriter);
637
		List<Dimension> extraDimensions= DimensionRewrite.copyDimensions(fFieldDeclaration.extraDimensions(), rewriter);
635
		param.extraDimensions().addAll(extraDimensions);
638
		param.extraDimensions().addAll(extraDimensions);
636
639
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java (-1 / +3 lines)
Lines 116-121 Link Here
116
import org.eclipse.jdt.internal.corext.dom.Bindings;
116
import org.eclipse.jdt.internal.corext.dom.Bindings;
117
import org.eclipse.jdt.internal.corext.dom.BodyDeclarationRewrite;
117
import org.eclipse.jdt.internal.corext.dom.BodyDeclarationRewrite;
118
import org.eclipse.jdt.internal.corext.dom.CodeScopeBuilder;
118
import org.eclipse.jdt.internal.corext.dom.CodeScopeBuilder;
119
import org.eclipse.jdt.internal.corext.dom.DeclarationRewrite;
119
import org.eclipse.jdt.internal.corext.dom.NecessaryParenthesesChecker;
120
import org.eclipse.jdt.internal.corext.dom.NecessaryParenthesesChecker;
120
import org.eclipse.jdt.internal.corext.dom.Selection;
121
import org.eclipse.jdt.internal.corext.dom.Selection;
121
import org.eclipse.jdt.internal.corext.dom.TypeRules;
122
import org.eclipse.jdt.internal.corext.dom.TypeRules;
Lines 318-324 Link Here
318
						UnionType newUnionType= ast.newUnionType();
319
						UnionType newUnionType= ast.newUnionType();
319
						List<Type> types= newUnionType.types();
320
						List<Type> types= newUnionType.types();
320
321
321
						types.add((Type) rewrite.createCopyTarget(type));
322
						Type copiedType= DeclarationRewrite.copyTypeAndMoveTypeAnnotations(type, rewrite, null);
323
						types.add(copiedType);
322
						for (int i= 0; i < uncaughtExceptions.length; i++) {
324
						for (int i= 0; i < uncaughtExceptions.length; i++) {
323
							ITypeBinding excBinding= uncaughtExceptions[i];
325
							ITypeBinding excBinding= uncaughtExceptions[i];
324
							Type type2= imports.addImport(excBinding, ast, importRewriteContext);
326
							Type type2= imports.addImport(excBinding, ast, importRewriteContext);
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java (-14 / +22 lines)
Lines 121-126 Link Here
121
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
121
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
122
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
122
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
123
import org.eclipse.jdt.internal.corext.dom.Bindings;
123
import org.eclipse.jdt.internal.corext.dom.Bindings;
124
import org.eclipse.jdt.internal.corext.dom.DeclarationRewrite;
124
import org.eclipse.jdt.internal.corext.dom.DimensionRewrite;
125
import org.eclipse.jdt.internal.corext.dom.DimensionRewrite;
125
import org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder;
126
import org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder;
126
import org.eclipse.jdt.internal.corext.dom.ModifierRewrite;
127
import org.eclipse.jdt.internal.corext.dom.ModifierRewrite;
Lines 951-957 Link Here
951
			VariableDeclarationExpression oldVarDecl= (VariableDeclarationExpression) fragParent;
952
			VariableDeclarationExpression oldVarDecl= (VariableDeclarationExpression) fragParent;
952
953
953
			VariableDeclarationStatement newVarDec= ast.newVariableDeclarationStatement(newFrag);
954
			VariableDeclarationStatement newVarDec= ast.newVariableDeclarationStatement(newFrag);
954
			newVarDec.setType((Type) rewrite.createCopyTarget(oldVarDecl.getType()));
955
			Type copiedTypeNode= DeclarationRewrite.copyTypeAndAddTypeAnnotations(oldVarDecl.getType(), rewrite);
956
			newVarDec.setType(copiedTypeNode);
955
			newVarDec.modifiers().addAll(ASTNodeFactory.newModifiers(ast, oldVarDecl.getModifiers()));
957
			newVarDec.modifiers().addAll(ASTNodeFactory.newModifiers(ast, oldVarDecl.getModifiers()));
956
			newStatement= newVarDec;
958
			newStatement= newVarDec;
957
		}
959
		}
Lines 1503-1509 Link Here
1503
			ASTRewrite rewrite= ASTRewrite.create(ast);
1505
			ASTRewrite rewrite= ASTRewrite.create(ast);
1504
			if (selectedMultiCatchType != null) {
1506
			if (selectedMultiCatchType != null) {
1505
				removeException(rewrite, (UnionType) type, selectedMultiCatchType);
1507
				removeException(rewrite, (UnionType) type, selectedMultiCatchType);
1506
				addExceptionToThrows(ast, methodDeclaration, rewrite, selectedMultiCatchType);
1508
				addExceptionToThrows(methodDeclaration, rewrite, selectedMultiCatchType);
1507
				String label= CorrectionMessages.QuickAssistProcessor_exceptiontothrows_description;
1509
				String label= CorrectionMessages.QuickAssistProcessor_exceptiontothrows_description;
1508
				ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REPLACE_EXCEPTION_WITH_THROWS, image);
1510
				ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REPLACE_EXCEPTION_WITH_THROWS, image);
1509
				resultingCollections.add(proposal);
1511
				resultingCollections.add(proposal);
Lines 1515-1524 Link Here
1515
					for (Type elementType : types) {
1517
					for (Type elementType : types) {
1516
						if (!(elementType instanceof SimpleType || elementType instanceof NameQualifiedType))
1518
						if (!(elementType instanceof SimpleType || elementType instanceof NameQualifiedType))
1517
							return false;
1519
							return false;
1518
						addExceptionToThrows(ast, methodDeclaration, rewrite, elementType);
1520
						addExceptionToThrows(methodDeclaration, rewrite, elementType);
1519
					}
1521
					}
1520
				} else {
1522
				} else {
1521
					addExceptionToThrows(ast, methodDeclaration, rewrite, type);
1523
					addExceptionToThrows(methodDeclaration, rewrite, type);
1522
				}
1524
				}
1523
				String label= CorrectionMessages.QuickAssistProcessor_catchclausetothrows_description;
1525
				String label= CorrectionMessages.QuickAssistProcessor_catchclausetothrows_description;
1524
				ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REPLACE_CATCH_CLAUSE_WITH_THROWS, image);
1526
				ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REPLACE_CATCH_CLAUSE_WITH_THROWS, image);
Lines 1544-1549 Link Here
1544
	}
1546
	}
1545
1547
1546
	private static void removeException(ASTRewrite rewrite, UnionType unionType, Type exception) {
1548
	private static void removeException(ASTRewrite rewrite, UnionType unionType, Type exception) {
1549
		DeclarationRewrite.removeTypeAnnotationsFromDeclaration(exception, rewrite, null);
1547
		ListRewrite listRewrite= rewrite.getListRewrite(unionType, UnionType.TYPES_PROPERTY);
1550
		ListRewrite listRewrite= rewrite.getListRewrite(unionType, UnionType.TYPES_PROPERTY);
1548
		List<Type> types= unionType.types();
1551
		List<Type> types= unionType.types();
1549
		for (Iterator<Type> iterator= types.iterator(); iterator.hasNext();) {
1552
		for (Iterator<Type> iterator= types.iterator(); iterator.hasNext();) {
Lines 1554-1563 Link Here
1554
		}
1557
		}
1555
	}
1558
	}
1556
1559
1557
	private static void addExceptionToThrows(AST ast, MethodDeclaration methodDeclaration, ASTRewrite rewrite, Type type2) {
1560
	private static void addExceptionToThrows(MethodDeclaration methodDeclaration, ASTRewrite rewrite, Type type2) {
1558
		ITypeBinding binding= type2.resolveBinding();
1561
		ITypeBinding binding= type2.resolveBinding();
1559
		if (binding == null || isNotYetThrown(binding, methodDeclaration.thrownExceptionTypes())) {
1562
		if (binding == null || isNotYetThrown(binding, methodDeclaration.thrownExceptionTypes())) {
1560
			Type newType= (Type) ASTNode.copySubtree(ast, type2);
1563
			Type newType= DeclarationRewrite.copyTypeAndAddTypeAnnotations(type2, rewrite);
1561
1564
1562
			ListRewrite listRewriter= rewrite.getListRewrite(methodDeclaration, MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY);
1565
			ListRewrite listRewriter= rewrite.getListRewrite(methodDeclaration, MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY);
1563
			listRewriter.insertLast(newType, null);
1566
			listRewriter.insertLast(newType, null);
Lines 1657-1664 Link Here
1657
		List<Type> types= newUnionType.types();
1660
		List<Type> types= newUnionType.types();
1658
		for (int i= 0; i < coveredNodes.size(); i++) {
1661
		for (int i= 0; i < coveredNodes.size(); i++) {
1659
			ASTNode typeNode= coveredNodes.get(i);
1662
			ASTNode typeNode= coveredNodes.get(i);
1660
			types.add((Type) rewrite.createCopyTarget(typeNode));
1663
			if (typeNode instanceof Type) {
1661
			rewrite.remove(typeNode, null);
1664
				Type copiedTypeNode= DeclarationRewrite.copyTypeAndMoveTypeAnnotations((Type) typeNode, rewrite, null);				
1665
				types.add(copiedTypeNode);
1666
				rewrite.remove(typeNode, null);
1667
			}
1662
		}
1668
		}
1663
		newSingleVariableDeclaration.setType(newUnionType);
1669
		newSingleVariableDeclaration.setType(newUnionType);
1664
		newSingleVariableDeclaration.setName((SimpleName) rewrite.createCopyTarget(catchClause.getException().getName()));
1670
		newSingleVariableDeclaration.setName((SimpleName) rewrite.createCopyTarget(catchClause.getException().getName()));
Lines 1747-1756 Link Here
1747
			if (type instanceof UnionType) {
1753
			if (type instanceof UnionType) {
1748
				List<Type> types2= ((UnionType) type).types();
1754
				List<Type> types2= ((UnionType) type).types();
1749
				for (Iterator<Type> iterator2= types2.iterator(); iterator2.hasNext();) {
1755
				for (Iterator<Type> iterator2= types2.iterator(); iterator2.hasNext();) {
1750
					types.add((Type) rewrite.createCopyTarget(iterator2.next()));
1756
					Type copiedTypeNode= DeclarationRewrite.copyTypeAndMoveTypeAnnotations(iterator2.next(), rewrite, null);
1757
					types.add(copiedTypeNode);
1751
				}
1758
				}
1752
			} else {
1759
			} else {
1753
				types.add((Type) rewrite.createCopyTarget(type));
1760
				Type copiedTypeNode= DeclarationRewrite.copyTypeAndMoveTypeAnnotations(type, rewrite, null);
1761
				types.add(copiedTypeNode);
1754
			}
1762
			}
1755
		}
1763
		}
1756
1764
Lines 1817-1823 Link Here
1817
			CatchClause newCatchClause= ast.newCatchClause();
1825
			CatchClause newCatchClause= ast.newCatchClause();
1818
1826
1819
			SingleVariableDeclaration newSingleVariableDeclaration= ast.newSingleVariableDeclaration();
1827
			SingleVariableDeclaration newSingleVariableDeclaration= ast.newSingleVariableDeclaration();
1820
			newSingleVariableDeclaration.setType((Type) rewrite.createCopyTarget(type2));
1828
			Type copiedTypeNode= DeclarationRewrite.copyTypeAndMoveTypeAnnotations(type2, rewrite, null);				
1829
			newSingleVariableDeclaration.setType(copiedTypeNode);
1821
			newSingleVariableDeclaration.setName((SimpleName) rewrite.createCopyTarget(singleVariableDeclaration.getName()));
1830
			newSingleVariableDeclaration.setName((SimpleName) rewrite.createCopyTarget(singleVariableDeclaration.getName()));
1822
			newCatchClause.setException(newSingleVariableDeclaration);
1831
			newCatchClause.setException(newSingleVariableDeclaration);
1823
			setCatchClauseBody(newCatchClause, rewrite, catchClause);
1832
			setCatchClauseBody(newCatchClause, rewrite, catchClause);
Lines 2585-2593 Link Here
2585
				VariableDeclarationStatement varDeclaration= ast.newVariableDeclarationStatement(varFragment);
2594
				VariableDeclarationStatement varDeclaration= ast.newVariableDeclarationStatement(varFragment);
2586
				Type varType;
2595
				Type varType;
2587
				if (initializerIsArray) {
2596
				if (initializerIsArray) {
2588
					ArrayType varArrayType= (ArrayType) DimensionRewrite.copyTypeAndAddDimensions(parameter.getType(), parameter.extraDimensions(), rewrite);
2597
					Type copiedType= DimensionRewrite.copyTypeAndAddDimensions(parameter.getType(), parameter.extraDimensions(), rewrite);
2589
					varArrayType.dimensions().add(0, ast.newDimension());
2598
					varType= ASTNodeFactory.newArrayType(copiedType);
2590
					varType= varArrayType;
2591
				} else {
2599
				} else {
2592
					ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot());
2600
					ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot());
2593
					ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(node, imports);
2601
					ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(node, imports);

Return to bug 426967