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

Collapse All | Expand All

(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (+4 lines)
Lines 1912-1917 Link Here
1912
						this.options.put(
1912
						this.options.put(
1913
								CompilerOptions.OPTION_ReportUnusedLabel,
1913
								CompilerOptions.OPTION_ReportUnusedLabel,
1914
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1914
								isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1915
					} else if (token.equals("paramAssign")) { //$NON-NLS-1$
1916
						this.options.put(
1917
							CompilerOptions.OPTION_ReportParameterAssignment,
1918
							isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1915
					} else {
1919
					} else {
1916
						throw new InvalidInputException(Main.bind("configure.invalidWarning", token)); //$NON-NLS-1$
1920
						throw new InvalidInputException(Main.bind("configure.invalidWarning", token)); //$NON-NLS-1$
1917
					}
1921
					}
(-)batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (+1 lines)
Lines 153-158 Link Here
153
\      noEffectAssign     + assignment without effect\n\
153
\      noEffectAssign     + assignment without effect\n\
154
\      null                 missing or redundant null check\n\
154
\      null                 missing or redundant null check\n\
155
\      over-ann             missing @Override annotation\n\
155
\      over-ann             missing @Override annotation\n\
156
\      paramAssign          assignment to a parameter\n\
156
\      pkgDefaultMethod   + attempt to override package-default method\n\
157
\      pkgDefaultMethod   + attempt to override package-default method\n\
157
\      raw                  usage of raw type\n\
158
\      raw                  usage of raw type\n\
158
\      semicolon            unnecessary semicolon, empty statement\n\
159
\      semicolon            unnecessary semicolon, empty statement\n\
(-)compiler/org/eclipse/jdt/core/compiler/IProblem.java (-1 / +10 lines)
Lines 72-77 Link Here
72
 *     IBM Corporation - added the following constants
72
 *     IBM Corporation - added the following constants
73
 *								   IllegalUsageOfQualifiedTypeReference
73
 *								   IllegalUsageOfQualifiedTypeReference
74
 *								   InvalidDigit
74
 *								   InvalidDigit
75
 *     IBM Corporation - added the following constants
76
 *								   ParameterAssignment
75
 *******************************************************************************/
77
 *******************************************************************************/
76
package org.eclipse.jdt.core.compiler;
78
package org.eclipse.jdt.core.compiler;
77
 
79
 
Lines 286-292 Link Here
286
	int TooManyArrayDimensions = Internal + 68;
288
	int TooManyArrayDimensions = Internal + 68;
287
	/** @since 2.1 */
289
	/** @since 2.1 */
288
	int BytecodeExceeds64KLimitForConstructor = Internal + 69;
290
	int BytecodeExceeds64KLimitForConstructor = Internal + 69;
289
291
	/** @since 3.2 */
292
	int ParameterAssignment = Internal + 860;
293
	// REVIEW argument would be more homogeneous with existing code, but JLS 
294
	//        puts a clear emphasis on parameter -- see p.211 for 
295
	//        parameter/argument disc.
296
	//        examples of existing code: RedefinedArgument, ArgumentIsNeverUsed,
297
	//        ArgumentHidingField...
298
	
290
	// fields
299
	// fields
291
	int UndefinedField = FieldRelated + 70;
300
	int UndefinedField = FieldRelated + 70;
292
	int NotVisibleField = FieldRelated + 71;
301
	int NotVisibleField = FieldRelated + 71;
(-)compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java (+3 lines)
Lines 119-124 Link Here
119
						currentScope.problemReporter().cannotAssignToFinalOuterLocal(localBinding, this);
119
						currentScope.problemReporter().cannotAssignToFinalOuterLocal(localBinding, this);
120
					}
120
					}
121
				}
121
				}
122
				else /* avoid double diagnostic */ if (localBinding.isArgument) {
123
					currentScope.problemReporter().parameterAssignment(localBinding, this);
124
				}
122
				flowInfo.markAsDefinitelyAssigned(localBinding);
125
				flowInfo.markAsDefinitelyAssigned(localBinding);
123
		}
126
		}
124
		manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo);
127
		manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo);
(-)compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java (-1 / +13 lines)
Lines 103-108 Link Here
103
	public static final String OPTION_ReportUnhandledWarningToken =  "org.eclipse.jdt.core.compiler.problem.unhandledWarningToken"; //$NON-NLS-1$
103
	public static final String OPTION_ReportUnhandledWarningToken =  "org.eclipse.jdt.core.compiler.problem.unhandledWarningToken"; //$NON-NLS-1$
104
	public static final String OPTION_ReportUnusedLabel =  "org.eclipse.jdt.core.compiler.problem.unusedLabel"; //$NON-NLS-1$
104
	public static final String OPTION_ReportUnusedLabel =  "org.eclipse.jdt.core.compiler.problem.unusedLabel"; //$NON-NLS-1$
105
	public static final String OPTION_FatalOptionalError =  "org.eclipse.jdt.core.compiler.problem.fatalOptionalError"; //$NON-NLS-1$
105
	public static final String OPTION_FatalOptionalError =  "org.eclipse.jdt.core.compiler.problem.fatalOptionalError"; //$NON-NLS-1$
106
	public static final String OPTION_ReportParameterAssignment =  "org.eclipse.jdt.core.compiler.problem.parameterAssignment"; //$NON-NLS-1$
106
	
107
	
107
	// Backward compatibility
108
	// Backward compatibility
108
	public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$
109
	public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$
Lines 185-190 Link Here
185
	public static final long UnhandledWarningToken = ASTNode.Bit45L;
186
	public static final long UnhandledWarningToken = ASTNode.Bit45L;
186
	public static final long RawTypeReference = ASTNode.Bit46L;
187
	public static final long RawTypeReference = ASTNode.Bit46L;
187
	public static final long UnusedLabel = ASTNode.Bit47L;
188
	public static final long UnusedLabel = ASTNode.Bit47L;
189
	public static final long ParameterAssignment = ASTNode.Bit48L;
188
	
190
	
189
	// Default severity level for handlers
191
	// Default severity level for handlers
190
	public long errorThreshold = 0;
192
	public long errorThreshold = 0;
Lines 393-398 Link Here
393
		optionsMap.put(OPTION_ReportNullReference, getSeverityString(NullReference));
395
		optionsMap.put(OPTION_ReportNullReference, getSeverityString(NullReference));
394
		optionsMap.put(OPTION_SuppressWarnings, this.suppressWarnings ? ENABLED : DISABLED); 
396
		optionsMap.put(OPTION_SuppressWarnings, this.suppressWarnings ? ENABLED : DISABLED); 
395
		optionsMap.put(OPTION_ReportUnhandledWarningToken, getSeverityString(UnhandledWarningToken));
397
		optionsMap.put(OPTION_ReportUnhandledWarningToken, getSeverityString(UnhandledWarningToken));
398
		optionsMap.put(OPTION_ReportParameterAssignment, getSeverityString(ParameterAssignment));
396
		return optionsMap;		
399
		return optionsMap;		
397
	}
400
	}
398
	
401
	
Lines 633-639 Link Here
633
		if ((optionValue = optionsMap.get(OPTION_ReportIncompleteEnumSwitch)) != null) updateSeverity(IncompleteEnumSwitch, optionValue);
636
		if ((optionValue = optionsMap.get(OPTION_ReportIncompleteEnumSwitch)) != null) updateSeverity(IncompleteEnumSwitch, optionValue);
634
		if ((optionValue = optionsMap.get(OPTION_ReportUnhandledWarningToken)) != null) updateSeverity(UnhandledWarningToken, optionValue);
637
		if ((optionValue = optionsMap.get(OPTION_ReportUnhandledWarningToken)) != null) updateSeverity(UnhandledWarningToken, optionValue);
635
		if ((optionValue = optionsMap.get(OPTION_ReportUnusedLabel)) != null) updateSeverity(UnusedLabel, optionValue);
638
		if ((optionValue = optionsMap.get(OPTION_ReportUnusedLabel)) != null) updateSeverity(UnusedLabel, optionValue);
636
				
639
		if ((optionValue = optionsMap.get(OPTION_ReportParameterAssignment)) != null) updateSeverity(ParameterAssignment, optionValue);
640
637
		// Javadoc options
641
		// Javadoc options
638
		if ((optionValue = optionsMap.get(OPTION_DocCommentSupport)) != null) {
642
		if ((optionValue = optionsMap.get(OPTION_DocCommentSupport)) != null) {
639
			if (ENABLED.equals(optionValue)) {
643
			if (ENABLED.equals(optionValue)) {
Lines 798-803 Link Here
798
		buf.append("\n\t- unhandled warning token: ").append(getSeverityString(UnhandledWarningToken)); //$NON-NLS-1$
802
		buf.append("\n\t- unhandled warning token: ").append(getSeverityString(UnhandledWarningToken)); //$NON-NLS-1$
799
		buf.append("\n\t- unused label: ").append(getSeverityString(UnusedLabel)); //$NON-NLS-1$
803
		buf.append("\n\t- unused label: ").append(getSeverityString(UnusedLabel)); //$NON-NLS-1$
800
		buf.append("\n\t- treat optional error as fatal: ").append(this.treatOptionalErrorAsFatal ? ENABLED : DISABLED); //$NON-NLS-1$
804
		buf.append("\n\t- treat optional error as fatal: ").append(this.treatOptionalErrorAsFatal ? ENABLED : DISABLED); //$NON-NLS-1$
805
		buf.append("\n\t- parameter assignment: ").append(getSeverityString(ParameterAssignment)); //$NON-NLS-1$
801
		return buf.toString();
806
		return buf.toString();
802
	}
807
	}
803
808
Lines 898-903 Link Here
898
			OPTION_ReportUnusedPrivateMember,
903
			OPTION_ReportUnusedPrivateMember,
899
			OPTION_ReportVarargsArgumentNeedCast,
904
			OPTION_ReportVarargsArgumentNeedCast,
900
			OPTION_ReportUnhandledWarningToken,
905
			OPTION_ReportUnhandledWarningToken,
906
			OPTION_ReportParameterAssignment,
901
		};
907
		};
902
		return result;
908
		return result;
903
	}
909
	}
Lines 949-954 Link Here
949
					return "unchecked"; //$NON-NLS-1$
955
					return "unchecked"; //$NON-NLS-1$
950
				case (int) UnusedLabel:
956
				case (int) UnusedLabel:
951
					return "unused"; //$NON-NLS-1$
957
					return "unused"; //$NON-NLS-1$
958
				case (int) (ParameterAssignment >>> 32) :
959
					return "paramAssign"; //$NON-NLS-1$
952
			}
960
			}
953
		}
961
		}
954
		return null;
962
		return null;
Lines 985-990 Link Here
985
				if ("nls".equals(warningToken)) //$NON-NLS-1$
993
				if ("nls".equals(warningToken)) //$NON-NLS-1$
986
					return NonExternalizedString;
994
					return NonExternalizedString;
987
				break;
995
				break;
996
			case 'p' :
997
				if ("paramAssign".equals(warningToken)) //$NON-NLS-1$
998
					return ParameterAssignment;
999
				break;
988
			case 's' :
1000
			case 's' :
989
				if ("serial".equals(warningToken)) //$NON-NLS-1$
1001
				if ("serial".equals(warningToken)) //$NON-NLS-1$
990
					return MissingSerialVersion;
1002
					return MissingSerialVersion;
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (+12 lines)
Lines 1461-1466 Link Here
1461
1461
1462
		case IProblem.JavadocMissing:
1462
		case IProblem.JavadocMissing:
1463
			return CompilerOptions.MissingJavadocComments;
1463
			return CompilerOptions.MissingJavadocComments;
1464
1465
		case IProblem.ParameterAssignment:
1466
			return CompilerOptions.ParameterAssignment;
1464
	}
1467
	}
1465
	return 0;
1468
	return 0;
1466
}
1469
}
Lines 4476-4481 Link Here
4476
		compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceStart,
4479
		compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceStart,
4477
		compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceEnd);
4480
		compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceEnd);
4478
}
4481
}
4482
public void parameterAssignment(LocalVariableBinding local, ASTNode location) {
4483
	String[] arguments = new String[] { new String(local.readableName())};
4484
	this.handle(
4485
		IProblem.ParameterAssignment,
4486
		arguments,
4487
		arguments,
4488
		location.sourceStart,
4489
		location.sourceEnd);
4490
}
4479
private String parameterBoundAsString(TypeVariableBinding typeVariable, boolean makeShort) {
4491
private String parameterBoundAsString(TypeVariableBinding typeVariable, boolean makeShort) {
4480
    StringBuffer nameBuffer = new StringBuffer(10);
4492
    StringBuffer nameBuffer = new StringBuffer(10);
4481
    if (typeVariable.firstBound == typeVariable.superclass) {
4493
    if (typeVariable.firstBound == typeVariable.superclass) {
(-)compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties (+2 lines)
Lines 557-559 Link Here
557
857 = Incorrect number of type arguments for generic constructor <{3}>{0}({1}) of type {2}; it cannot be parameterized with arguments <{4}>
557
857 = Incorrect number of type arguments for generic constructor <{3}>{0}({1}) of type {2}; it cannot be parameterized with arguments <{4}>
558
858 = The parameterized constructor <{3}>{0}({1}) of type {2} is not applicable for the arguments ({4})
558
858 = The parameterized constructor <{3}>{0}({1}) of type {2} is not applicable for the arguments ({4})
559
859 = The constructor {0}({1}) of raw type {2} is no longer generic; it cannot be parameterized with arguments <{3}>
559
859 = The constructor {0}({1}) of raw type {2} is no longer generic; it cannot be parameterized with arguments <{3}>
560
561
860 = The parameter {0} should not be assigned
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java (+98 lines)
Lines 1472-1477 Link Here
1472
		},
1472
		},
1473
		"a=11b=1");
1473
		"a=11b=1");
1474
}
1474
}
1475
// warn upon parameter assignment
1476
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773
1477
public void test040() {
1478
	Map options = getCompilerOptions();
1479
	options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR);
1480
	this.runNegativeTest(
1481
		new String[] {
1482
			"X.java",
1483
			"public class X {\n" + 
1484
			"  void foo(boolean b) {\n" + 
1485
			"    b = false;\n" + 
1486
			"  }\n" + 
1487
			"}\n",
1488
		},
1489
		"----------\n" + 
1490
		"1. ERROR in X.java (at line 3)\n" + 
1491
		"	b = false;\n" + 
1492
		"	^\n" + 
1493
		"The parameter b should not be assigned\n" + 
1494
		"----------\n",
1495
		null, true, options);
1496
}
1497
// warn upon parameter assignment
1498
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773
1499
// diagnose within fake reachable code
1500
public void test041() {
1501
	Map options = getCompilerOptions();
1502
	options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR);
1503
	this.runNegativeTest(
1504
		new String[] {
1505
			"X.java",
1506
			"public class X {\n" + 
1507
			"  void foo(boolean b) {\n" + 
1508
			"    if (false) {\n" + 
1509
			"      b = false;\n" + 
1510
			"    }\n" + 
1511
			"  }\n" + 
1512
			"}\n",
1513
		},
1514
		"----------\n" + 
1515
		"1. ERROR in X.java (at line 4)\n" + 
1516
		"	b = false;\n" + 
1517
		"	^\n" + 
1518
		"The parameter b should not be assigned\n" + 
1519
		"----------\n",
1520
		null, true, options);
1521
}
1522
// warn upon parameter assignment
1523
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773
1524
// diagnose within fake reachable code
1525
public void test042() {
1526
	Map options = getCompilerOptions();
1527
	options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR);
1528
	this.runNegativeTest(
1529
		new String[] {
1530
			"X.java",
1531
			"public class X {\n" + 
1532
			"  void foo(boolean b) {\n" + 
1533
			"    if (true) {\n" + 
1534
			"      return;\n" + 
1535
			"    }\n" + 
1536
			"    b = false;\n" + 
1537
			"  }\n" + 
1538
			"}\n",
1539
		},
1540
		"----------\n" + 
1541
		"1. ERROR in X.java (at line 6)\n" + 
1542
		"	b = false;\n" + 
1543
		"	^\n" + 
1544
		"The parameter b should not be assigned\n" + 
1545
		"----------\n",
1546
		null, true, options);
1547
}
1548
// warn upon parameter assignment
1549
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773
1550
// we only show the 'assignment to final' error here
1551
public void test043() {
1552
	Map options = getCompilerOptions();
1553
	options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR);
1554
	this.runNegativeTest(
1555
		new String[] {
1556
			"X.java",
1557
			"public class X {\n" + 
1558
			"  void foo(final boolean b) {\n" + 
1559
			"    if (false) {\n" + 
1560
			"      b = false;\n" + 
1561
			"    }\n" + 
1562
			"  }\n" + 
1563
			"}\n",
1564
		},
1565
		"----------\n" + 
1566
		"1. ERROR in X.java (at line 4)\n" + 
1567
		"	b = false;\n" + 
1568
		"	^\n" + 
1569
		"The final local variable b cannot be assigned. It must be blank and not using a compound assignment\n" + 
1570
		"----------\n",
1571
		null, true, options);
1572
}
1475
public static Class testClass() {
1573
public static Class testClass() {
1476
	return AssignmentTest.class;
1574
	return AssignmentTest.class;
1477
}
1575
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (+35 lines)
Lines 2035-2040 Link Here
2035
		System.setProperty("user.dir", javaUserDir);
2035
		System.setProperty("user.dir", javaUserDir);
2036
	}
2036
	}
2037
}
2037
}
2038
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773
2039
public void test036() {
2040
	this.runNegativeTest(
2041
		new String[] {
2042
			"X.java",
2043
			"public class X {\n" + 
2044
			"	 void foo(int i, final int j) {\n" + 
2045
			"		 i =  0; // warning\n" + 
2046
			"		 j =  0; // error\n" + 
2047
			"	 }\n" + 
2048
			"}\n",
2049
		},
2050
		    "\"" + OUTPUT_DIR +  File.separator + "X.java\""
2051
		      + " -1.5 "
2052
		      + " -cp \"" + OUTPUT_DIR + "\""
2053
		      + " -warn:+paramAssign"
2054
		      + " -proceedOnError"
2055
		      + " -d \"" + OUTPUT_DIR + "\"",
2056
		    "", 
2057
				"----------\n" + 
2058
				"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---" +  File.separator + "X.java\n" + 
2059
				" (at line 3)\n" + 
2060
				"	i =  0; // warning\n" + 
2061
				"	^\n" + 
2062
				"The parameter i should not be assigned\n" + 
2063
				"----------\n" + 
2064
				"2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---" +  File.separator + "X.java\n" + 
2065
				" (at line 4)\n" + 
2066
				"	j =  0; // error\n" + 
2067
				"	^\n" + 
2068
				"The final local variable j cannot be assigned. It must be blank and not using a compound assignment\n" + 
2069
				"----------\n" + 
2070
				"2 problems (1 error, 1 warning)",
2071
		    true);
2072
}
2038
public static Class testClass() {
2073
public static Class testClass() {
2039
	return BatchCompilerTest.class;
2074
	return BatchCompilerTest.class;
2040
}
2075
}

Return to bug 53773