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/10/19 20:48:28 UTC

[jira] [Commented] (GROOVY-7640) AST Builder should include superclass properties

    [ https://issues.apache.org/jira/browse/GROOVY-7640?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14963824#comment-14963824 ] 

Marc Bogaerts commented on GROOVY-7640:
---------------------------------------

I'd love to participate in the resolution of the bug. Therefor I would like to get some help how to best write a test that shows the bug. I've had a look at the builder tests, but they all rely on groovy scripts. However in the case of groovy scripts, the problem is less visible since groovy will compile and run the code in some cases, since the necessary methods exist at runtime and types will eventually match.

So I'm looking for help how to best write such a test in plain java.

> AST Builder should include superclass properties
> ------------------------------------------------
>
>                 Key: GROOVY-7640
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7640
>             Project: Groovy
>          Issue Type: Bug
>          Components: ast builder
>    Affects Versions: 2.4.5
>            Reporter: Marc Bogaerts
>            Priority: Minor
>
> If one annotates a groovy class with @Builder and that class extends from another class, then the generated builder does not support setting the parent class properties.
> This is especially problematic when mixin groovy builders in java code.
> e.g. the following class shows what will and will not compile
> {code:java}
> // Animal.groovy
> import groovy.transform.builder.Builder
> import groovy.transform.builder.SimpleStrategy
> @Builder(builderStrategy = SimpleStrategy)
> class Animal {
>    String color
>     int legs
> }
> // Pet.groovy
> import groovy.transform.builder.Builder
> import groovy.transform.builder.SimpleStrategy
> @Builder(builderStrategy = SimpleStrategy)
> class Pet extends Animal {
>     String name
> }
> // PetTest.java
> import org.junit.Test;
> import static org.junit.Assert.*;
> public class PetTest {
>     @Test public void createPet() {
>         // Pet pet = new Pet().setColor("white").setLegs(4).setName("Bobby"); does not compile
>         Pet pet = (Pet) new Pet().setName("Bobby").setColor("white").setLegs(4);
>         assertTrue(pet.getLegs() == 4);
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)