Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2017-04-09 19:03:54 +0000
committerStephan Herrmann2017-04-09 19:03:54 +0000
commitdc6e539f1543a55b703775e31c7eb90500565bee (patch)
treeeeec593dca3d64972e70ce1e997393e5621953f0
parent0da3c2bfd41bdb1134fb297a803d154ee2ea7998 (diff)
downloadeclipse.jdt.core-dc6e539f1543a55b703775e31c7eb90500565bee.tar.gz
eclipse.jdt.core-dc6e539f1543a55b703775e31c7eb90500565bee.tar.xz
eclipse.jdt.core-dc6e539f1543a55b703775e31c7eb90500565bee.zip
Bug 506653: Eclipse claims about duplicated method declarationI20170409-2000
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java40
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java48
2 files changed, 67 insertions, 21 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java
index f1e4c53c45..4b1422ed61 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java
@@ -14327,4 +14327,44 @@ public void testBug500673() {
"The type mfa must implement the inherited abstract method mfi.a(Throwable)\n" +
"----------\n");
}
+public void testBug506653() {
+ runConformTest(
+ false, // flushOutputDirectory
+ new String[] {
+ "A.java",
+ " public class A {\n" +
+ " public class B {\n" +
+ " <E extends Object, F extends E> E bar(F x) {\n" +
+ " return null;\n" +
+ " }\n" +
+ " }\n" +
+ " public class C extends B {\n" +
+ " @Override\n" +
+ " public String bar(Object x) {\n" +
+ " return \"Oops\";\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " new A().test();\n" +
+ " }\n" +
+ " void test() {\n" +
+ " B b = new C();\n" +
+ " try {\n" +
+ " Integer i = b.bar(1);\n" +
+ " } catch (ClassCastException cce) {\n" +
+ " System.out.print(\"cce\");\n" +
+ " }\n" +
+ " }\n" +
+ " }\n"
+ },
+ "----------\n" +
+ "1. WARNING in A.java (at line 9)\n" +
+ " public String bar(Object x) {\n" +
+ " ^^^^^^\n" +
+ "Type safety: The return type String for bar(Object) from the type A.C needs unchecked conversion to conform to E from the type A.B\n" +
+ "----------\n",
+ "cce",
+ "",
+ JavacTestOptions.DEFAULT);
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java
index 934a4835f6..4636fdd8fe 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java
@@ -192,31 +192,37 @@ public MethodBinding asRawMethod(LookupEnvironment env) {
int length = this.typeVariables.length;
TypeBinding[] arguments = new TypeBinding[length];
for (int i = 0; i < length; i++) {
- TypeVariableBinding var = this.typeVariables[i];
- if (var.boundsCount() <= 1) {
- arguments[i] = env.convertToRawType(var.upperBound(), false /*do not force conversion of enclosing types*/);
+ arguments[i] = makeRawArgument(env, this.typeVariables[i]);
+ }
+ return env.createParameterizedGenericMethod(this, arguments);
+}
+private TypeBinding makeRawArgument(LookupEnvironment env, TypeVariableBinding var) {
+ if (var.boundsCount() <= 1) {
+ TypeBinding upperBound = var.upperBound();
+ if (upperBound.isTypeVariable())
+ return makeRawArgument(env, (TypeVariableBinding) upperBound);
+ return env.convertToRawType(upperBound, false /*do not force conversion of enclosing types*/);
+ } else {
+ // use an intersection type to retain full bound information if more than 1 bound
+ TypeBinding[] itsSuperinterfaces = var.superInterfaces();
+ int superLength = itsSuperinterfaces.length;
+ TypeBinding rawFirstBound = null;
+ TypeBinding[] rawOtherBounds = null;
+ if (var.boundsCount() == superLength) {
+ rawFirstBound = env.convertToRawType(itsSuperinterfaces[0], false);
+ rawOtherBounds = new TypeBinding[superLength - 1];
+ for (int s = 1; s < superLength; s++)
+ rawOtherBounds[s - 1] = env.convertToRawType(itsSuperinterfaces[s], false);
} else {
- // use an intersection type to retain full bound information if more than 1 bound
- TypeBinding[] itsSuperinterfaces = var.superInterfaces();
- int superLength = itsSuperinterfaces.length;
- TypeBinding rawFirstBound = null;
- TypeBinding[] rawOtherBounds = null;
- if (var.boundsCount() == superLength) {
- rawFirstBound = env.convertToRawType(itsSuperinterfaces[0], false);
- rawOtherBounds = new TypeBinding[superLength - 1];
- for (int s = 1; s < superLength; s++)
- rawOtherBounds[s - 1] = env.convertToRawType(itsSuperinterfaces[s], false);
- } else {
- rawFirstBound = env.convertToRawType(var.superclass(), false);
- rawOtherBounds = new TypeBinding[superLength];
- for (int s = 0; s < superLength; s++)
- rawOtherBounds[s] = env.convertToRawType(itsSuperinterfaces[s], false);
- }
- arguments[i] = env.createWildcard(null, 0, rawFirstBound, rawOtherBounds, org.eclipse.jdt.internal.compiler.ast.Wildcard.EXTENDS);
+ rawFirstBound = env.convertToRawType(var.superclass(), false);
+ rawOtherBounds = new TypeBinding[superLength];
+ for (int s = 0; s < superLength; s++)
+ rawOtherBounds[s] = env.convertToRawType(itsSuperinterfaces[s], false);
}
+ return env.createWildcard(null, 0, rawFirstBound, rawOtherBounds, org.eclipse.jdt.internal.compiler.ast.Wildcard.EXTENDS);
}
- return env.createParameterizedGenericMethod(this, arguments);
}
+
/* Answer true if the receiver is visible to the type provided by the scope.
* InvocationSite implements isSuperAccess() to provide additional information
* if the receiver is protected.

Back to the top