projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.89k stars 2.39k forks source link

Feature Request: Skip Field Generation #1746

Open desoss opened 6 years ago

desoss commented 6 years ago

Is it possible with lombok to generate only the getter and setter related to a field and not the field?

Possible use case, I have a parent class A, I have a class B that extends A. In class B I want to ovveride the annotations of the getters/setters of some fields of A.

Essentially I have 2 possibilities for doing this:

  1. I can override the interested getter and setter adding the annotations
  2. exploiting java field hiding, I redeclare the interested fields, adding the annotations over them and annotating class B with the annotation Data.

The second solution is much more cleaner and readable then the first one thanks to lombok. I prefer the second solution since in some cases I would have dozens of getters/setters. Nevertheless I would like to avoid field hiding.

What I'm looking for is something like GenerateField(value=false) annotation. That at compile time will not generate the field (no field hiding so) but will generate the getters and the setters of this field together with the annotations added to the field.

Something like this:

@Data
public class A{
  private String id;

  private String name;
}

@Data
public class B extends A{

  @Id
  @GeneratedField(value=false)
  private String id;
}
randakar commented 6 years ago

I don't think the field is "generated" insomuch as "left alone". So what you're asking lombok to do is remove the field after the fact.

On Thu, Jun 28, 2018 at 11:26 AM, Jacopo Rigoli notifications@github.com wrote:

Is it possible with lombok to generate only the methods related (@getter https://github.com/getter, @setter https://github.com/setter) to a field and not the field?

Possible use case, I have a parent class A, I have a class B that extends A. In class B I want to ovverride the annotations of the getters/setters of some fields of A.

Essentially I have 2 possibilities for doing this:

  1. I can override the interested getter and setter adding the annotations
  2. exploiting java field hiding, I redeclare the interested fields, adding the annotations over them and annotating class B with the annotation Data.

The second solution is much more cleaner and readable then the first one thanks to lombok. I prefer the second solution since in some cases I would have dozens of getters/setters. Nevertheless I would like to avoid field hiding.

What I'm looking for is something like @generatefield(value=false). That at compile time will not generate the field (no field hiding so) but will generate the @getterS https://github.com/getterS and the @setters of this field together with the added annotations.

Something like this:

@Data public class A{ private String id;

private String name; }

@Data public class B extends A{

@Id @GeneratedField(value=false) private String id; }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rzwitserloot/lombok/issues/1746, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKCRQOHtQsXy7K9E0cVLxs3lRciOdZQks5uBKE8gaJpZM4U7C8T .

-- "Don't only practice your art, but force your way into it's secrets, for it and knowledge can raise men to the divine." -- Ludwig von Beethoven

randakar commented 6 years ago

Also, what exactly do you expect the generated getter and setter code to do in that case, if the underlying field is not there? Use the corresponding fields from the superclass, I take it? But .. that's a problem. Because that requires resolution. And resolution .. well, read it yourself: https://github.com/rzwitserloot/lombok/wiki/LOMBOK-CONCEPT:-Resolution

On Thu, Jun 28, 2018 at 1:20 PM, Floris Kraak randakar@gmail.com wrote:

I don't think the field is "generated" insomuch as "left alone". So what you're asking lombok to do is remove the field after the fact.

On Thu, Jun 28, 2018 at 11:26 AM, Jacopo Rigoli notifications@github.com wrote:

Is it possible with lombok to generate only the methods related (@getter https://github.com/getter, @setter https://github.com/setter) to a field and not the field?

Possible use case, I have a parent class A, I have a class B that extends A. In class B I want to ovverride the annotations of the getters/setters of some fields of A.

Essentially I have 2 possibilities for doing this:

  1. I can override the interested getter and setter adding the annotations
  2. exploiting java field hiding, I redeclare the interested fields, adding the annotations over them and annotating class B with the annotation Data.

The second solution is much more cleaner and readable then the first one thanks to lombok. I prefer the second solution since in some cases I would have dozens of getters/setters. Nevertheless I would like to avoid field hiding.

What I'm looking for is something like @generatefield(value=false). That at compile time will not generate the field (no field hiding so) but will generate the @getterS https://github.com/getterS and the @setters of this field together with the added annotations.

Something like this:

@Data public class A{ private String id;

private String name; }

@Data public class B extends A{

@Id @GeneratedField(value=false) private String id; }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rzwitserloot/lombok/issues/1746, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKCRQOHtQsXy7K9E0cVLxs3lRciOdZQks5uBKE8gaJpZM4U7C8T .

-- "Don't only practice your art, but force your way into it's secrets, for it and knowledge can raise men to the divine." -- Ludwig von Beethoven

-- "Don't only practice your art, but force your way into it's secrets, for it and knowledge can raise men to the divine." -- Ludwig von Beethoven