You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Get the package name of the Class in which this violation was identified.
*
* @return The package name.
*/
// TODO Isn't this Java specific?
StringgetPackageName();
/**
* Get the name of the Class in which this violation was identified.
*
* @return The Class name.
*/
// TODO Isn't this Java specific?
StringgetClassName();
/**
* Get the method name in which this violation was identified.
*
* @return The method name.
*/
// TODO Isn't this Java specific?
StringgetMethodName();
/**
* Get the variable name on which this violation was identified.
*
* @return The variable name.
*/
StringgetVariableName();
These are mostly Java-specific and the way this data is filled-in is very awkward: we have a JavaRuleViolation subclass of RuleViolation that initializes the fields in its constructor. To create a JavaRuleViolation we need a RuleViolationFactory instance which is mostly redundant.
The problems with this design are
We need a subclass of ParametricRuleViolation even though the superclass already has all fields
We need the interface RuleViolationFactory and language-specific implementations even though they're only used to call the correct constructor for the violation subclass
The attributes cannot be extended easily by other languages than Java
The attributes are meaningless in some languages, eg XML flavours
Describe the solution you'd like
Refactor these "extra attributes" to be exposed through a method Map<String, String> getAdditionalInfo() in RuleViolation. Standard keys like PACKAGE_NAME and CLASS_NAME can be exposed as constants in the RuleViolation interface.
Create a new interface ViolationDecorator whose job is to add extra attributes to the map. Use that in RuleContext when we create a new violation
Remove the RuleViolation subclasses and finally remove RuleViolationFactory.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Is your feature request related to a problem? Please describe.
Currently violations have a couple of methods like getPackageName, getMethodName:
pmd/pmd-core/src/main/java/net/sourceforge/pmd/RuleViolation.java
Lines 90 to 119 in 05d5bea
These are mostly Java-specific and the way this data is filled-in is very awkward: we have a JavaRuleViolation subclass of RuleViolation that initializes the fields in its constructor. To create a JavaRuleViolation we need a RuleViolationFactory instance which is mostly redundant.
The problems with this design are
Describe the solution you'd like
Map<String, String> getAdditionalInfo()in RuleViolation. Standard keys like PACKAGE_NAME and CLASS_NAME can be exposed as constants in the RuleViolation interface.ViolationDecoratorwhose job is to add extra attributes to the map. Use that in RuleContext when we create a new violationDescribe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
nspmd.reportingpackage, like ViolationSuppressor