I am trying to do something like the Builder annotation, I am adding a new
inner class to a class with my custom annotation. It is unclear where I
should add it because if I wait to do this in an AST transformation in
SEMANTIC_ANALYSIS phase, any use of this type results in an error in the
resolve phase because it does not exist yet. What is the right way to add a
new class generated (and used later on in code) during compile time to the
module node?

regards
Saravanan


On Wed, Jun 4, 2025 at 9:59 AM Saravanan Palanichamy <chava...@gmail.com>
wrote:

> Hello Users
>
> I am trying to use the builder annotation and am seeing compile errors. I
> am not sure if I am doing something wrong
>
> package com.my.builder
>>
>> import groovy.transform.builder.Builder
>>
>> @Builder(builderClassName = "MyBuilder")
>> class NoMembers {
>>     private int privateInt;
>>     public int publicInt;
>>     static int staticInt = 1;
>> }
>>
>> class MyOtherClass {
>>     public boolean containsValidFieldValues(List<Integer>
>> expectedFieldValues) {
>>         new NoMembers.MyBuilder().build()
>>     }
>> }
>
>
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
> failed:
> 14: unable to resolve class NoMembers.MyBuilder
>  @ line 14, column 9.
>            new NoMembers.MyBuilder().build()
>            ^
>
> I am using this single line to compile
>
>> GroovyClassLoader().parseClass(File("testdata/plugins/Builder.groovy"))
>
>
> It looks like the builder annotation is adding a new class and this
> happens after the resolver caused the compile error. Any help is
> appreciated.
>
> regards
> Saravanan
>

Reply via email to