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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/core/compiler/IProblem.java (+2 lines)
Lines 1225-1230 Link Here
1225
	int MethodMustOverrideOrImplement = MethodRelated + 634;
1225
	int MethodMustOverrideOrImplement = MethodRelated + 634;
1226
	/** @since 3.4 */
1226
	/** @since 3.4 */
1227
	int UnusedWarningToken = Internal + 635;
1227
	int UnusedWarningToken = Internal + 635;
1228
	/** @since 3.5 */
1229
	int MissingOverrideAnnotationForInterfaceMethodImplementation = MethodRelated + 636;
1228
1230
1229
	/**
1231
	/**
1230
	 * More problems in generics
1232
	 * More problems in generics
(-)model/org/eclipse/jdt/core/JavaCore.java (+14 lines)
Lines 976-981 Link Here
976
	 */
976
	 */
977
	public static final String COMPILER_PB_MISSING_OVERRIDE_ANNOTATION = PLUGIN_ID + ".compiler.problem.missingOverrideAnnotation"; //$NON-NLS-1$
977
	public static final String COMPILER_PB_MISSING_OVERRIDE_ANNOTATION = PLUGIN_ID + ".compiler.problem.missingOverrideAnnotation"; //$NON-NLS-1$
978
	/**
978
	/**
979
	 * Compiler option ID: Reporting Missing <code>@Override</code> Annotation for interface method implementation.
980
	 * <p>When enabled, the compiler will issue an error or a warning whenever encountering a method
981
	 *    declaration which overrides or implements a supertype method but has no <code>@Override</code> annotation.
982
	 * <p>The severity of the problem is controlled with option {@link #COMPILER_PB_MISSING_OVERRIDE_ANNOTATION}.
983
	 * <dl>
984
	 * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation"</code></dd>
985
	 * <dt>Possible values:</dt><dd><code>{ "enabled", "disabled" }</code></dd>
986
	 * <dt>Default:</dt><dd><code>"disabled"</code></dd>
987
	 * </dl>
988
	 * @since 3.5
989
	 * @category CompilerOptionID
990
	 */
991
	public static final String COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION = PLUGIN_ID + ".compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation"; //$NON-NLS-1$
992
	/**
979
	 * Compiler option ID: Reporting Missing <code>@Deprecated</code> Annotation.
993
	 * Compiler option ID: Reporting Missing <code>@Deprecated</code> Annotation.
980
	 * <p>When enabled, the compiler will issue an error or a warning whenever encountering a declaration
994
	 * <p>When enabled, the compiler will issue an error or a warning whenever encountering a declaration
981
	 *    carrying a <code>@deprecated</code> doc tag but having no corresponding <code>@Deprecated</code> annotation.
995
	 *    carrying a <code>@deprecated</code> doc tag but having no corresponding <code>@Deprecated</code> annotation.
(-)compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties (+1 lines)
Lines 560-565 Link Here
560
633 = The value for annotation attribute {0}.{1} must be an enum constant expression
560
633 = The value for annotation attribute {0}.{1} must be an enum constant expression
561
634 = The method {0}({1}) of type {2} must override or implement a supertype method
561
634 = The method {0}({1}) of type {2} must override or implement a supertype method
562
635 = Unnecessary @SuppressWarnings("{0}")
562
635 = Unnecessary @SuppressWarnings("{0}")
563
636 = The method {0}({1}) of type {2} should be tagged with @Override since it actually overrides a supertype method
563
564
564
### MORE GENERICS
565
### MORE GENERICS
565
660 = Unused type arguments for the non generic constructor {0}({1}) of type {2}; it should not be parameterized with arguments <{3}>
566
660 = Unused type arguments for the non generic constructor {0}({1}) of type {2}; it should not be parameterized with arguments <{3}>
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (+13 lines)
Lines 254-259 Link Here
254
			return CompilerOptions.RawTypeReference;
254
			return CompilerOptions.RawTypeReference;
255
255
256
		case IProblem.MissingOverrideAnnotation:
256
		case IProblem.MissingOverrideAnnotation:
257
		case IProblem.MissingOverrideAnnotationForInterfaceMethodImplementation:
257
			return CompilerOptions.MissingOverrideAnnotation;
258
			return CompilerOptions.MissingOverrideAnnotation;
258
259
259
		case IProblem.FieldMissingDeprecatedAnnotation:
260
		case IProblem.FieldMissingDeprecatedAnnotation:
Lines 5001-5006 Link Here
5001
		method.sourceStart,
5002
		method.sourceStart,
5002
		method.sourceEnd);
5003
		method.sourceEnd);
5003
}
5004
}
5005
public void missingOverrideAnnotationForInterfaceMethodImplementation(AbstractMethodDeclaration method) {
5006
	int severity = computeSeverity(IProblem.MissingOverrideAnnotationForInterfaceMethodImplementation);
5007
	if (severity == ProblemSeverities.Ignore) return;
5008
	MethodBinding binding = method.binding;
5009
	this.handle(
5010
		IProblem.MissingOverrideAnnotationForInterfaceMethodImplementation,
5011
		new String[] {new String(binding.selector), typesAsString(binding.isVarargs(), binding.parameters, false), new String(binding.declaringClass.readableName()), },
5012
		new String[] {new String(binding.selector), typesAsString(binding.isVarargs(), binding.parameters, true), new String(binding.declaringClass.shortReadableName()),},
5013
		severity,
5014
		method.sourceStart,
5015
		method.sourceEnd);
5016
}
5004
public void missingReturnType(AbstractMethodDeclaration methodDecl) {
5017
public void missingReturnType(AbstractMethodDeclaration methodDecl) {
5005
	this.handle(
5018
	this.handle(
5006
		IProblem.MissingReturnType,
5019
		IProblem.MissingReturnType,
(-)batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (+1 lines)
Lines 236-241 Link Here
236
\      allDeadCode          dead code including trivial if(DEBUG) check\n\
236
\      allDeadCode          dead code including trivial if(DEBUG) check\n\
237
\      allDeprecation       deprecation including inside deprecated code\n\
237
\      allDeprecation       deprecation including inside deprecated code\n\
238
\      allJavadoc           invalid or missing javadoc\n\
238
\      allJavadoc           invalid or missing javadoc\n\
239
\	   allOver-ann			all missing @Override annotations\n\
239
\      assertIdentifier   + ''assert'' used as identifier\n\
240
\      assertIdentifier   + ''assert'' used as identifier\n\
240
\      boxing               autoboxing conversion\n\
241
\      boxing               autoboxing conversion\n\
241
\      charConcat         + char[] in String concat\n\
242
\      charConcat         + char[] in String concat\n\
(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (+11 lines)
Lines 3088-3093 Link Here
3088
						CompilerOptions.OPTION_ReportDeadCodeInTrivialIfStatement,
3088
						CompilerOptions.OPTION_ReportDeadCodeInTrivialIfStatement,
3089
						isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
3089
						isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
3090
					return;
3090
					return;
3091
			} else if (token.equals("allOver-ann")) { //$NON-NLS-1$
3092
				this.options.put(
3093
						CompilerOptions.OPTION_ReportMissingOverrideAnnotation,
3094
						isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
3095
				this.options.put(
3096
						CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation,
3097
						isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
3098
				return;
3091
			}
3099
			}
3092
			break;
3100
			break;
3093
		case 'b' :
3101
		case 'b' :
Lines 3319-3324 Link Here
3319
				this.options.put(
3327
				this.options.put(
3320
					CompilerOptions.OPTION_ReportMissingOverrideAnnotation,
3328
					CompilerOptions.OPTION_ReportMissingOverrideAnnotation,
3321
					isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
3329
					isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
3330
				this.options.put(
3331
					CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation,
3332
					CompilerOptions.DISABLED);
3322
				return;
3333
				return;
3323
			}
3334
			}
3324
			break;
3335
			break;
(-)compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java (+11 lines)
Lines 105-110 Link Here
105
	public static final String OPTION_ReportAutoboxing = "org.eclipse.jdt.core.compiler.problem.autoboxing"; //$NON-NLS-1$
105
	public static final String OPTION_ReportAutoboxing = "org.eclipse.jdt.core.compiler.problem.autoboxing"; //$NON-NLS-1$
106
	public static final String OPTION_ReportAnnotationSuperInterface = "org.eclipse.jdt.core.compiler.problem.annotationSuperInterface"; //$NON-NLS-1$
106
	public static final String OPTION_ReportAnnotationSuperInterface = "org.eclipse.jdt.core.compiler.problem.annotationSuperInterface"; //$NON-NLS-1$
107
	public static final String OPTION_ReportMissingOverrideAnnotation = "org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation"; //$NON-NLS-1$
107
	public static final String OPTION_ReportMissingOverrideAnnotation = "org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation"; //$NON-NLS-1$
108
	public static final String OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation = "org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation"; //$NON-NLS-1$
108
	public static final String OPTION_ReportMissingDeprecatedAnnotation = "org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation"; //$NON-NLS-1$
109
	public static final String OPTION_ReportMissingDeprecatedAnnotation = "org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation"; //$NON-NLS-1$
109
	public static final String OPTION_ReportIncompleteEnumSwitch = "org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch"; //$NON-NLS-1$
110
	public static final String OPTION_ReportIncompleteEnumSwitch = "org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch"; //$NON-NLS-1$
110
	public static final String OPTION_ReportForbiddenReference =  "org.eclipse.jdt.core.compiler.problem.forbiddenReference"; //$NON-NLS-1$
111
	public static final String OPTION_ReportForbiddenReference =  "org.eclipse.jdt.core.compiler.problem.forbiddenReference"; //$NON-NLS-1$
Lines 326-331 Link Here
326
	public boolean processAnnotations;
327
	public boolean processAnnotations;
327
	/** Store annotations */
328
	/** Store annotations */
328
	public boolean storeAnnotations;
329
	public boolean storeAnnotations;
330
	/** Specify if need to report missing override annotation for a method implementing an interface method (java 1.6 and above)*/
331
	public boolean reportMissingOverrideAnnotationForInterfaceMethodImplementation;
329
	/** Indicate if annotation processing generates classfiles */
332
	/** Indicate if annotation processing generates classfiles */
330
	public boolean generateClassFiles;
333
	public boolean generateClassFiles;
331
334
Lines 843-848 Link Here
843
		optionsMap.put(OPTION_ReportDiscouragedReference, getSeverityString(DiscouragedReference));
846
		optionsMap.put(OPTION_ReportDiscouragedReference, getSeverityString(DiscouragedReference));
844
		optionsMap.put(OPTION_ReportVarargsArgumentNeedCast, getSeverityString(VarargsArgumentNeedCast));
847
		optionsMap.put(OPTION_ReportVarargsArgumentNeedCast, getSeverityString(VarargsArgumentNeedCast));
845
		optionsMap.put(OPTION_ReportMissingOverrideAnnotation, getSeverityString(MissingOverrideAnnotation));
848
		optionsMap.put(OPTION_ReportMissingOverrideAnnotation, getSeverityString(MissingOverrideAnnotation));
849
		optionsMap.put(OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, this.reportMissingOverrideAnnotationForInterfaceMethodImplementation ? ENABLED : DISABLED);
846
		optionsMap.put(OPTION_ReportMissingDeprecatedAnnotation, getSeverityString(MissingDeprecatedAnnotation));
850
		optionsMap.put(OPTION_ReportMissingDeprecatedAnnotation, getSeverityString(MissingDeprecatedAnnotation));
847
		optionsMap.put(OPTION_ReportIncompleteEnumSwitch, getSeverityString(IncompleteEnumSwitch));
851
		optionsMap.put(OPTION_ReportIncompleteEnumSwitch, getSeverityString(IncompleteEnumSwitch));
848
		optionsMap.put(OPTION_ReportUnusedLabel, getSeverityString(UnusedLabel));
852
		optionsMap.put(OPTION_ReportUnusedLabel, getSeverityString(UnusedLabel));
Lines 1208-1213 Link Here
1208
				this.treatOptionalErrorAsFatal = false;
1212
				this.treatOptionalErrorAsFatal = false;
1209
			}
1213
			}
1210
		}
1214
		}
1215
		if ((optionValue = optionsMap.get(OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation)) != null) {
1216
			if (ENABLED.equals(optionValue)) {
1217
				this.reportMissingOverrideAnnotationForInterfaceMethodImplementation = true;
1218
			} else if (DISABLED.equals(optionValue)) {
1219
				this.reportMissingOverrideAnnotationForInterfaceMethodImplementation = false;
1220
			}
1221
		}
1211
		if ((optionValue = optionsMap.get(OPTION_ReportMethodWithConstructorName)) != null) updateSeverity(MethodWithConstructorName, optionValue);
1222
		if ((optionValue = optionsMap.get(OPTION_ReportMethodWithConstructorName)) != null) updateSeverity(MethodWithConstructorName, optionValue);
1212
		if ((optionValue = optionsMap.get(OPTION_ReportOverridingPackageDefaultMethod)) != null) updateSeverity(OverriddenPackageDefaultMethod, optionValue);
1223
		if ((optionValue = optionsMap.get(OPTION_ReportOverridingPackageDefaultMethod)) != null) updateSeverity(OverriddenPackageDefaultMethod, optionValue);
1213
		if ((optionValue = optionsMap.get(OPTION_ReportDeprecation)) != null) updateSeverity(UsingDeprecatedAPI, optionValue);
1224
		if ((optionValue = optionsMap.get(OPTION_ReportDeprecation)) != null) updateSeverity(UsingDeprecatedAPI, optionValue);
(-)compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java (-4 / +26 lines)
Lines 160-169 Link Here
160
					break checkOverride;
160
					break checkOverride;
161
				// claims to override, and doesn't actually do so
161
				// claims to override, and doesn't actually do so
162
				this.scope.problemReporter().methodMustOverride(this, complianceLevel);
162
				this.scope.problemReporter().methodMustOverride(this, complianceLevel);
163
			} else if (!this.binding.declaringClass.isInterface()
163
			} else {
164
						&& (bindingModifiers & (ClassFileConstants.AccStatic|ExtraCompilerModifiers.AccOverriding)) == ExtraCompilerModifiers.AccOverriding) {
164
				//In case of  a concrete class method, we have to check if it overrides(in 1.5 and above) OR implements a method(1.6 and above).
165
				// actually overrides, but did not claim to do so
165
				//Also check if the method has a signature that is override-equivalent to that of any public method declared in Object.
166
				this.scope.problemReporter().missingOverrideAnnotation(this);
166
				if (!this.binding.declaringClass.isInterface()){
167
						if((bindingModifiers & (ClassFileConstants.AccStatic|ExtraCompilerModifiers.AccOverriding)) == ExtraCompilerModifiers.AccOverriding) {
168
							this.scope.problemReporter().missingOverrideAnnotation(this);
169
						} else {
170
							if(complianceLevel >= ClassFileConstants.JDK1_6
171
								&& compilerOptions.reportMissingOverrideAnnotationForInterfaceMethodImplementation
172
								&& this.binding.isImplementing()) {
173
									// actually overrides, but did not claim to do so
174
									this.scope.problemReporter().missingOverrideAnnotationForInterfaceMethodImplementation(this);
175
							}
176
							
177
						}
178
				}
179
				else {	//For 1.6 and above only
180
					//In case of a interface class method, we have to check if it overrides a method (isImplementing returns true in case it overrides)
181
					//Also check if the method has a signature that is override-equivalent to that of any public method declared in Object.
182
					if(complianceLevel >= ClassFileConstants.JDK1_6
183
							&& compilerOptions.reportMissingOverrideAnnotationForInterfaceMethodImplementation
184
							&& (((bindingModifiers & (ClassFileConstants.AccStatic|ExtraCompilerModifiers.AccOverriding)) == ExtraCompilerModifiers.AccOverriding) || this.binding.isImplementing())){
185
						// actually overrides, but did not claim to do so
186
						this.scope.problemReporter().missingOverrideAnnotationForInterfaceMethodImplementation(this);
187
					}
188
				}
167
			}
189
			}
168
		}
190
		}
169
191
(-)src/org/eclipse/jdt/internal/compiler/tool/Options.java (+1 lines)
Lines 145-150 Link Here
145
				if (token.equals("allDeadCode")//$NON-NLS-1$
145
				if (token.equals("allDeadCode")//$NON-NLS-1$
146
						|| token.equals("allDeprecation")//$NON-NLS-1$
146
						|| token.equals("allDeprecation")//$NON-NLS-1$
147
						|| token.equals("allJavadoc")//$NON-NLS-1$
147
						|| token.equals("allJavadoc")//$NON-NLS-1$
148
						|| token.equals("allOver-ann")//$NON-NLS-1$
148
						|| token.equals("assertIdentifier")//$NON-NLS-1$
149
						|| token.equals("assertIdentifier")//$NON-NLS-1$
149
						|| token.equals("boxing")//$NON-NLS-1$
150
						|| token.equals("boxing")//$NON-NLS-1$
150
						|| token.equals("charConcat")//$NON-NLS-1$
151
						|| token.equals("charConcat")//$NON-NLS-1$
(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (+42 lines)
Lines 1641-1646 Link Here
1641
        "      allDeadCode          dead code including trivial if(DEBUG) check\n" +
1641
        "      allDeadCode          dead code including trivial if(DEBUG) check\n" +
1642
        "      allDeprecation       deprecation including inside deprecated code\n" +
1642
        "      allDeprecation       deprecation including inside deprecated code\n" +
1643
        "      allJavadoc           invalid or missing javadoc\n" +
1643
        "      allJavadoc           invalid or missing javadoc\n" +
1644
        "	   allOver-ann			all missing @Override annotations\n" +
1644
        "      assertIdentifier   + ''assert'' used as identifier\n" +
1645
        "      assertIdentifier   + ''assert'' used as identifier\n" +
1645
        "      boxing               autoboxing conversion\n" +
1646
        "      boxing               autoboxing conversion\n" +
1646
        "      charConcat         + char[] in String concat\n" +
1647
        "      charConcat         + char[] in String concat\n" +
Lines 1813-1818 Link Here
1813
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding\" value=\"disabled\"/>\n" +
1814
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding\" value=\"disabled\"/>\n" +
1814
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility\" value=\"public\"/>\n" +
1815
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility\" value=\"public\"/>\n" +
1815
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation\" value=\"ignore\"/>\n" +
1816
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation\" value=\"ignore\"/>\n" +
1817
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation\" value=\"disabled\"/>\n" +
1816
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingSerialVersion\" value=\"warning\"/>\n" +
1818
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingSerialVersion\" value=\"warning\"/>\n" +
1817
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod\" value=\"ignore\"/>\n" +
1819
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod\" value=\"ignore\"/>\n" +
1818
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.noEffectAssignment\" value=\"warning\"/>\n" +
1820
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.noEffectAssignment\" value=\"warning\"/>\n" +
Lines 11054-11057 Link Here
11054
		actual, 
11056
		actual, 
11055
		true/*show line serators*/);
11057
		true/*show line serators*/);
11056
}
11058
}
11059
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163194
11060
// -warn option - regression tests to check option allOver-ann
11061
public void test292_warn_options() {
11062
	this.runConformTest(
11063
		new String[] {
11064
			"X.java",
11065
			"interface A {\n" +
11066
			"  void m();\n" +
11067
			"}" +
11068
			"interface B extends A{\n" +
11069
			"  void m();\n" +
11070
			"}" +
11071
			"public class X implements A{\n" +
11072
			"  public void m(){}\n" +
11073
			"  public String toString(){return \"HelloWorld\";}\n" +
11074
			"}",
11075
		},
11076
		"\"" + OUTPUT_DIR +  File.separator + "X.java\""
11077
		+ " -sourcepath \"" + OUTPUT_DIR + "\""
11078
		+ " -warn:allOver-ann -1.6 -d \"" + OUTPUT_DIR + "\"",
11079
		"",
11080
		"----------\n" +
11081
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
11082
		"	void m();\n" +
11083
		"	     ^^^\n" +
11084
		"The method m() of type B should be tagged with @Override since it actually overrides a supertype method\n" +
11085
		"----------\n" +
11086
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 6)\n" +
11087
		"	public void m(){}\n" +
11088
		"	            ^^^\n"+
11089
		"The method m() of type X should be tagged with @Override since it actually overrides a supertype method\n" +
11090
		"----------\n" +
11091
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 7)\n" +
11092
		"	public String toString(){return \"HelloWorld\";}\n" +
11093
		"	              ^^^^^^^^^^\n" +
11094
		"The method toString() of type X should be tagged with @Override since it actually overrides a superclass method\n" +
11095
		"----------\n" +
11096
		"3 problems (3 warnings)",
11097
		true);
11098
}
11057
}
11099
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java (+178 lines)
Lines 8869-8872 Link Here
8869
		"Cycle detected: the annotation type Test<T>.Anno cannot contain attributes of the annotation type itself\n" +
8869
		"Cycle detected: the annotation type Test<T>.Anno cannot contain attributes of the annotation type itself\n" +
8870
		"----------\n");
8870
		"----------\n");
8871
}
8871
}
8872
8873
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163194
8874
// To check Missing override annotation error when a method implements
8875
// and also overrides a method in a superclass
8876
public void test271a() {
8877
	String testString [] = new String[] {
8878
			"T.java",
8879
			"public interface T {\n" +
8880
			"        void m();\n" +
8881
			"}\n" + 
8882
			"abstract class A implements T {\n" +
8883
			"}\n" +
8884
			"class B extends A {\n" +
8885
			"        public void m() {}\n" +
8886
			"}\n"
8887
			};
8888
	Map customOptions = getCompilerOptions();
8889
	customOptions.put(
8890
			CompilerOptions.OPTION_ReportMissingOverrideAnnotation,
8891
			CompilerOptions.ERROR);
8892
	customOptions.put(
8893
			CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation,
8894
			CompilerOptions.ENABLED);
8895
	if (new CompilerOptions(customOptions).sourceLevel >= ClassFileConstants.JDK1_6) {
8896
		String expectedOutput =
8897
				"----------\n" +
8898
				"1. ERROR in T.java (at line 7)\n" +
8899
				"	public void m() {}\n" +
8900
				"	            ^^^\n" +
8901
				"The method m() of type B should be tagged with @Override since it actually overrides a supertype method\n" +
8902
				"----------\n";
8903
		this.runNegativeTest(
8904
				true,
8905
				testString,
8906
				null, customOptions,
8907
				expectedOutput, 
8908
				JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8909
	} else {
8910
		this.runConformTest(
8911
				true, testString,
8912
				null,
8913
				customOptions,
8914
				null,
8915
				null, null, 
8916
				JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8917
	}
8918
}
8919
8920
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163194
8921
// To check Missing override annotation error when a method implements but
8922
// doesn't overrides
8923
public void test271b() {
8924
	String testString [] = new String[] {
8925
			"Over.java",
8926
			"interface I {\n" +
8927
			"        void m();\n" +
8928
			"}\n" +
8929
			"public class Over implements I {\n" +
8930
			"        public void m() {}\n" +
8931
			"}\n"
8932
			};
8933
	Map customOptions = getCompilerOptions();
8934
	customOptions.put(
8935
			CompilerOptions.OPTION_ReportMissingOverrideAnnotation,
8936
			CompilerOptions.ERROR);
8937
	customOptions.put(
8938
			CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation,
8939
			CompilerOptions.ENABLED);
8940
	if (new CompilerOptions(customOptions).sourceLevel >= ClassFileConstants.JDK1_6) {
8941
		String expectedOutput =
8942
			"----------\n" +
8943
			"1. ERROR in Over.java (at line 5)\n" +
8944
			"	public void m() {}\n" +
8945
			"	            ^^^\n" +
8946
			"The method m() of type Over should be tagged with @Override since it actually overrides a supertype method\n" +
8947
			"----------\n";
8948
		this.runNegativeTest(
8949
				true,
8950
				testString,
8951
				null, customOptions,
8952
				expectedOutput,
8953
				JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8954
	} else {
8955
		this.runConformTest(
8956
				true, testString,
8957
				null,
8958
				customOptions,
8959
				null,
8960
				null, null,
8961
				JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8962
	}
8963
}
8964
8965
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163194
8966
// To check Missing override annotation error when a method simply overrides
8967
public void test271c() {
8968
	String testString [] = new String[] {
8969
			"B.java",
8970
			"interface A {\n" +
8971
			"        void m();\n" +
8972
			"}\n" +
8973
			"public interface B extends A {\n" +
8974
			"        void m();\n" +
8975
			"}\n"
8976
			};
8977
	Map customOptions = getCompilerOptions();
8978
	customOptions.put(
8979
			CompilerOptions.OPTION_ReportMissingOverrideAnnotation,
8980
			CompilerOptions.ERROR);
8981
	customOptions.put(
8982
			CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation,
8983
			CompilerOptions.ENABLED);
8984
	if (new CompilerOptions(customOptions).sourceLevel >= ClassFileConstants.JDK1_6) {
8985
		String expectedOutput =
8986
				"----------\n" +
8987
				"1. ERROR in B.java (at line 5)\n" +
8988
				"	void m();\n" +
8989
				"	     ^^^\n" +
8990
				"The method m() of type B should be tagged with @Override since it actually overrides a supertype method\n" +
8991
				"----------\n";
8992
		this.runNegativeTest(
8993
				true,
8994
				testString,
8995
				null, customOptions,
8996
				expectedOutput,
8997
				JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
8998
	} else {
8999
		this.runConformTest(
9000
				true, testString,
9001
				null,
9002
				customOptions,
9003
				null,
9004
				null, null,
9005
				JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
9006
	}
9007
}
9008
9009
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163194
9010
// To check missing override annotation if the method has a signature
9011
// that is override-equivalent to that of any public method declared in Object.
9012
public void test271d() {
9013
	String testString [] = new String[] {
9014
			"A.java",
9015
			"public interface A {\n" +
9016
			"        String toString();\n" +
9017
			"}\n"
9018
			};
9019
	Map customOptions = getCompilerOptions();
9020
	customOptions.put(
9021
			CompilerOptions.OPTION_ReportMissingOverrideAnnotation,
9022
			CompilerOptions.ERROR);
9023
	customOptions.put(
9024
			CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation,
9025
			CompilerOptions.ENABLED);
9026
	if (new CompilerOptions(customOptions).sourceLevel >= ClassFileConstants.JDK1_6) {
9027
		String expectedOutput =
9028
			"----------\n" +
9029
			"1. ERROR in A.java (at line 2)\n" +
9030
			"	String toString();\n" +
9031
			"	       ^^^^^^^^^^\n" +
9032
			"The method toString() of type A should be tagged with @Override since it actually overrides a supertype method\n" +
9033
			"----------\n";
9034
		this.runNegativeTest(
9035
				true,
9036
				testString,
9037
				null, customOptions,
9038
				expectedOutput,
9039
				JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
9040
	} else {
9041
		this.runConformTest(
9042
				true, testString,
9043
				null,
9044
				customOptions,
9045
				null,
9046
				null, null,
9047
				JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
9048
	}
9049
}
8872
}
9050
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java (+2 lines)
Lines 815-820 Link Here
815
		expectedProblemAttributes.put("AnnotationValueMustBeAnnotation", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
815
		expectedProblemAttributes.put("AnnotationValueMustBeAnnotation", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
816
		expectedProblemAttributes.put("AnnotationTypeUsedAsSuperInterface", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE));
816
		expectedProblemAttributes.put("AnnotationTypeUsedAsSuperInterface", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE));
817
		expectedProblemAttributes.put("MissingOverrideAnnotation", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE));
817
		expectedProblemAttributes.put("MissingOverrideAnnotation", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE));
818
		expectedProblemAttributes.put("MissingOverrideAnnotationForInterfaceMethodImplementation", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE));
818
		expectedProblemAttributes.put("FieldMissingDeprecatedAnnotation", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE));
819
		expectedProblemAttributes.put("FieldMissingDeprecatedAnnotation", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE));
819
		expectedProblemAttributes.put("MethodMissingDeprecatedAnnotation", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE));
820
		expectedProblemAttributes.put("MethodMissingDeprecatedAnnotation", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE));
820
		expectedProblemAttributes.put("TypeMissingDeprecatedAnnotation", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE));
821
		expectedProblemAttributes.put("TypeMissingDeprecatedAnnotation", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE));
Lines 1444-1449 Link Here
1444
		expectedProblemAttributes.put("AnnotationValueMustBeAnnotation", SKIP);
1445
		expectedProblemAttributes.put("AnnotationValueMustBeAnnotation", SKIP);
1445
		expectedProblemAttributes.put("AnnotationTypeUsedAsSuperInterface", new ProblemAttributes(JavaCore.COMPILER_PB_ANNOTATION_SUPER_INTERFACE));
1446
		expectedProblemAttributes.put("AnnotationTypeUsedAsSuperInterface", new ProblemAttributes(JavaCore.COMPILER_PB_ANNOTATION_SUPER_INTERFACE));
1446
		expectedProblemAttributes.put("MissingOverrideAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION));
1447
		expectedProblemAttributes.put("MissingOverrideAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION));
1448
		expectedProblemAttributes.put("MissingOverrideAnnotationForInterfaceMethodImplementation", SKIP);
1447
		expectedProblemAttributes.put("FieldMissingDeprecatedAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_DEPRECATED_ANNOTATION));
1449
		expectedProblemAttributes.put("FieldMissingDeprecatedAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_DEPRECATED_ANNOTATION));
1448
		expectedProblemAttributes.put("MethodMissingDeprecatedAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_DEPRECATED_ANNOTATION));
1450
		expectedProblemAttributes.put("MethodMissingDeprecatedAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_DEPRECATED_ANNOTATION));
1449
		expectedProblemAttributes.put("TypeMissingDeprecatedAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_DEPRECATED_ANNOTATION));
1451
		expectedProblemAttributes.put("TypeMissingDeprecatedAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_DEPRECATED_ANNOTATION));

Return to bug 163194