You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Marc Bogaerts (JIRA)" <ji...@apache.org> on 2015/07/12 22:11:04 UTC

[jira] [Updated] (GROOVY-7501) Builder class name should not contain package name

     [ https://issues.apache.org/jira/browse/GROOVY-7501?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Marc Bogaerts updated GROOVY-7501:
----------------------------------
    Description: 
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.

  was:
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') the 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.


> 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)