Skip to content

[core] Builder pattern for properties#669

Merged
jsotuyod merged 14 commits into
pmd:masterfrom
oowekyala:properties-builder
Nov 4, 2017
Merged

[core] Builder pattern for properties#669
jsotuyod merged 14 commits into
pmd:masterfrom
oowekyala:properties-builder

Conversation

@oowekyala

@oowekyala oowekyala commented Oct 15, 2017

Copy link
Copy Markdown
Member

Checks item 4 of #504

I did my best but it feels like so much boilerplate lol. With that builder thing going on, what about deprecating the constructors? Maybe not even to remove them, but to be able to change them when we need it, and to warn users there's a better way

Cheers!

*/
public abstract class PropertyDescriptorBuilder<E, T extends PropertyDescriptorBuilder<E, T>> {

protected String name;

@jsotuyod jsotuyod Oct 25, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

considering the name is required (there is no way to use a property without a name), I'd suggest having a constructor to set it directly instead of having to call name() each time, which will:

  1. reduce errors
  2. remove some boilerplate

Maybe go further with something such as IntegerProperty.named("myProp").desc(....)....build()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing, it replaces the boilerplate by some other boilerplate ^^ But I agree with the rationale

* @return The same builder
*/
@SuppressWarnings("unchecked")
public T defalt(List<V> val) {

@jsotuyod jsotuyod Oct 25, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultValue? I rather have a longer name than a typo :P

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right

* @return The same builder
*/
@SuppressWarnings("unchecked")
public T defalt(E val) {

@jsotuyod jsotuyod Oct 25, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultValue? I rather have a longer name than a typo :P

* @return The same builder
*/
@SuppressWarnings("unchecked")
public T min(V val) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

considering NumericPropertyModule requires both, lowerLimit and upperLimit to be set, we may want to add a T range(V min, V max) method to reduce boilerplate a little further.

@jsotuyod jsotuyod self-assigned this Oct 27, 2017
@jsotuyod jsotuyod added this to the 6.0.0 milestone Oct 29, 2017
@jsotuyod jsotuyod added an:enhancement An improvement on existing features / rules in:pmd-internals Affects PMD's internals labels Oct 29, 2017
@jsotuyod jsotuyod merged commit ac2ff0f into pmd:master Nov 4, 2017
jsotuyod added a commit that referenced this pull request Nov 4, 2017
@oowekyala oowekyala deleted the properties-builder branch November 5, 2017 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

an:enhancement An improvement on existing features / rules in:pmd-internals Affects PMD's internals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants