diff graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/TypeSystemMethodParser.java @ 18782:3ea386a1036f

Truffle-DSL: breaking: @TypeCheck and @TypeCast now require casted/checked type as explicit parameter. Previously the type was parsed from the method name. (GRAAL-446 #resolve)
author Christian Humer <christian.humer@gmail.com>
date Mon, 05 Jan 2015 20:23:22 +0100
parents 23415229349b
children 18c0f02fa4d2
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/TypeSystemMethodParser.java	Mon Jan 05 20:23:22 2015 +0100
+++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/TypeSystemMethodParser.java	Mon Jan 05 20:23:22 2015 +0100
@@ -23,6 +23,7 @@
 package com.oracle.truffle.dsl.processor.parser;
 
 import javax.lang.model.element.*;
+import javax.lang.model.type.*;
 
 import com.oracle.truffle.api.dsl.*;
 import com.oracle.truffle.dsl.processor.*;
@@ -40,28 +41,18 @@
         return ElementUtils.findAnnotationMirror(getContext().getEnvironment(), method, getAnnotationType()) != null;
     }
 
-    protected TypeData findTypeByMethodName(String methodName, String prefix) {
-        String typeName = methodName.substring(prefix.length(), methodName.length());
-        TypeData type = getTypeSystem().findType(typeName);
-        return type;
-    }
-
-    protected TypeData findTypeByMethodName(TemplateMethod method, String prefix) {
-        String methodName = method.getMethodName();
-        if (!methodName.startsWith(prefix)) {
-            String annotationName = ElementUtils.getSimpleName(method.getMessageAnnotation().getAnnotationType());
-            method.addError("Methods annotated with %s must match the pattern '%s'.", annotationName, String.format("%s${typeName}", prefix));
+    protected final TypeData resolveCastOrCheck(TemplateMethod method) {
+        Class<?> annotationType = getAnnotationType();
+        TypeMirror targetTypeMirror = ElementUtils.getAnnotationValue(TypeMirror.class, method.getMessageAnnotation(), "value");
+        TypeData targetType = getTypeSystem().findTypeData(targetTypeMirror);
+        if (targetType == null) {
+            method.addError("The type '%s' is not declared in the @%s.", ElementUtils.getSimpleName(targetTypeMirror), TypeSystem.class.getSimpleName());
             return null;
         }
-        String typeName = methodName.substring(prefix.length(), methodName.length());
-        TypeData type = getTypeSystem().findType(typeName);
-        if (type == null) {
-            String annotationName = TypeSystem.class.getSimpleName();
-            method.addError("Type '%s' is not declared in this @%s.", typeName, annotationName);
-            return null;
+        if (!method.getMethod().getModifiers().contains(Modifier.PUBLIC) || !method.getMethod().getModifiers().contains(Modifier.STATIC)) {
+            method.addError("@%s annotated method %s must be public and static.", annotationType.getSimpleName(), method.getMethodName());
         }
-
-        return type;
+        return targetType;
     }
 
 }