comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/SpecializationMethodParser.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 2db61eddcb97
children 08aa0372dad4
comparison
equal deleted inserted replaced
18769:144fba40c979 18770:2c669386b5d0
57 57
58 private SpecializationData parseSpecialization(TemplateMethod method) { 58 private SpecializationData parseSpecialization(TemplateMethod method) {
59 AnnotationValue rewriteValue = ElementUtils.getAnnotationValue(method.getMarkerAnnotation(), "rewriteOn"); 59 AnnotationValue rewriteValue = ElementUtils.getAnnotationValue(method.getMarkerAnnotation(), "rewriteOn");
60 List<TypeMirror> exceptionTypes = ElementUtils.getAnnotationValueList(TypeMirror.class, method.getMarkerAnnotation(), "rewriteOn"); 60 List<TypeMirror> exceptionTypes = ElementUtils.getAnnotationValueList(TypeMirror.class, method.getMarkerAnnotation(), "rewriteOn");
61 List<SpecializationThrowsData> exceptionData = new ArrayList<>(); 61 List<SpecializationThrowsData> exceptionData = new ArrayList<>();
62 List<TypeMirror> rewriteOnTypes = new ArrayList<>();
62 for (TypeMirror exceptionType : exceptionTypes) { 63 for (TypeMirror exceptionType : exceptionTypes) {
63 SpecializationThrowsData throwsData = new SpecializationThrowsData(method.getMarkerAnnotation(), rewriteValue, exceptionType); 64 SpecializationThrowsData throwsData = new SpecializationThrowsData(method.getMarkerAnnotation(), rewriteValue, exceptionType);
64 if (!ElementUtils.canThrowType(method.getMethod().getThrownTypes(), exceptionType)) { 65 if (!ElementUtils.canThrowType(method.getMethod().getThrownTypes(), exceptionType)) {
65 throwsData.addError("Method must specify a throws clause with the exception type '%s'.", ElementUtils.getQualifiedName(exceptionType)); 66 method.addError("A rewriteOn checked exception was specified but not thrown in the method's throws clause. The @%s method must specify a throws clause with the exception type '%s'.",
67 Specialization.class.getSimpleName(), ElementUtils.getQualifiedName(exceptionType));
66 } 68 }
69 rewriteOnTypes.add(throwsData.getJavaClass());
67 exceptionData.add(throwsData); 70 exceptionData.add(throwsData);
71 }
72
73 for (TypeMirror typeMirror : method.getMethod().getThrownTypes()) {
74 if (!ElementUtils.canThrowType(rewriteOnTypes, typeMirror)) {
75 method.addError(rewriteValue,
76 "A checked exception '%s' is thrown but is not specified using the rewriteOn property. Checked exceptions that are not used for rewriting are not handled by the DSL. Use RuntimeExceptions for this purpose instead.",
77 ElementUtils.getQualifiedName(typeMirror));
78 }
68 } 79 }
69 80
70 Collections.sort(exceptionData, new Comparator<SpecializationThrowsData>() { 81 Collections.sort(exceptionData, new Comparator<SpecializationThrowsData>() {
71 82
72 @Override 83 @Override