Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTill Brychcy2017-07-09 15:55:39 +0000
committerTill Brychcy2017-11-26 13:54:42 +0000
commit1eb1eeafeb83314c2c9956f72dab41ada788a34c (patch)
tree63f8085f1be2a4ebc076621d4ee2cd32da2c2718
parenta2ee843b668ecf9aca7c99300671ad9c2845690b (diff)
downloadeclipse.jdt.core-1eb1eeafeb83314c2c9956f72dab41ada788a34c.tar.gz
eclipse.jdt.core-1eb1eeafeb83314c2c9956f72dab41ada788a34c.tar.xz
eclipse.jdt.core-1eb1eeafeb83314c2c9956f72dab41ada788a34c.zip
Bug 518157 - A Class<? extends RawType> = Impl.class where RawType is a
nested interface within a generic class fails compilation Change-Id: I143588b201a3374819d0c5dff068e986c73f0cbc
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java37
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotatableTypeSystem.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java24
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java3
5 files changed, 59 insertions, 13 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
index 3298610fd5..e618727ac5 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
@@ -6122,6 +6122,43 @@ public void testBug515614() {
}
);
}
+public void testBug518157A() {
+ runConformTest(
+ new String[] {
+ "RawClassParameterizationBug.java",
+ "class RawClassParameterizationBug<Oops> {\n" +
+ "\n" +
+ " public interface Example<K,V> {\n" +
+ " }\n" +
+ " \n" +
+ " public static class DefaultExample<K,V> implements Example<K,V> {\n" +
+ " }\n" +
+ " @SuppressWarnings(\"rawtypes\")\n" +
+ " static final Class<? extends Example> fails = DefaultExample.class;\n" +
+ "}\n" +
+ "",
+ }
+ );
+}
+public void testBug518157B() {
+ runConformTest(
+ new String[] {
+ "AlternateRawClassParameterizationBug.java",
+ "import java.util.Map;\n" +
+ "\n" +
+ "class AlternateRawClassParameterizationBug {\n" +
+ "\n" +
+ " abstract static class MapEntry<K,V> implements Map.Entry<K, V> {\n" +
+ " }\n" +
+ "\n" +
+ " @SuppressWarnings(\"rawtypes\")\n" +
+ " static final Class<? extends Map.Entry> mapFails = MapEntry.class;\n" +
+ "\n" +
+ "}\n" +
+ "",
+ }
+ );
+}
public void testBug521212() {
runNegativeTest(
new String[] {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotatableTypeSystem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotatableTypeSystem.java
index 54d0a7a2d4..ada1b75a5a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotatableTypeSystem.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotatableTypeSystem.java
@@ -134,9 +134,11 @@ public class AnnotatableTypeSystem extends TypeSystem {
}
public RawTypeBinding getRawType(ReferenceBinding genericType, ReferenceBinding enclosingType, AnnotationBinding [] annotations) {
-
if (genericType.hasTypeAnnotations())
throw new IllegalStateException();
+ if (genericType.isStatic() && enclosingType != null) {
+ enclosingType = (ReferenceBinding) enclosingType.original();
+ }
RawTypeBinding nakedType = null;
TypeBinding[] derivedTypes = getDerivedTypes(genericType);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java
index efa1fe1958..b0b4844263 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java
@@ -844,20 +844,24 @@ public TypeBinding convertToRawType(TypeBinding type, boolean forceRawEnclosingT
convertedType = needToConvert ? createRawType((ReferenceBinding)originalType.erasure(), null) : originalType;
} else {
ReferenceBinding convertedEnclosing;
- if (originalEnclosing.kind() == Binding.RAW_TYPE) {
- needToConvert |= !((ReferenceBinding)originalType).isStatic();
- convertedEnclosing = originalEnclosing;
- } else if (forceRawEnclosingType && !needToConvert/*stop recursion when conversion occurs*/) {
- convertedEnclosing = (ReferenceBinding) convertToRawType(originalEnclosing, forceRawEnclosingType);
- needToConvert = TypeBinding.notEquals(originalEnclosing, convertedEnclosing); // only convert generic or parameterized types
- } else if (needToConvert || ((ReferenceBinding)originalType).isStatic()) {
- convertedEnclosing = (ReferenceBinding) convertToRawType(originalEnclosing, false);
+ if(((ReferenceBinding)originalType).isStatic()) {
+ convertedEnclosing = (ReferenceBinding) originalEnclosing.original();
} else {
- convertedEnclosing = convertToParameterizedType(originalEnclosing);
+ if (originalEnclosing.kind() == Binding.RAW_TYPE) {
+ convertedEnclosing = originalEnclosing;
+ needToConvert = true;
+ } else if (forceRawEnclosingType && !needToConvert/*stop recursion when conversion occurs*/) {
+ convertedEnclosing = (ReferenceBinding) convertToRawType(originalEnclosing, forceRawEnclosingType);
+ needToConvert = TypeBinding.notEquals(originalEnclosing, convertedEnclosing); // only convert generic or parameterized types
+ } else if (needToConvert) {
+ convertedEnclosing = (ReferenceBinding) convertToRawType(originalEnclosing, false);
+ } else {
+ convertedEnclosing = convertToParameterizedType(originalEnclosing);
+ }
}
if (needToConvert) {
convertedType = createRawType((ReferenceBinding) originalType.erasure(), convertedEnclosing);
- } else if (TypeBinding.notEquals(originalEnclosing, convertedEnclosing) && !originalType.isStatic()) {
+ } else if (TypeBinding.notEquals(originalEnclosing, convertedEnclosing)) {
convertedType = createParameterizedType((ReferenceBinding) originalType.erasure(), null, convertedEnclosing);
} else {
convertedType = originalType;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java
index 5dcefd96d1..d3818a4829 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java
@@ -57,7 +57,7 @@ public class RawTypeBinding extends ParameterizedTypeBinding {
}
}
}
- if (enclosingType == null || (enclosingType.modifiers & ExtraCompilerModifiers.AccGenericSignature) == 0) {
+ if (enclosingType == null || this.isStatic() || (enclosingType.modifiers & ExtraCompilerModifiers.AccGenericSignature) == 0) {
this.modifiers &= ~ExtraCompilerModifiers.AccGenericSignature; // only need signature if enclosing needs one
}
}
@@ -145,7 +145,7 @@ public class RawTypeBinding extends ParameterizedTypeBinding {
this.genericTypeSignature = genericType().signature();
} else {
StringBuffer sig = new StringBuffer(10);
- if (isMemberType()) {
+ if (isMemberType() && !isStatic()) {
ReferenceBinding enclosing = enclosingType();
char[] typeSig = enclosing.genericTypeSignature();
sig.append(typeSig, 0, typeSig.length-1);// copy all but trailing semicolon
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java
index d63ca6673e..9ddd86f368 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java
@@ -335,6 +335,9 @@ public class TypeSystem {
they may and we need to materialize the unannotated versions and work on them.
*/
public RawTypeBinding getRawType(ReferenceBinding genericType, ReferenceBinding enclosingType) {
+ if (genericType.isStatic() && enclosingType != null) {
+ enclosingType = (ReferenceBinding) enclosingType.original();
+ }
ReferenceBinding unannotatedGenericType = (ReferenceBinding) getUnannotatedType(genericType);
ReferenceBinding unannotatedEnclosingType = enclosingType == null ? null : (ReferenceBinding) getUnannotatedType(enclosingType);

Back to the top