@TupleConstructor: what am I doing wrong?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

@TupleConstructor: what am I doing wrong?

mauromol

Hello all,
I'm getting crazy because I can't understand what I'm doing wrong.

Consider this (it can be pasted on the Groovy console):

import groovy.transform.TupleConstructor

public class Foobar {
  private Long id;
 
  public Long getId() { return this.id; }
  public void setId(Long id) { this.id = id; }
}

@TupleConstructor(includeSuperProperties=true)
class Ext extends Foobar {
  String foo
}

Ext.constructors.each {
    println it
}
println 'end'

The result is just:

public Ext(java.lang.String)
public Ext()
end

But isn't id a property (as per the Java beans conventions)???

If I replace includeSuperProperties=true with includeSuperFields=true, I get the expected result:

public Ext()
public Ext(java.lang.Long)
public Ext(java.lang.Long,java.lang.String)
end

But in more complex cases, includeSuperFields=true will include unwanted fields that are not actually properties.

What am I doing wrong?

Thanks in advance,
Mauro
Reply | Threaded
Open this post in threaded view
|

Re: @TupleConstructor: what am I doing wrong?

paulk_asert
I haven't checked the code yet but I think @Builder and @ToString originally had similar issues and we added an `allProperties` attribute with default true. Perhaps that is needed here too. I'll try to check the code shortly.

On Thu, Jan 11, 2018 at 11:57 PM, Mauro Molinari <[hidden email]> wrote:

Hello all,
I'm getting crazy because I can't understand what I'm doing wrong.

Consider this (it can be pasted on the Groovy console):

import groovy.transform.TupleConstructor

public class Foobar {
  private Long id;
 
  public Long getId() { return this.id; }
  public void setId(Long id) { this.id = id; }
}

@TupleConstructor(includeSuperProperties=true)
class Ext extends Foobar {
  String foo
}

Ext.constructors.each {
    println it
}
println 'end'

The result is just:

public Ext(java.lang.String)
public Ext()
end

But isn't id a property (as per the Java beans conventions)???

If I replace includeSuperProperties=true with includeSuperFields=true, I get the expected result:

public Ext()
public Ext(java.lang.Long)
public Ext(java.lang.Long,java.lang.String)
end

But in more complex cases, includeSuperFields=true will include unwanted fields that are not actually properties.

What am I doing wrong?

Thanks in advance,
Mauro

Reply | Threaded
Open this post in threaded view
|

Re: @TupleConstructor: what am I doing wrong?

mauromol
Hi Paul,
thank you! I can't see allProperties annotation attribute in any of those annotations, at least in Groovy 2.4.x.
Let me know if I should open a JIRA ticket about this.

But... by the way... why the need of such an attribute? What's the difference between properties included whatever value allProperties has and those that require allProperties=true?
If the base class is written in Java, I see the behaviour I described, so I guess all Java bean properties require allProperties=true in order to make includeSuperProperties work as expected?

Thanks,
Mauro

Il 11/01/2018 23:52, Paul King ha scritto:
I haven't checked the code yet but I think @Builder and @ToString originally had similar issues and we added an `allProperties` attribute with default true. Perhaps that is needed here too. I'll try to check the code shortly.

On Thu, Jan 11, 2018 at 11:57 PM, Mauro Molinari <[hidden email]> wrote:

Hello all,
I'm getting crazy because I can't understand what I'm doing wrong.

Consider this (it can be pasted on the Groovy console):

import groovy.transform.TupleConstructor

public class Foobar {
  private Long id;
 
  public Long getId() { return this.id; }
  public void setId(Long id) { this.id = id; }
}

@TupleConstructor(includeSuperProperties=true)
class Ext extends Foobar {
  String foo
}

Ext.constructors.each {
    println it
}
println 'end'

The result is just:

public Ext(java.lang.String)
public Ext()
end

But isn't id a property (as per the Java beans conventions)???

If I replace includeSuperProperties=true with includeSuperFields=true, I get the expected result:

public Ext()
public Ext(java.lang.Long)
public Ext(java.lang.Long,java.lang.String)
end

But in more complex cases, includeSuperFields=true will include unwanted fields that are not actually properties.

What am I doing wrong?

Thanks in advance,
Mauro


Reply | Threaded
Open this post in threaded view
|

Re: @TupleConstructor: what am I doing wrong?

paulk_asert
We originally didn't support JavaBean properties for most of the AST transformations. We added support and added an allProperties flag defaulting to true. Basically, this is an acknowledgement that we should be supporting those properties all along but if anyone is relying on the old behavior they can turn off that feature. I looked at the code and it would be easy to add in allProperties support, so yes, please create a Jira - and PR if you feel so inclined! :-)

Cheers, Paul.

On Fri, Jan 12, 2018 at 9:25 PM, Mauro Molinari <[hidden email]> wrote:
Hi Paul,
thank you! I can't see allProperties annotation attribute in any of those annotations, at least in Groovy 2.4.x.
Let me know if I should open a JIRA ticket about this.

But... by the way... why the need of such an attribute? What's the difference between properties included whatever value allProperties has and those that require allProperties=true?
If the base class is written in Java, I see the behaviour I described, so I guess all Java bean properties require allProperties=true in order to make includeSuperProperties work as expected?

Thanks,
Mauro


Il 11/01/2018 23:52, Paul King ha scritto:
I haven't checked the code yet but I think @Builder and @ToString originally had similar issues and we added an `allProperties` attribute with default true. Perhaps that is needed here too. I'll try to check the code shortly.

On Thu, Jan 11, 2018 at 11:57 PM, Mauro Molinari <[hidden email]> wrote:

Hello all,
I'm getting crazy because I can't understand what I'm doing wrong.

Consider this (it can be pasted on the Groovy console):

import groovy.transform.TupleConstructor

public class Foobar {
  private Long id;
 
  public Long getId() { return this.id; }
  public void setId(Long id) { this.id = id; }
}

@TupleConstructor(includeSuperProperties=true)
class Ext extends Foobar {
  String foo
}

Ext.constructors.each {
    println it
}
println 'end'

The result is just:

public Ext(java.lang.String)
public Ext()
end

But isn't id a property (as per the Java beans conventions)???

If I replace includeSuperProperties=true with includeSuperFields=true, I get the expected result:

public Ext()
public Ext(java.lang.Long)
public Ext(java.lang.Long,java.lang.String)
end

But in more complex cases, includeSuperFields=true will include unwanted fields that are not actually properties.

What am I doing wrong?

Thanks in advance,
Mauro



Reply | Threaded
Open this post in threaded view
|

Re: @TupleConstructor: what am I doing wrong?

mauromol
Hi Paul, thank you! I opened GROOVY-8453.

Mauro

Il 13/01/2018 00:52, Paul King ha scritto:
> We originally didn't support JavaBean properties for most of the AST
> transformations. We added support and added an allProperties flag
> defaulting to true. Basically, this is an acknowledgement that we
> should be supporting those properties all along but if anyone is
> relying on the old behavior they can turn off that feature. I looked
> at the code and it would be easy to add in allProperties support, so
> yes, please create a Jira - and PR if you feel so inclined! :-)
>
> Cheers, Paul.