Thank you Paul for your response.

Yes, but if you change your code to this, I think it will fail. The problem
is that we are referencing the type and the resolver cannot find it. So the
real question I am trying to answer is how do I add classes in my AST
transformation (that I am using in the source code). Kinda like the Builder
annotation that creates the builder class.

Adding this during Semantic Analysis will fail in the resolver phase
because semantic analysis kicks in after the resolver and the resolver is
not able to find this type

regards
Saravanan

@Builder(builderClassName = "MyBuilder")
class NoMembers {
    private int privateInt;
    public int publicInt;
    static int staticInt = 1;
}

class MyOtherClass {
    public boolean containsValidFieldValues(List<Integer>
expectedFieldValues) {
        NoMembers.MyBuilder myBuilder = NoMembers.builder()
        myBuilder.build()
    }
}

assert new MyOtherClass().containsValidFieldValues([])


On Wed, Jun 4, 2025 at 9:56 PM Paul King <pa...@asert.com.au> wrote:

> This seems to work for me:
>
> 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) {
>         NoMembers.builder().build()
>     }
> }
>
> assert new MyOtherClass().containsValidFieldValues([])
>
> The normal usage is all set up to avoid any problems with class resolution.
>
> Cheers, Paul.
>
>
> On Thu, Jun 5, 2025 at 2: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