[
https://issues.apache.org/jira/browse/GROOVY-9472?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17507373#comment-17507373
]
Paul King commented on GROOVY-9472:
-----------------------------------
[~blackdrag] I don't think anything has changed w.r.t the normal compilation
path/usage for @Builder which has been identified as a potential issue before
(GROOVY-8803). In dynamic style (the context assumed in the design of most of
the current strategies), you might rarely need to reference the builder class
and can proceed as normal. For static typing scenarios or cases like the
@Delegate combination mentioned in GROOVY-8803, it would be good to have access
to the builder class. We could take some steps forward by making something like
a Buildable<T> interface (would be Buildable<Person> in the above example). The
Default and External strategies could add this interface for example and we'd
need a way to make that happen early, e.g. CONVERSION. A similar trick might
fix the similar @Delegate with joint compilation issue discussed previously
(GROOVY-8105) if we could get it to work. This might not address all use cases
but might be a very useful step forward.
> Static import causes unresolved reference to become resolved
> ------------------------------------------------------------
>
> Key: GROOVY-9472
> URL: https://issues.apache.org/jira/browse/GROOVY-9472
> Project: Groovy
> Issue Type: Bug
> Components: Compiler, Static Type Checker
> Affects Versions: 2.5.10
> Reporter: Daniil Ovchinnikov
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.0
>
>
> {code:groovy|title=com/foo/Person.groovy}
> package com.foo
> @groovy.transform.builder.Builder
> class Person {
> String name
> }
> {code}
> 1.
> {code:groovy|title=Main.groovy}
> import com.foo.Person
> class Main {
> static void main(String[] args) {
> Person.PersonBuilder pb = Person.builder()
> println(pb.build())
> }
> }
> {code}
> Trying to use it without a static import yields {{unable to resolve class
> Person.PersonBuilder}}, which is another issue.
> 2. Let's add a static import
> {code:groovy|title=Main.groovy}
> import com.foo.Person
> import static com.foo.Person.PersonBuilder
> class Main {
> static void main(String[] args) {
> PersonBuilder pb = Person.builder()
> println(pb.build())
> }
> }
> {code}
> The code compiles, but fails with {{java.lang.NoClassDefFoundError:
> PersonBuilder}} when run.
> 3. Let's add {{@CompileStatic}}
> {code:groovy|title=Main.groovy}
> import com.foo.Person
> import static com.foo.Person.PersonBuilder
> import groovy.transform.CompileStatic
> @CompileStatic
> class Main {
> static void main(String[] args) {
> PersonBuilder pb = Person.builder()
> println(pb.build())
> }
> }
> {code}
> Compilation fails with:
> {{Cannot assign value of type com.foo.Person$PersonBuilder to variable of
> type PersonBuilder}} and {{Cannot find matching method PersonBuilder#build()}}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)