groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefano Rocca <s.ro...@oandsi.it>
Subject Annotation on script
Date Fri, 12 Jun 2015 15:46:58 GMT
Hi,
we're using groovy.util.GroovyScriptEngine to run our scripts and we 
would like to use reflection on the Script class returned by 
createScript to get the annotations declared in the script, for example:

--- script1.groovy ---
package xxxx

@CustomAnnotation("xyz", description = "aaa bbb ccc")

println "Hello world!"

--- END ---

--- CustomAnnotation.java ---
package xxxx;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({   ElementType.METHOD,         ElementType.TYPE,
             ElementType.CONSTRUCTOR,    ElementType.FIELD,
             ElementType.LOCAL_VARIABLE, ElementType.PACKAGE
})
public @interface CustomAnnotation {

     String value() default "";
     String description() default "";

}

--- END ---

if we execute

Script s = groovyScriptEngine.createScript("script1.groovy", new 
Binding()); // groovyScriptEngine is an instance of 
groovy.util.GroovyScriptEngine

we cannot find the annotation CustomAnnotation anywhere in Script s 
(i.e.: s.getClass().getAnnotations() is empty)

Is it possible to obtain such annotation?

Thanks in advance.

Stefano


Mime
View raw message