Skip to content

[core] Implement PropertyFactory#1470

Merged
adangel merged 23 commits into
pmd:masterfrom
oowekyala:new-properties-framework
Nov 26, 2018
Merged

[core] Implement PropertyFactory#1470
adangel merged 23 commits into
pmd:masterfrom
oowekyala:new-properties-framework

Conversation

@oowekyala

Copy link
Copy Markdown
Member

Second step to #1432, scheduled for 6.10.0. It should be merged on master. The release notes update about PropertyFactory will be part of the next PR, along with the deprecations of concrete property classes.

  • The API is built around PropertyFactory. The new concrete classes of the property descriptors are not public. The PropertyBuilder replaces the previous hierarchy in n.s.pmd.properties.builders
  • The PropertyFactory and property builders are put in place to provide a replacement to the current public property classes that will be nearly 100% source compatible with the 7.0.0 version (with the exception of the delimiter() method).
  • The new API is designed to offer exactly the same capabilities to rule builders as the current framework for now, but no more. Functionality will be fleshed out on the 7.0.x branch, because without java 8 it's a pain. In particular the PropertyConstraint interface and its usage can be much improved with java 8.
  • If a rule has a property with a wrong value, it is now reported as a configuration error and the rule is pruned from the run ruleset. This contrasts with the current framework, which throws an IllegalArgumentException if a constraint e.g. on numeric range is violated.

@ghost

ghost commented Nov 16, 2018

Copy link
Copy Markdown
1 Message
📖 This changeset introduces 0 new violations and 0 new errors,
removes 0 violations and 0 errors. Full report
This changeset introduces 0 new violations and 0 new errors,
removes 61 violations and 0 errors. Full report

Generated by 🚫 Danger

They make no sense as they are shared by all StatisticalRules, and provoke configuration
errors on normal inputs since uncorrectly configured properties now cause the rule not to
be run

@adangel adangel left a comment

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.

I like the way, this is going 👍

One small question: We once said, we wanted to move the internal implementation classes into a sub-package called internal or impl. You have now created the implementations in the same package and just made the classes package-private - which is fine, since this also hides the classes from public API. I think, if we would create a sub-package, then you'd need to make the implementations public, so that you can use it the PropertyFactory... What do you think?

// todo Java 8 move up to interface
@Override
public String dysfunctionReason() {
for (PropertyDescriptor<?> descriptor : getOverriddenPropertyDescriptors()) {

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.

We should think about improving this API (different PR) - this would only return the first error. We should have a API, that returns all the problems a rule has.

Comment thread pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyDescriptor.java Outdated
* Note: from 7.0.0 on, this will be the only way to
* build property descriptors.
*
* TODO next PR add doc

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.

👍

Comment thread pmd-core/src/test/resources/net/sourceforge/pmd/TestRuleset1.xml
*
* @return The same builder
*/
// TODO we could probably specify the order of execution of constraints come 7.0.0, for now this remains unspecified

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.

I thought shortly about this - but does the order of the constraints matter? They all need to be met, and the constraints should be independent from each other...

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.

Indeed it wouldn't matter if constraints are truly independent -> in which case we should specify that. I think it makes sense, and it would allow to report all errors on a value, like you suggested for rules.

Comment thread pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyBuilder.java Outdated
Comment thread pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyBuilder.java Outdated
Comment thread pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyBuilder.java Outdated
adangel and others added 2 commits November 23, 2018 20:25
Co-Authored-By: oowekyala <clement.fournier76@gmail.com>
Co-Authored-By: oowekyala <clement.fournier76@gmail.com>
@oowekyala

Copy link
Copy Markdown
Member Author

One small question: We once said, we wanted to move the internal implementation classes into a sub-package called internal or impl. You have now created the implementations in the same package and just made the classes package-private - which is fine, since this also hides the classes from public API. I think, if we would create a sub-package, then you'd need to make the implementations public, so that you can use it the PropertyFactory... What do you think?

My 2 cents on that is, if the internal classes are only relevant to the package they're in (eg in this case), then I'd prefer package visibility over having an internal package. The internals are better hidden that way I guess. Although in some cases using package visibility is simply not possible, then those internal APIs would belong in an internal package. Also if the main package has many classes.

@adangel adangel self-assigned this Nov 26, 2018
@adangel adangel merged commit b2d9b4e into pmd:master Nov 26, 2018
@oowekyala oowekyala deleted the new-properties-framework branch November 26, 2018 21:00
public List<T> get() {
return new ArrayList<>();
}
};

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.

do we really need this and to pass it around just to create an empty list? sounds like overkill to me

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.

This is in prevision of the migration to Java 8. Many things here are sloppy because I designed this as if it was Java 8, but had to write it with Java 7 syntax so it's ugly. In Java 8 it will be as short as ArrayList::new, and we can also provide a toSet method with HashSet::new, or let the user use any collection supplier they want.

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.

It's not about the syntax, it's about the actual need for a Supplier for such a thing

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.

As documented, GenericCollectionPropertyBuilder is designed to support building properties for an arbitrary Collection, not just lists. The most generic way to do that is to pass on a Supplier for the collection you want. How would you do it otherwise?

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.

I'm unsure there is a need for arbitrary collections types at all, and I fear being flexible about it is overengineering. Do we even have a use case for this?

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.

It's extremely easy to grab, so I wouldn't consider that overengineering. Everything is already completely generic, and GenericMultivaluePropertyDescriptor will be removed with 7.0.0, so there's really no point in artificially constraining ourselves to lists. One use case I can think of is the options for metrics rules, which would be better served by using a Set rather than a list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants