Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/ElementUtils.java @ 18770:2c669386b5d0
Truffle-DSL: fix crash if type in rewriteOn is not of type Throwable. Improved error messages for Specialization#rewriteOn.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 02 Jan 2015 14:31:51 +0100 |
parents | a665483c3881 |
children | c0fb70634640 |
comparison
equal
deleted
inserted
replaced
18769:144fba40c979 | 18770:2c669386b5d0 |
---|---|
986 if (isRuntimeException(exceptionType)) { | 986 if (isRuntimeException(exceptionType)) { |
987 return true; | 987 return true; |
988 } | 988 } |
989 | 989 |
990 // search for any super types | 990 // search for any super types |
991 TypeElement exceptionTypeElement = fromTypeMirror(exceptionType); | 991 for (TypeElement typeElement : getSuperTypes(fromTypeMirror(exceptionType))) { |
992 List<TypeElement> superTypes = getSuperTypes(exceptionTypeElement); | |
993 for (TypeElement typeElement : superTypes) { | |
994 if (ElementUtils.containsType(thrownTypes, typeElement.asType())) { | 992 if (ElementUtils.containsType(thrownTypes, typeElement.asType())) { |
995 return true; | 993 return true; |
996 } | 994 } |
997 } | 995 } |
998 | 996 |
1020 return null; | 1018 return null; |
1021 } | 1019 } |
1022 | 1020 |
1023 private static boolean isRuntimeException(TypeMirror type) { | 1021 private static boolean isRuntimeException(TypeMirror type) { |
1024 Set<String> typeSuperSet = new HashSet<>(getQualifiedSuperTypeNames(fromTypeMirror(type))); | 1022 Set<String> typeSuperSet = new HashSet<>(getQualifiedSuperTypeNames(fromTypeMirror(type))); |
1025 String typeName = getQualifiedName(type); | 1023 return typeSuperSet.contains(RuntimeException.class.getCanonicalName()) || getQualifiedName(type).equals(RuntimeException.class.getCanonicalName()); |
1026 if (!typeSuperSet.contains(Throwable.class.getCanonicalName()) && !typeName.equals(Throwable.class.getCanonicalName())) { | |
1027 throw new IllegalArgumentException("Given type does not extend Throwable."); | |
1028 } | |
1029 return typeSuperSet.contains(RuntimeException.class.getCanonicalName()) || typeName.equals(RuntimeException.class.getCanonicalName()); | |
1030 } | 1024 } |
1031 | 1025 |
1032 private static boolean containsType(Collection<? extends TypeMirror> collection, TypeMirror type) { | 1026 private static boolean containsType(Collection<? extends TypeMirror> collection, TypeMirror type) { |
1033 for (TypeMirror otherTypeMirror : collection) { | 1027 for (TypeMirror otherTypeMirror : collection) { |
1034 if (typeEquals(otherTypeMirror, type)) { | 1028 if (typeEquals(otherTypeMirror, type)) { |