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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (-16 / +30 lines)
Lines 19-24 Link Here
19
import org.eclipse.jdt.core.ToolFactory;
19
import org.eclipse.jdt.core.ToolFactory;
20
import org.eclipse.jdt.core.tests.util.Util;
20
import org.eclipse.jdt.core.tests.util.Util;
21
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
21
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
22
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
22
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
23
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
23
24
24
public class GenericTypeTest extends AbstractComparableTest {
25
public class GenericTypeTest extends AbstractComparableTest {
Lines 31156-31161 Link Here
31156
}
31157
}
31157
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140643
31158
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140643
31158
public void test0987() {
31159
public void test0987() {
31160
	String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6
31161
	?	"----------\n" + 
31162
		"1. ERROR in X.java (at line 7)\n" + 
31163
		"	abstract class GLinkElementView<M,CM> extends AbstractLinkView<M> {}\n" + 
31164
		"	               ^^^^^^^^^^^^^^^^\n" + 
31165
		"The return type is incompatible with EditPart.getViewer(), AbstractLinkView<M>.getViewer()\n" + 
31166
		"----------\n" + 
31167
		"2. ERROR in X.java (at line 11)\n" + 
31168
		"	public ISheetViewer getViewer() { return null; }	\n" + 
31169
		"	                    ^^^^^^^^^^^\n" + 
31170
		"The return type is incompatible with EditPart.getViewer()\n" + 
31171
		"----------\n" + 
31172
		"3. ERROR in X.java (at line 11)\n" + 
31173
		"	public ISheetViewer getViewer() { return null; }	\n" + 
31174
		"	                    ^^^^^^^^^^^\n" + 
31175
		"The method getViewer() of type AbstractLinkView<M> must override a superclass method\n" + 
31176
		"----------\n"
31177
	:	"----------\n" + 
31178
		"1. ERROR in X.java (at line 7)\n" + 
31179
		"	abstract class GLinkElementView<M,CM> extends AbstractLinkView<M> {}\n" + 
31180
		"	               ^^^^^^^^^^^^^^^^\n" + 
31181
		"The return type is incompatible with EditPart.getViewer(), AbstractLinkView<M>.getViewer()\n" + 
31182
		"----------\n" + 
31183
		"2. ERROR in X.java (at line 11)\n" + 
31184
		"	public ISheetViewer getViewer() { return null; }	\n" + 
31185
		"	                    ^^^^^^^^^^^\n" + 
31186
		"The return type is incompatible with EditPart.getViewer()\n" + 
31187
		"----------\n";	
31159
	this.runNegativeTest(
31188
	this.runNegativeTest(
31160
			new String[] {
31189
			new String[] {
31161
				"X.java",//===================
31190
				"X.java",//===================
Lines 31190-31211 Link Here
31190
				"\n" + 
31219
				"\n" + 
31191
				"interface EditPartViewer {}\n", // =================			
31220
				"interface EditPartViewer {}\n", // =================			
31192
			},
31221
			},
31193
			"----------\n" + 
31222
			expectedOutput);
31194
			"1. ERROR in X.java (at line 7)\n" + 
31195
			"	abstract class GLinkElementView<M,CM> extends AbstractLinkView<M> {}\n" + 
31196
			"	               ^^^^^^^^^^^^^^^^\n" + 
31197
			"The return type is incompatible with EditPart.getViewer(), AbstractLinkView<M>.getViewer()\n" + 
31198
			"----------\n" + 
31199
			"2. ERROR in X.java (at line 11)\n" + 
31200
			"	public ISheetViewer getViewer() { return null; }	\n" + 
31201
			"	                    ^^^^^^^^^^^\n" + 
31202
			"The return type is incompatible with EditPart.getViewer()\n" + 
31203
			"----------\n" + 
31204
			"3. ERROR in X.java (at line 11)\n" + 
31205
			"	public ISheetViewer getViewer() { return null; }	\n" + 
31206
			"	                    ^^^^^^^^^^^\n" + 
31207
			"The method getViewer() of type AbstractLinkView<M> must override a superclass method\n" + 
31208
			"----------\n");
31209
}
31223
}
31210
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140643 - variation
31224
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140643 - variation
31211
public void test0988() {
31225
public void test0988() {
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java (-23 / +113 lines)
Lines 2437-2442 Link Here
2437
	}	
2437
	}	
2438
	// check @Override annotation - strictly for superclasses (overrides) and not interfaces (implements)
2438
	// check @Override annotation - strictly for superclasses (overrides) and not interfaces (implements)
2439
	public void test077() {
2439
	public void test077() {
2440
		String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6
2441
			?	"----------\n" + 
2442
				"1. ERROR in X.java (at line 14)\n" + 
2443
				"	void foo() {}\n" + 
2444
				"	     ^^^^^\n" + 
2445
				"The method foo() of type X must override a superclass method\n" + 
2446
				"----------\n" + 
2447
				"2. ERROR in X.java (at line 18)\n" + 
2448
				"	public void baz() {}\n" + 
2449
				"	            ^^^^^\n" + 
2450
				"The method baz() of type X must override a superclass method\n" + 
2451
				"----------\n"
2452
			:	"----------\n" + 
2453
				"1. ERROR in X.java (at line 14)\n" + 
2454
				"	void foo() {}\n" + 
2455
				"	     ^^^^^\n" + 
2456
				"The method foo() of type X must override a superclass method\n" + 
2457
				"----------\n";
2440
		this.runNegativeTest(
2458
		this.runNegativeTest(
2441
			new String[] {
2459
			new String[] {
2442
				"X.java",
2460
				"X.java",
Lines 2460-2476 Link Here
2460
				"	public void baz() {}\n" + 
2478
				"	public void baz() {}\n" + 
2461
				"}\n"
2479
				"}\n"
2462
			},
2480
			},
2463
			"----------\n" + 
2481
			expectedOutput);
2464
			"1. ERROR in X.java (at line 14)\n" + 
2465
			"	void foo() {}\n" + 
2466
			"	     ^^^^^\n" + 
2467
			"The method foo() of type X must override a superclass method\n" + 
2468
			"----------\n" + 
2469
			"2. ERROR in X.java (at line 18)\n" + 
2470
			"	public void baz() {}\n" + 
2471
			"	            ^^^^^\n" + 
2472
			"The method baz() of type X must override a superclass method\n" + 
2473
			"----------\n");
2474
	}
2482
	}
2475
	
2483
	
2476
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=80114
2484
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=80114
Lines 5611-5617 Link Here
5611
    }
5619
    }
5612
    //https://bugs.eclipse.org/bugs/show_bug.cgi?id=94759
5620
    //https://bugs.eclipse.org/bugs/show_bug.cgi?id=94759
5613
    public void test168() {
5621
    public void test168() {
5614
        this.runNegativeTest(
5622
    	String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6
5623
			?	"----------\n" + 
5624
				"1. ERROR in X.java (at line 2)\n" + 
5625
				"	@Override I clone();\n" + 
5626
				"	            ^^^^^^^\n" + 
5627
				"The method clone() of type I must override a superclass method\n" + 
5628
				"----------\n" + 
5629
				"2. ERROR in X.java (at line 7)\n" + 
5630
				"	@Override void foo();\n" + 
5631
				"	               ^^^^^\n" + 
5632
				"The method foo() of type J must override a superclass method\n" + 
5633
				"----------\n"
5634
			:	"----------\n" + 
5635
				"1. ERROR in X.java (at line 2)\n" + 
5636
				"	@Override I clone();\n" + 
5637
				"	            ^^^^^^^\n" + 
5638
				"The method clone() of type I must override a superclass method\n" + 
5639
				"----------\n";
5640
    	this.runNegativeTest(
5615
            new String[] {
5641
            new String[] {
5616
                "X.java",
5642
                "X.java",
5617
				"interface I {\n" + 
5643
				"interface I {\n" + 
Lines 5623-5639 Link Here
5623
				"	@Override void foo();\n" + 
5649
				"	@Override void foo();\n" + 
5624
				"}\n",
5650
				"}\n",
5625
           },
5651
           },
5626
		"----------\n" + 
5652
           expectedOutput);
5627
		"1. ERROR in X.java (at line 2)\n" + 
5628
		"	@Override I clone();\n" + 
5629
		"	            ^^^^^^^\n" + 
5630
		"The method clone() of type I must override a superclass method\n" + 
5631
		"----------\n" + 
5632
		"2. ERROR in X.java (at line 7)\n" + 
5633
		"	@Override void foo();\n" + 
5634
		"	               ^^^^^\n" + 
5635
		"The method foo() of type J must override a superclass method\n" + 
5636
		"----------\n");
5637
    }
5653
    }
5638
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220
5654
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220
5639
    public void test169() {
5655
    public void test169() {
Lines 7005-7008 Link Here
7005
		"The array creation is unnecessary in an annotation value; only an array initializer is allowed\n" + 
7021
		"The array creation is unnecessary in an annotation value; only an array initializer is allowed\n" + 
7006
		"----------\n");
7022
		"----------\n");
7007
}
7023
}
7024
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=141931
7025
public void test214() {
7026
	String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6
7027
		?	"----------\n" + 
7028
			"1. ERROR in X.java (at line 3)\n" + 
7029
			"	void foo();\n" + 
7030
			"	     ^^^^^\n" + 
7031
			"The method foo() of type I must override a superclass method\n" + 
7032
			"----------\n" + 
7033
			"2. ERROR in X.java (at line 8)\n" + 
7034
			"	public void foo() {}\n" + 
7035
			"	            ^^^^^\n" + 
7036
			"The method foo() of type X must override a superclass method\n" + 
7037
			"----------\n" + 
7038
			"3. ERROR in X.java (at line 13)\n" + 
7039
			"	void foo();\n" + 
7040
			"	     ^^^^^\n" + 
7041
			"The method foo() of type J must override a superclass method\n" + 
7042
			"----------\n"
7043
		:	"----------\n" + 
7044
			"1. ERROR in X.java (at line 3)\n" + 
7045
			"	void foo();\n" + 
7046
			"	     ^^^^^\n" + 
7047
			"The method foo() of type I must override a superclass method\n" + 
7048
			"----------\n";
7049
    this.runNegativeTest(
7050
        new String[] {
7051
            "X.java",
7052
			"interface I {\n" + 
7053
			"  @Override\n" + 
7054
			"  void foo();\n" + 
7055
			"  void bar();\n" + 
7056
			"}\n" + 
7057
			"public class X implements I {\n" + 
7058
			"  @Override\n" + 
7059
			"  public void foo() {}\n" + 
7060
			"  public void bar() {}\n" + 
7061
			"}\n" + 
7062
			"interface J extends I {\n" + 
7063
			"	@Override\n" + 
7064
			"	void foo();\n" + 
7065
			"}\n",
7066
        },
7067
        expectedOutput);
7068
}
7069
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=141931
7070
// variant
7071
public void test215() {
7072
	String sources[] = new String[] {
7073
		"I.java",
7074
		"public interface I {\n" + 
7075
		"  void foo();\n" + 
7076
		"}\n",
7077
		"X.java",
7078
		"abstract class X implements I {\n" + 
7079
		"}\n",
7080
		"Y.java",
7081
		"class Y extends X {\n" + 
7082
		"  @Override\n" +
7083
		"  public void foo() {}\n" +
7084
		"}\n"};
7085
	if (new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6) {
7086
		this.runNegativeTest(sources,
7087
			"----------\n" + 
7088
			"1. ERROR in Y.java (at line 3)\r\n" + 
7089
			"	public void foo() {}\r\n" + 
7090
			"	            ^^^^^\n" + 
7091
			"The method foo() of type Y must override a superclass method\n" + 
7092
			"----------\n");
7093
	} else {
7094
		this.runConformTest(sources,
7095
			"");
7096
	}
7097
}
7008
}
7098
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java (-3 / +14 lines)
Lines 17-22 Link Here
17
import org.eclipse.jdt.internal.compiler.flow.ExceptionHandlingFlowContext;
17
import org.eclipse.jdt.internal.compiler.flow.ExceptionHandlingFlowContext;
18
import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
18
import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
19
import org.eclipse.jdt.internal.compiler.flow.InitializationFlowContext;
19
import org.eclipse.jdt.internal.compiler.flow.InitializationFlowContext;
20
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
20
import org.eclipse.jdt.internal.compiler.lookup.*;
21
import org.eclipse.jdt.internal.compiler.lookup.*;
21
import org.eclipse.jdt.internal.compiler.parser.*;
22
import org.eclipse.jdt.internal.compiler.parser.*;
22
import org.eclipse.jdt.internal.compiler.problem.AbortMethod;
23
import org.eclipse.jdt.internal.compiler.problem.AbortMethod;
Lines 142-158 Link Here
142
		}
143
		}
143
		
144
		
144
		// check @Override annotation
145
		// check @Override annotation
146
		final CompilerOptions compilerOptions = this.scope.compilerOptions();
145
		checkOverride: {
147
		checkOverride: {
146
			if (this.binding == null) break checkOverride;
148
			if (this.binding == null) break checkOverride;
147
			if (this.scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_5) break checkOverride;
149
			long sourceLevel = compilerOptions.sourceLevel;
150
			if (sourceLevel < ClassFileConstants.JDK1_5) break checkOverride;
148
			int bindingModifiers = this.binding.modifiers;
151
			int bindingModifiers = this.binding.modifiers;
149
			boolean hasOverrideAnnotation = (this.binding.tagBits & TagBits.AnnotationOverride) != 0;
152
			boolean hasOverrideAnnotation = (this.binding.tagBits & TagBits.AnnotationOverride) != 0;
150
			boolean isInterfaceMethod = this.binding.declaringClass.isInterface();
153
			boolean isInterfaceMethod = this.binding.declaringClass.isInterface();
151
			if (hasOverrideAnnotation) {
154
			if (hasOverrideAnnotation) {
152
				if ((bindingModifiers & ExtraCompilerModifiers.AccOverriding) == 0 || isInterfaceMethod || this.binding.isStatic())
155
				// no static method is considered overriding
156
				if (!isInterfaceMethod && (bindingModifiers & (ClassFileConstants.AccStatic|ExtraCompilerModifiers.AccOverriding)) == ExtraCompilerModifiers.AccOverriding)
157
					break checkOverride;
158
				//	in 1.5, strictly for overriding superclass method
159
				//	in 1.6 and above, also tolerate implementing interface method
160
				if (sourceLevel >= ClassFileConstants.JDK1_6
161
						&& ((bindingModifiers & (ClassFileConstants.AccStatic|ExtraCompilerModifiers.AccImplementing)) == ExtraCompilerModifiers.AccImplementing))
162
					break checkOverride;
153
					// claims to override, and doesn't actually do so
163
					// claims to override, and doesn't actually do so
154
					this.scope.problemReporter().methodMustOverride(this);					
164
					this.scope.problemReporter().methodMustOverride(this);					
155
			} else if (!isInterfaceMethod 	&& (bindingModifiers & (ClassFileConstants.AccStatic|ExtraCompilerModifiers.AccOverriding)) == ExtraCompilerModifiers.AccOverriding) {
165
			} else if (!isInterfaceMethod 	
166
						&& (bindingModifiers & (ClassFileConstants.AccStatic|ExtraCompilerModifiers.AccOverriding)) == ExtraCompilerModifiers.AccOverriding) {
156
				// actually overrides, but did not claim to do so
167
				// actually overrides, but did not claim to do so
157
				this.scope.problemReporter().missingOverrideAnnotation(this);
168
				this.scope.problemReporter().missingOverrideAnnotation(this);
158
			}
169
			}

Return to bug 141931