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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java (-1 / +84 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
12
13
import java.util.HashMap;
13
import java.util.Map;
14
import java.util.Map;
14
15
15
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
16
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
Lines 26-33 Link Here
26
	Map options = super.getCompilerOptions();
27
	Map options = super.getCompilerOptions();
27
	options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR);
28
	options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR);
28
	options.put(CompilerOptions.OPTION_ReportNoEffectAssignment, CompilerOptions.ERROR);
29
	options.put(CompilerOptions.OPTION_ReportNoEffectAssignment, CompilerOptions.ERROR);
30
	options.put(CompilerOptions.OPTION_ReportUnhandledWarningToken, CompilerOptions.ERROR);
29
	return options;
31
	return options;
30
}
32
}
33
	// Static initializer to specify tests subset using TESTS_* static variables
34
	// All specified tests which does not belong to the class are skipped...
35
	static {
36
//		TESTS_NAMES = new String[] { "test000" };
37
//		TESTS_NUMBERS = new int[] { 38 };
38
//		TESTS_RANGE = new int[] { 38, -1 };
39
	}
40
	
31
public static Test suite() {
41
public static Test suite() {
32
42
33
	if (false) {
43
	if (false) {
Lines 37-45 Link Here
37
		ts.addTest(new AssignmentTest("test221"));
47
		ts.addTest(new AssignmentTest("test221"));
38
		return new RegressionTestSetup(ts, COMPLIANCE_1_4);
48
		return new RegressionTestSetup(ts, COMPLIANCE_1_4);
39
	}
49
	}
40
	return setupSuite(testClass());
50
	return buildTestSuite(testClass());
41
}
51
}
42
52
53
43
/*
54
/*
44
 * no effect assignment bug
55
 * no effect assignment bug
45
 * http://bugs.eclipse.org/bugs/show_bug.cgi?id=27235
56
 * http://bugs.eclipse.org/bugs/show_bug.cgi?id=27235
Lines 1391-1396 Link Here
1391
		},
1402
		},
1392
		"");
1403
		"");
1393
}
1404
}
1405
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773
1406
public void test038() {
1407
	Map options = new HashMap(1);
1408
	options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.WARNING);
1409
	this.runNegativeTest(
1410
		new String[] {
1411
			"X.java",
1412
			"public class X {\n" + 
1413
			"	 void foo(final int i, int j) {\n" + 
1414
			"		 i =  0; // error (only) on this one\n" + 
1415
			"		 j =  0; // warning on this one\n" + 
1416
			"	 }\n" + 
1417
			"}\n",
1418
		},
1419
		"----------\n" + 
1420
		"1. ERROR in X.java (at line 3)\n" + 
1421
		"	i =  0; // error (only) on this one\n" + 
1422
		"	^\n" + 
1423
		"The final local variable i cannot be assigned. It must be blank and not using a compound assignment\n" + 
1424
		"----------\n" + 
1425
		"2. WARNING in X.java (at line 4)\n" + 
1426
		"	j =  0; // warning on this one\n" + 
1427
		"	^\n" + 
1428
		"The parameter j should not be assigned\n" + 
1429
		"----------\n", null, true, options);
1430
}
1431
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773
1432
public void test039() {
1433
	Map options = new HashMap(1);
1434
	options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.WARNING);
1435
	// toggle to 1.5 to use annotations
1436
	options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
1437
	options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);	
1438
	this.runNegativeTest(
1439
		new String[] {
1440
			"X.java",
1441
			"public class X {\n" + 
1442
			"	 @SuppressWarnings(\"parameter-assignment\")\n" + 
1443
			"	 void foo(int i) {\n" + 
1444
			"		 i =  0; // keep quiet\n" + 
1445
			"		 zork++; // error\n" + 
1446
			"	 }\n" + 
1447
			"}\n",
1448
		},
1449
		"----------\n" + 
1450
		"1. ERROR in X.java (at line 5)\n" + 
1451
		"	zork++; // error\n" + 
1452
		"	^^^^\n" + 
1453
		"zork cannot be resolved\n" + 
1454
		"----------\n", null, true, options);
1455
}
1456
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773
1457
public void test040() {
1458
	Map options = new HashMap(1);
1459
	options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.WARNING);
1460
	this.runNegativeTest(
1461
		new String[] {
1462
			"X.java",
1463
			"public class X {\n" + 
1464
			"	 void foo(int i) {\n" + 
1465
			"		 int i; // error: hide parameter\n" + 
1466
			"		 i =  0; // ok: local assigned\n" + 
1467
			"	 }\n" + 
1468
			"}\n",
1469
		},
1470
		"----------\n" + 
1471
		"1. ERROR in X.java (at line 3)\n" + 
1472
		"	int i; // error: hide parameter\n" + 
1473
		"	    ^\n" + 
1474
		"Duplicate local variable i\n" + 
1475
		"----------\n", null, true, options);
1476
}
1394
public static Class testClass() {
1477
public static Class testClass() {
1395
	return AssignmentTest.class;
1478
	return AssignmentTest.class;
1396
}
1479
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (+36 lines)
Lines 1991-1996 Link Here
1991
        "",
1991
        "",
1992
        true);
1992
        true);
1993
}
1993
}
1994
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773
1995
public void test034() {
1996
	this.runNegativeTest(
1997
		new String[] {
1998
			"X.java",
1999
			"public class X {\n" + 
2000
			"	 void foo(int i, final int j) {\n" + 
2001
			"		 i =  0; // warning\n" + 
2002
			"		 j =  0; // error\n" + 
2003
			"	 }\n" + 
2004
			"}\n",
2005
		},
2006
		    "\"" + OUTPUT_DIR +  File.separator + "X.java\""
2007
		      + " -1.5 "
2008
		      + " -cp \"" + OUTPUT_DIR + "\""
2009
		      + " -warn:+parameter-assignment"
2010
		      + " -proceedOnError"
2011
		      + " -d \"" + OUTPUT_DIR + "\"",
2012
		    "", 
2013
				"----------\n" + 
2014
				"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java\n" + 
2015
				" (at line 3)\n" + 
2016
				"	i =  0; // warning\n" + 
2017
				"	^\n" + 
2018
				"The parameter i should not be assigned\n" + 
2019
				"----------\n" + 
2020
				"----------\n" + 
2021
				"2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java\n" + 
2022
				" (at line 4)\n" + 
2023
				"	j =  0; // error\n" + 
2024
				"	^\n" + 
2025
				"The final local variable j cannot be assigned. It must be blank and not using a compound assignment\n" + 
2026
				"----------\n" + 
2027
				"2 problems (1 error, 1 warning)",
2028
		    true);
2029
}
1994
public static Class testClass() {
2030
public static Class testClass() {
1995
	return BatchCompilerTest.class;
2031
	return BatchCompilerTest.class;
1996
}
2032
}

Return to bug 53773