[
https://issues.apache.org/jira/browse/GROOVY-7501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14623994#comment-14623994
]
ASF GitHub Bot commented on GROOVY-7501:
----------------------------------------
GitHub user Controlix opened a pull request:
https://github.com/apache/incubator-groovy/pull/60
GROOVY-7501: omit package name from builder class name
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/Controlix/incubator-groovy master
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-groovy/pull/60.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #60
----
commit 91c4d5a033f600f8b584811affeaf012df7bcc60
Author: Marc Bogaerts <[email protected]>
Date: 2015-07-12T20:28:58Z
GROOVY-7501: omit package name from builder class name
----
> Builder class name should not contain package name
> --------------------------------------------------
>
> Key: GROOVY-7501
> URL: https://issues.apache.org/jira/browse/GROOVY-7501
> Project: Groovy
> Issue Type: Bug
> Components: ast builder
> Affects Versions: 2.4.3
> Reporter: Marc Bogaerts
> Assignee: Guillaume Laforge
> Priority: Minor
> Original Estimate: 10m
> Remaining Estimate: 10m
>
> When creating a builder for a class not in the default package, the builder
> class name includes the package name. This makes the builder unsusable from
> java code.
> Example:
> {code:title=Person.groovy}
> package alfa.beta
> import groovy.transform.ToString
> import groovy.transform.builder.Builder
> @ToString
> @Builder // (builderClassName='PersonBuilder')
> class Person {
> String name
> String firstName
> Date birthDate
> }
> {code}
> {code:title=Show.java}
> package alfa.beta;
> public class Show {
> public static void main(String[] args) {
> Person lance = new Person();
> lance.setFirstName("Lance");
> lance.setName("Von Trier");
> System.out.println("Hello from " + lance);
> Person rick =
> Person.builder().name("Ashley").firstName("Rick").build();
> System.out.println("Hello from " + rick + " too");
> }
> }
> {code}
> When trying to comilpile the java class I get a 'class not found' error:
> {noformat}
> :compileJava
> /home/marc/dev/workspace-groovy/java-package/src/main/java/Show.java:10:
> error: cannot access alfa.beta.PersonBuilder
> Person rick =
> Person.builder().name("Ashley").firstName("Rick").build();
> ^
> class file for alfa.beta.Person$alfa.beta.PersonBuilder not found
> 1 error
> :compileJava FAILED
> {noformat}
> If I uncomment the (builderClassName='PersonBuilder') then the java code
> compiles fine.
> {noformat}
> :compileJava
> :processResources UP-TO-DATE
> :classes
> :run
> Hello from alfa.beta.Person(Von Trier, Lance, null)
> Hello from alfa.beta.Person(Ashley, Rick, null) too
> BUILD SUCCESSFUL
> {noformat}
> The problem boils down to the creation of the builder class name in
> groovy.transform.builder.DefaultStrategy and
> groovy.transform.builder.InitializerStrategy. Replacing the code
> buildee.getName() to buildee.getNameWithoutPackage() solves the problem.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)