changeset 8456:d815f0ac9ed3

Merge.
author Christian Humer <christian.humer@gmail.com>
date Fri, 22 Mar 2013 19:50:51 +0100
parents 00d2e017073d (diff) 3b7e3b2306f0 (current diff)
children b27261747964 68b04162180e c36e8ded27d4
files graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/HotSpotMethodSubstitutionsTest.java graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/StandardMethodSubstitutionsTest.java
diffstat 1 files changed, 14 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.replacements.verifier/src/com/oracle/graal/replacements/verifier/MethodSubstitutionVerifier.java	Fri Mar 22 19:14:50 2013 +0100
+++ b/graal/com.oracle.graal.replacements.verifier/src/com/oracle/graal/replacements/verifier/MethodSubstitutionVerifier.java	Fri Mar 22 19:50:51 2013 +0100
@@ -186,16 +186,21 @@
         return originalMethod;
     }
 
-    private static boolean isTypeCompatible(TypeMirror originalType, TypeMirror substitutionType) {
-        /*
-         * TypeMirrors may contain generic types which deny the types to be equal. So if both types
-         * are declared we erase the generic types by comparing their corresponding declared
-         * element.
-         */
-        if (originalType.getKind() == TypeKind.DECLARED && substitutionType.getKind() == TypeKind.DECLARED) {
-            return ((DeclaredType) originalType).asElement().equals(((DeclaredType) substitutionType).asElement());
+    private boolean isTypeCompatible(TypeMirror originalType, TypeMirror substitutionType) {
+        TypeMirror original = originalType;
+        TypeMirror substitution = substitutionType;
+        if (needsErasure(original)) {
+            original = env.getTypeUtils().erasure(original);
         }
-        return originalType.equals(substitutionType);
+        if (needsErasure(substitution)) {
+            substitution = env.getTypeUtils().erasure(substitution);
+        }
+        return env.getTypeUtils().isSameType(original, substitution);
+    }
+
+    private static boolean needsErasure(TypeMirror typeMirror) {
+        return typeMirror.getKind() != TypeKind.NONE && typeMirror.getKind() != TypeKind.VOID && !typeMirror.getKind().isPrimitive() && typeMirror.getKind() != TypeKind.OTHER &&
+                        typeMirror.getKind() != TypeKind.NULL;
     }
 
     private static TypeElement findEnclosingClass(Element element) {