View | Details | Raw Unified | Return to bug 38751
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (+2 lines)
Lines 1654-1659 Link Here
1654
        "      finalBound           type parameter with final bound\n" +
1654
        "      finalBound           type parameter with final bound\n" +
1655
        "      finally            + finally block not completing normally\n" +
1655
        "      finally            + finally block not completing normally\n" +
1656
        "      forbidden          + use of types matching a forbidden access rule\n" +
1656
        "      forbidden          + use of types matching a forbidden access rule\n" +
1657
        "      hashCode               missing hashCode() method when overriding equals()\n" + 
1657
        "      hiding               macro for fieldHiding, localHiding, typeHiding and\n" +
1658
        "      hiding               macro for fieldHiding, localHiding, typeHiding and\n" +
1658
        "                           maskedCatchBlock\n" +
1659
        "                           maskedCatchBlock\n" +
1659
        "      incomplete-switch    same as enumSwitch\n" +
1660
        "      incomplete-switch    same as enumSwitch\n" +
Lines 1799-1804 Link Here
1799
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.localVariableHiding\" value=\"ignore\"/>\n" +
1800
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.localVariableHiding\" value=\"ignore\"/>\n" +
1800
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.methodWithConstructorName\" value=\"warning\"/>\n" +
1801
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.methodWithConstructorName\" value=\"warning\"/>\n" +
1801
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation\" value=\"ignore\"/>\n" +
1802
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation\" value=\"ignore\"/>\n" +
1803
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod\" value=\"ignore\"/>\n" +
1802
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingJavadocComments\" value=\"ignore\"/>\n" +
1804
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingJavadocComments\" value=\"ignore\"/>\n" +
1803
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding\" value=\"disabled\"/>\n" +
1805
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding\" value=\"disabled\"/>\n" +
1804
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility\" value=\"public\"/>\n" +
1806
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility\" value=\"public\"/>\n" +
(-)src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java (+43 lines)
Lines 8929-8932 Link Here
8929
		"----------\n"
8929
		"----------\n"
8930
	);
8930
	);
8931
}
8931
}
8932
8933
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38751
8934
public void test175() {
8935
	Map options = getCompilerOptions();
8936
	options.put(CompilerOptions.OPTION_ReportMissingHashCodeMethod, CompilerOptions.WARNING);
8937
	this.runNegativeTest(
8938
		new String[] {
8939
			"A.java",
8940
			"class A {\n" +
8941
			"	@Override public boolean equals(Object o) { return true; }\n" +
8942
			"}"
8943
		},
8944
		"----------\n" + 
8945
		"1. WARNING in A.java (at line 1)\n" + 
8946
		"	class A {\n" + 
8947
		"	      ^\n" + 
8948
		"The type A should also implement hashcode() since it overrides Object.equals()\n" + 
8949
		"----------\n",
8950
	null,
8951
	false,
8952
	options);
8953
}
8954
8955
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38751
8956
public void test176() {
8957
	Map options = getCompilerOptions();
8958
	options.put(CompilerOptions.OPTION_ReportMissingHashCodeMethod, CompilerOptions.WARNING);
8959
	this.runNegativeTest(
8960
		new String[] {
8961
			"A.java",
8962
			"class A {\n" +
8963
			"	@Override public boolean equals(Object o) { return true; }\n" +
8964
			"	@Override public int hashCode() { return 1; }\n" +
8965
			"}\n" +
8966
			"class B extends A {\n" +
8967
			"	@Override public boolean equals(Object o) { return false; }\n" +
8968
			"}"
8969
		},
8970
		"",
8971
	null,
8972
	false,
8973
	options);
8974
}
8932
}
8975
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java (+2 lines)
Lines 852-857 Link Here
852
		expectedProblemAttributes.put("ExternalProblemNotFixable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
852
		expectedProblemAttributes.put("ExternalProblemNotFixable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
853
		expectedProblemAttributes.put("ExternalProblemFixable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
853
		expectedProblemAttributes.put("ExternalProblemFixable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
854
		expectedProblemAttributes.put("MissingSynchronizedModifierInInheritedMethod", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
854
		expectedProblemAttributes.put("MissingSynchronizedModifierInInheritedMethod", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
855
		expectedProblemAttributes.put("ShouldImplementHashcode", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
855
		StringBuffer failures = new StringBuffer();
856
		StringBuffer failures = new StringBuffer();
856
		Field[] fields = (iProblemClass = IProblem.class).getFields();
857
		Field[] fields = (iProblemClass = IProblem.class).getFields();
857
		boolean watchInternalCategory = false, printHeader = true;
858
		boolean watchInternalCategory = false, printHeader = true;
Lines 2002-2007 Link Here
2002
		expectedProblemAttributes.put("ExternalProblemFixable", SKIP);
2003
		expectedProblemAttributes.put("ExternalProblemFixable", SKIP);
2003
		expectedProblemAttributes.put("ComparingIdentical", new ProblemAttributes(JavaCore.COMPILER_PB_COMPARING_IDENTICAL));
2004
		expectedProblemAttributes.put("ComparingIdentical", new ProblemAttributes(JavaCore.COMPILER_PB_COMPARING_IDENTICAL));
2004
		expectedProblemAttributes.put("MissingSynchronizedModifierInInheritedMethod", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD));
2005
		expectedProblemAttributes.put("MissingSynchronizedModifierInInheritedMethod", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD));
2006
		expectedProblemAttributes.put("ShouldImplementHashcode", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_HASHCODE_METHOD));
2005
		Map constantNamesIndex = new HashMap();
2007
		Map constantNamesIndex = new HashMap();
2006
		Field[] fields = JavaCore.class.getFields();
2008
		Field[] fields = JavaCore.class.getFields();
2007
		for (int i = 0, length = fields.length; i < length; i++) {
2009
		for (int i = 0, length = fields.length; i < length; i++) {
(-)compiler/org/eclipse/jdt/core/compiler/IProblem.java (+2 lines)
Lines 627-632 Link Here
627
	int ObjectMustBeClass = Internal + 330;
627
	int ObjectMustBeClass = Internal + 330;
628
	/** @since 3.4 */
628
	/** @since 3.4 */
629
	int RedundantSuperinterface = TypeRelated + 331;
629
	int RedundantSuperinterface = TypeRelated + 331;
630
	/** @since 3.5 */
631
	int ShouldImplementHashcode = TypeRelated + 332;
630
632
631
	/** @deprecated - problem is no longer generated, use {@link #UndefinedType} instead */
633
	/** @deprecated - problem is no longer generated, use {@link #UndefinedType} instead */
632
	int SuperclassNotFound =  TypeRelated + 329 + ProblemReasons.NotFound; // TypeRelated + 330
634
	int SuperclassNotFound =  TypeRelated + 329 + ProblemReasons.NotFound; // TypeRelated + 330
(-)batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (+1 lines)
Lines 251-256 Link Here
251
\      finalBound           type parameter with final bound\n\
251
\      finalBound           type parameter with final bound\n\
252
\      finally            + finally block not completing normally\n\
252
\      finally            + finally block not completing normally\n\
253
\      forbidden          + use of types matching a forbidden access rule\n\
253
\      forbidden          + use of types matching a forbidden access rule\n\
254
\      hashCode               missing hashCode() method when overriding equals()\n\
254
\      hiding               macro for fieldHiding, localHiding, typeHiding and\n\
255
\      hiding               macro for fieldHiding, localHiding, typeHiding and\n\
255
\                           maskedCatchBlock\n\
256
\                           maskedCatchBlock\n\
256
\      incomplete-switch    same as enumSwitch\n\
257
\      incomplete-switch    same as enumSwitch\n\
(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (+5 lines)
Lines 3205-3210 Link Here
3205
					CompilerOptions.OPTION_ReportTypeParameterHiding,
3205
					CompilerOptions.OPTION_ReportTypeParameterHiding,
3206
					isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
3206
					isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
3207
				return;
3207
				return;
3208
			} else if (token.equals("hashCode")) { //$NON-NLS-1$
3209
				this.options.put(
3210
					CompilerOptions.OPTION_ReportMissingHashCodeMethod,
3211
					isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
3212
				return;
3208
			}
3213
			}
3209
			break;
3214
			break;
3210
		case 'i' :
3215
		case 'i' :
(-)compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties (+1 lines)
Lines 256-261 Link Here
256
329 = The type java.lang.Object cannot have a superclass or superinterfaces
256
329 = The type java.lang.Object cannot have a superclass or superinterfaces
257
330 = The type java.lang.Object must be a class
257
330 = The type java.lang.Object must be a class
258
331 = Redundant superinterface {0} for the type {1}, already defined by {2}
258
331 = Redundant superinterface {0} for the type {1}, already defined by {2}
259
332 = The type {0} should also implement hashcode() since it overrides Object.equals()
259
260
260
###[obsolete] 330 = {0} cannot be resolved or is not a valid superclass
261
###[obsolete] 330 = {0} cannot be resolved or is not a valid superclass
261
###[obsolete] 331 = Superclass {0} is not visible
262
###[obsolete] 331 = Superclass {0} is not visible
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (-1 / +14 lines)
Lines 323-328 Link Here
323
			
323
			
324
		case IProblem.MissingSynchronizedModifierInInheritedMethod:
324
		case IProblem.MissingSynchronizedModifierInInheritedMethod:
325
			return CompilerOptions.MissingSynchronizedModifierInInheritedMethod;
325
			return CompilerOptions.MissingSynchronizedModifierInInheritedMethod;
326
327
		case IProblem.ShouldImplementHashcode:
328
			return CompilerOptions.ShouldImplementHashcode;
326
	}
329
	}
327
	return 0;
330
	return 0;
328
}
331
}
Lines 370-376 Link Here
370
			case CompilerOptions.FallthroughCase :
373
			case CompilerOptions.FallthroughCase :
371
			case CompilerOptions.OverridingMethodWithoutSuperInvocation :
374
			case CompilerOptions.OverridingMethodWithoutSuperInvocation :
372
			case CompilerOptions.ComparingIdentical :
375
			case CompilerOptions.ComparingIdentical :
373
			case CompilerOptions.MissingSynchronizedModifierInInheritedMethod :				
376
			case CompilerOptions.MissingSynchronizedModifierInInheritedMethod :
377
			case CompilerOptions.ShouldImplementHashcode :
374
				return CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM;
378
				return CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM;
375
			
379
			
376
			case CompilerOptions.OverriddenPackageDefaultMethod :
380
			case CompilerOptions.OverriddenPackageDefaultMethod :
Lines 7265-7268 Link Here
7265
		typeRef.sourceStart,
7269
		typeRef.sourceStart,
7266
		typeRef.sourceEnd);
7270
		typeRef.sourceEnd);
7267
}
7271
}
7272
7273
public void shouldImplementHashcode(SourceTypeBinding type) {	
7274
	this.handle(
7275
		IProblem.ShouldImplementHashcode,
7276
		new String[] {new String(type.sourceName())},
7277
		new String[] {new String(type.sourceName())},
7278
		type.sourceStart(),
7279
		type.sourceEnd());
7280
}
7268
}
7281
}
(-)model/org/eclipse/jdt/core/JavaCore.java (+13 lines)
Lines 986-991 Link Here
986
	 */
986
	 */
987
	public static final String COMPILER_PB_MISSING_DEPRECATED_ANNOTATION = PLUGIN_ID + ".compiler.problem.missingDeprecatedAnnotation"; //$NON-NLS-1$
987
	public static final String COMPILER_PB_MISSING_DEPRECATED_ANNOTATION = PLUGIN_ID + ".compiler.problem.missingDeprecatedAnnotation"; //$NON-NLS-1$
988
	/**
988
	/**
989
	 * Compiler option ID: Reporting Missing HashCode Method.
990
	 * <p>When enabled, the compiler will issue an error or a warning if a type
991
	 * overrides Object.equals(Object) but does not override hashCode().
992
	 * <dl>
993
	 * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod"</code></dd>
994
	 * <dt>Possible values:</dt><dd><code>{ "error", "warning", "ignore" }</code></dd>
995
	 * <dt>Default:</dt><dd><code>"ignore"</code></dd>
996
	 * </dl>
997
	 * @since 3.5
998
	 * @category CompilerOptionID
999
	 */
1000
	public static final String COMPILER_PB_MISSING_HASHCODE_METHOD = PLUGIN_ID + ".compiler.problem.missingHashCodeMethod"; //$NON-NLS-1$
1001
	/**
989
	 * Compiler option ID: Reporting Incomplete Enum Switch.
1002
	 * Compiler option ID: Reporting Incomplete Enum Switch.
990
	 * <p>When enabled, the compiler will issue an error or a warning whenever
1003
	 * <p>When enabled, the compiler will issue an error or a warning whenever
991
	 *    an enum constant has no corresponding case label in an enum switch
1004
	 *    an enum constant has no corresponding case label in an enum switch
(-).settings/org.eclipse.jdt.core.prefs (+1 lines)
Lines 44-49 Link Here
44
org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning
44
org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning
45
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
45
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
46
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
46
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
47
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
47
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
48
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
48
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=enabled
49
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=enabled
49
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
50
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
(-)compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java (-2 / +7 lines)
Lines 122-127 Link Here
122
	public static final String OPTION_ReportRedundantSuperinterface =  "org.eclipse.jdt.core.compiler.problem.redundantSuperinterface"; //$NON-NLS-1$
122
	public static final String OPTION_ReportRedundantSuperinterface =  "org.eclipse.jdt.core.compiler.problem.redundantSuperinterface"; //$NON-NLS-1$
123
	public static final String OPTION_ReportComparingIdentical =  "org.eclipse.jdt.core.compiler.problem.comparingIdentical"; //$NON-NLS-1$
123
	public static final String OPTION_ReportComparingIdentical =  "org.eclipse.jdt.core.compiler.problem.comparingIdentical"; //$NON-NLS-1$
124
	public static final String OPTION_ReportMissingSynchronizedOnInheritedMethod =  "org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod"; //$NON-NLS-1$
124
	public static final String OPTION_ReportMissingSynchronizedOnInheritedMethod =  "org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod"; //$NON-NLS-1$
125
	public static final String OPTION_ReportMissingHashCodeMethod =  "org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod"; //$NON-NLS-1$
125
126
126
	// Backward compatibility
127
	// Backward compatibility
127
	public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$
128
	public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$
Lines 224-231 Link Here
224
	public static final int MissingSynchronizedModifierInInheritedMethod= IrritantSet.GROUP1 | ASTNode.Bit29;
225
	public static final int MissingSynchronizedModifierInInheritedMethod= IrritantSet.GROUP1 | ASTNode.Bit29;
225
226
226
	// group 2
227
	// group 2
227
	// NEXT IRRITANT GOES HERE (group1 is complete already)
228
	public static final int ShouldImplementHashcode= IrritantSet.GROUP2 | ASTNode.Bit1;
228
	//	public static final int FirstInGroup2 = IrritantSet.GROUP2 | ASTNode.Bit1;
229
	
229
	
230
	// Map: String optionKey --> Long irritant>
230
	// Map: String optionKey --> Long irritant>
231
	private static Map OptionToIrritants;
231
	private static Map OptionToIrritants;
Lines 476-481 Link Here
476
				return OPTION_ReportComparingIdentical;
476
				return OPTION_ReportComparingIdentical;
477
			case MissingSynchronizedModifierInInheritedMethod :
477
			case MissingSynchronizedModifierInInheritedMethod :
478
				return OPTION_ReportMissingSynchronizedOnInheritedMethod;
478
				return OPTION_ReportMissingSynchronizedOnInheritedMethod;
479
			case ShouldImplementHashcode :
480
				return OPTION_ReportMissingHashCodeMethod;
479
		}
481
		}
480
		return null;
482
		return null;
481
	}
483
	}
Lines 890-895 Link Here
890
		optionsMap.put(OPTION_ReportRedundantSuperinterface, getSeverityString(RedundantSuperinterface));
892
		optionsMap.put(OPTION_ReportRedundantSuperinterface, getSeverityString(RedundantSuperinterface));
891
		optionsMap.put(OPTION_ReportComparingIdentical, getSeverityString(ComparingIdentical));
893
		optionsMap.put(OPTION_ReportComparingIdentical, getSeverityString(ComparingIdentical));
892
		optionsMap.put(OPTION_ReportMissingSynchronizedOnInheritedMethod, getSeverityString(MissingSynchronizedModifierInInheritedMethod));
894
		optionsMap.put(OPTION_ReportMissingSynchronizedOnInheritedMethod, getSeverityString(MissingSynchronizedModifierInInheritedMethod));
895
		optionsMap.put(OPTION_ReportMissingHashCodeMethod, getSeverityString(ShouldImplementHashcode));
893
		return optionsMap;
896
		return optionsMap;
894
	}
897
	}
895
898
Lines 1260-1265 Link Here
1260
		if ((optionValue = optionsMap.get(OPTION_ReportRedundantSuperinterface)) != null) updateSeverity(RedundantSuperinterface, optionValue);
1263
		if ((optionValue = optionsMap.get(OPTION_ReportRedundantSuperinterface)) != null) updateSeverity(RedundantSuperinterface, optionValue);
1261
		if ((optionValue = optionsMap.get(OPTION_ReportComparingIdentical)) != null) updateSeverity(ComparingIdentical, optionValue);
1264
		if ((optionValue = optionsMap.get(OPTION_ReportComparingIdentical)) != null) updateSeverity(ComparingIdentical, optionValue);
1262
		if ((optionValue = optionsMap.get(OPTION_ReportMissingSynchronizedOnInheritedMethod)) != null) updateSeverity(MissingSynchronizedModifierInInheritedMethod, optionValue);
1265
		if ((optionValue = optionsMap.get(OPTION_ReportMissingSynchronizedOnInheritedMethod)) != null) updateSeverity(MissingSynchronizedModifierInInheritedMethod, optionValue);
1266
		if ((optionValue = optionsMap.get(OPTION_ReportMissingHashCodeMethod)) != null) updateSeverity(ShouldImplementHashcode, optionValue);
1263
1267
1264
		// Javadoc options
1268
		// Javadoc options
1265
		if ((optionValue = optionsMap.get(OPTION_DocCommentSupport)) != null) {
1269
		if ((optionValue = optionsMap.get(OPTION_DocCommentSupport)) != null) {
Lines 1456-1461 Link Here
1456
		buf.append("\n\t- redundant superinterface: ").append(getSeverityString(RedundantSuperinterface)); //$NON-NLS-1$
1460
		buf.append("\n\t- redundant superinterface: ").append(getSeverityString(RedundantSuperinterface)); //$NON-NLS-1$
1457
		buf.append("\n\t- comparing identical expr: ").append(getSeverityString(ComparingIdentical)); //$NON-NLS-1$
1461
		buf.append("\n\t- comparing identical expr: ").append(getSeverityString(ComparingIdentical)); //$NON-NLS-1$
1458
		buf.append("\n\t- missing synchronized on inherited method: ").append(getSeverityString(MissingSynchronizedModifierInInheritedMethod)); //$NON-NLS-1$
1462
		buf.append("\n\t- missing synchronized on inherited method: ").append(getSeverityString(MissingSynchronizedModifierInInheritedMethod)); //$NON-NLS-1$
1463
		buf.append("\n\t- should implement hashCode() method: ").append(getSeverityString(ShouldImplementHashcode)); //$NON-NLS-1$
1459
		return buf.toString();
1464
		return buf.toString();
1460
	}
1465
	}
1461
	
1466
	
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java (+16 lines)
Lines 24-29 Link Here
24
	HashtableOfObject currentMethods;
24
	HashtableOfObject currentMethods;
25
	LookupEnvironment environment;
25
	LookupEnvironment environment;
26
	private boolean allowCompatibleReturnTypes;
26
	private boolean allowCompatibleReturnTypes;
27
	char[] equals = "equals".toCharArray(); //$NON-NLS-1$
28
	char[] hashCode = "hashCode".toCharArray(); //$NON-NLS-1$
27
/*
29
/*
28
Binding creation is responsible for reporting all problems with types:
30
Binding creation is responsible for reporting all problems with types:
29
	- all modifier problems (duplicates & multiple visibility modifiers + incompatible combinations - abstract/final)
31
	- all modifier problems (duplicates & multiple visibility modifiers + incompatible combinations - abstract/final)
Lines 247-252 Link Here
247
	// no op before 1.5
249
	// no op before 1.5
248
}
250
}
249
251
252
void checkForMissingHashCodeMethod() {
253
	MethodBinding[] choices = this.type.getMethods(this.equals);
254
	boolean overridesEquals = false;
255
	for (int i = choices.length; !overridesEquals && --i >= 0;)
256
		overridesEquals = choices[i].parameters.length == 1 && choices[i].parameters[0].id == TypeIds.T_JavaLangObject;
257
	if (overridesEquals) {
258
		MethodBinding hashCodeMethod = this.type.getExactMethod(this.hashCode, Binding.NO_PARAMETERS, null);
259
		if (hashCodeMethod != null && hashCodeMethod.declaringClass.id == TypeIds.T_JavaLangObject)
260
			this.problemReporter().shouldImplementHashcode(this.type);
261
	}
262
}
263
250
void checkForRedundantSuperinterfaces(ReferenceBinding superclass, ReferenceBinding[] superInterfaces) {
264
void checkForRedundantSuperinterfaces(ReferenceBinding superclass, ReferenceBinding[] superInterfaces) {
251
	if (superInterfaces == Binding.NO_SUPERINTERFACES) return;
265
	if (superInterfaces == Binding.NO_SUPERINTERFACES) return;
252
266
Lines 861-866 Link Here
861
	computeMethods();
875
	computeMethods();
862
	computeInheritedMethods();
876
	computeInheritedMethods();
863
	checkMethods();
877
	checkMethods();
878
	if (this.type.isClass())
879
		checkForMissingHashCodeMethod();
864
}
880
}
865
881
866
public String toString() {
882
public String toString() {
(-)guide/jdt_api_options.htm (+14 lines)
Lines 468-473 Link Here
468
</tr>
468
</tr>
469
469
470
<tr>
470
<tr>
471
<td colspan=2><b>Reporting Missing HashCode Method</b> (<b><a href="../reference/api/org/eclipse/jdt/core/JavaCore.html#COMPILER_PB_MISSING_HASHCODE_METHOD">COMPILER_PB_MISSING_HASHCODE_METHOD</a></b>)</td>
472
</tr>
473
<tr valign="top">
474
<td rowspan=3>When enabled, the compiler will issue an error or a warning if a type overrides Object.equals(Object) but does not override hashCode().</td>
475
<td><b><a href="../reference/api/org/eclipse/jdt/core/JavaCore.html#ERROR"><i>ERROR</i></a></b></td>
476
</tr>
477
<tr valign="top">
478
<td><b><a href="../reference/api/org/eclipse/jdt/core/JavaCore.html#WARNING">WARNING</a></b></td>
479
</tr>
480
<tr valign="top">
481
<td><b><a href="../reference/api/org/eclipse/jdt/core/JavaCore.html#IGNORE">IGNORE</a></b></td>
482
</tr>
483
484
<tr>
471
<td colspan=2><b>Reporting Hidden Catch Block</b> (<b><a href="../reference/api/org/eclipse/jdt/core/JavaCore.html#COMPILER_PB_HIDDEN_CATCH_BLOCK">COMPILER_PB_HIDDEN_CATCH_BLOCK</a></b>)</td>
485
<td colspan=2><b>Reporting Hidden Catch Block</b> (<b><a href="../reference/api/org/eclipse/jdt/core/JavaCore.html#COMPILER_PB_HIDDEN_CATCH_BLOCK">COMPILER_PB_HIDDEN_CATCH_BLOCK</a></b>)</td>
472
</tr>
486
</tr>
473
<tr valign="top">
487
<tr valign="top">

Return to bug 38751