A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/3203 below:

[core] Replace RuleViolationFactory implementations with ViolationDecorator · Issue #3203 · pmd/pmd · GitHub

Is your feature request related to a problem? Please describe.
Currently RuleViolation has a few methods which are somewhat language-specific:

This is fine, but the way these properties are filled in is very indirect and weird: you need an implementation of RuleViolation which sets fields of its superclass in its constructor. You also need an implementation of RuleViolationFactory which calls the constructor of your subclass. So we multiply implementations of these interfaces even though ParametricRuleViolation, the default RuleViolation implementation already has all the necessary fields. Those implementations are useless except to fill those properties.

Describe the solution you'd like

interface ViolationDecorator {
   RuleViolation decorate(RuleViolation baseViolation, Node node);
}

and an implementation:

ViolationDecorator javaViolationDecorator = (baseViolation, node) -> {
    JavaNode node = (JavaNode) node;
    Map<String, String> metadata = new HashMap<>(baseViolation.getExtraAttributes()); // copy original map
    metadata.put(RuleViolation.VARIABLE_NAME, getVarName(javaNode));
    metadata.put(RuleViolation.METHOD_NAME, getMethodName(javaNode));
    // etc
    return new ParametricRuleViolation(baseViolation, metadata); // replace metadata, copy all other attributes of the base violation
};

Describe alternatives you've considered None

Additional context In #2807 I changed RuleViolationFactory a lot, with this idea in mind.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4