Martin Häusler created GROOVY-10654:
---------------------------------------

             Summary: Cannot pass enum literal to ASTTransformationCustomizer
                 Key: GROOVY-10654
                 URL: https://issues.apache.org/jira/browse/GROOVY-10654
             Project: Groovy
          Issue Type: Bug
          Components: Compiler
    Affects Versions: 4.0.3
            Reporter: Martin Häusler


Please consider the following compiler configuration:
{code:java}
var config = new CompilerConfiguration();
var extensions = new ArrayList<String>()
var timedInterruptParams = new HashMap<String, Object>()

// this works (value is a constant):
timedInterruptParams.put("value", 100);

// this does not work (value is an enum literal):
timedInterruptParams.put("unit", TimeUnit.MILLISECONDS);
config.addCompilationCustomizers(
    new ASTTransformationCustomizer(timedInterruptParams, TimedInterrupt.class)
);
{code}

 According to the documentation of ASTTransformationCustomizer, it should be 
possible to override any property from the annotation (TimedInterrupt in this 
case) by storing it into the parameters map (with the name of the annotation 
field as key). While this works nicely for numbers and strings, it currently 
doesn't seem to work for enum literals. When this configuration is used to 
compile a script, the compiler will throw a runtime exception where it claims 
that "TimeUnit.MILLISECONDS is not a valid constant". This should be adressed, 
as enum literals are perceived as constants by most developers.

 

The following line is a valid workaround for the time being:
{code:java}
timedInterruptParams.put("unit", propX(classX(TimeUnit.class), 
TimeUnit.MILLISECONDS.toString()), {code}
 



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to