playframework / play-enhancer

14 stars 9 forks source link

Handling boolean fields #12

Closed thibaultmeyer closed 7 years ago

thibaultmeyer commented 7 years ago

Related to #7, boolean fields are now handled with extra getter / setter names. getX and setX for boolean fields are been keep to avoid API breaking.

Unit tests added too.

public class Demo {
    public Boolean admin;
    public Boolean isEnabled;
    public Boolean hasPermissions;
    public boolean b;
    public boolean canDeleteAccount;
}

Will be enhanced as

public class Demo {
    public Boolean admin;
    public Boolean isEnabled;
    public Boolean hasPermissions;
    public boolean b;
    public boolean canDeleteAccount;

    public Boolean isAdmin() {
        return this.admin
    }

    public Boolean isAdmin(Boolean admin) {
        this.admin = admin;
    }

    public Boolean getAdmin() {
        return this.admin
    }

    public Boolean setAdmin(Boolean admin) {
        this.admin = admin;
    }

    public Boolean isEnabled() {
        return this.enabled
    }

    public Boolean isEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public Boolean getEnabled() {
        return this.enabled
    }

    public Boolean setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public Boolean hasPermissions() {
        return this.hasPermissions
    }

    public Boolean hasPermissions(Boolean hasPermissions) {
        this.hasPermissions = hasPermissions;
    }

    public Boolean getHasPermissions() {
        return this.hasPermissions
    }

    public Boolean setHasPermissions(Boolean hasPermissions) {
        this.hasPermissions = hasPermissions;
    }

    public boolean isB() {
        return this.b
    }

    public boolean isB(boolean b) {
        this.b = b;
    }

    public boolean getB() {
        return this.b
    }

    public boolean setB(boolean b) {
        this.b = b;
    }

    public boolean canDeleteAccount() {
        return this.canDeleteAccount
    }

    public boolean canDeleteAccount(boolean canDeleteAccount) {
        this.canDeleteAccount = canDeleteAccount;
    }

    public boolean getCanDeleteAccount() {
        return this.canDeleteAccount
    }

    public boolean setCanDeleteAccount(boolean canDeleteAccount) {
        this.canDeleteAccount = canDeleteAccount;
    }
}
marcospereira commented 7 years ago

I don't think we need the is* setters. According to the Java Beans specification:

Boolean properties

In addition, for boolean properties, we allow a getter method to match the pattern:

public boolean is<PropertyName>();

This "is" method may be provided instead of a "get" method, or it may be provided in addition to a "get" method.

In either case, if the "is" method is present for a boolean property then we will use the "is" method to read the property value.

An example boolean property might be:

public boolean isMarsupial();
public void setMarsupial(boolean m);

So, we can reduce it to generate just the following methods:

 public boolean isMarsupial();
 public boolean getMarsupial();
 public void setMarsupial(boolean m);

WDYT?

thibaultmeyer commented 7 years ago

Sure, I will do modifications today

marcospereira commented 7 years ago

Thanks, @0xbaadf00d.