Merge branch 'pr-2010'
This commit is contained in:
@ -19,6 +19,11 @@ This is a {{ site.pmd.release_type }} release.
|
||||
* The Java rules {% rule "java/errorprone/InvalidSlf4jMessageFormat" %} and {% rule "java/errorprone/MoreThanOneLogger" %}
|
||||
(`java-errorprone`) now both support [Log4j2](https://logging.apache.org/log4j/2.x/).
|
||||
|
||||
* The Java rule {% rule "java/design/LawOfDemeter" %} (`java-design`) ignores now also Builders, that are
|
||||
not assigned to a local variable, but just directly used within a method call chain. The method, that creates
|
||||
the builder needs to end with "Builder", e.g. `newBuilder()` or `initBuilder()` works. This change
|
||||
fixes a couple of false positives.
|
||||
|
||||
### Fixed Issues
|
||||
|
||||
* core
|
||||
@ -66,6 +71,7 @@ This is a {{ site.pmd.release_type }} release.
|
||||
|
||||
### External Contributions
|
||||
|
||||
* [#2010](https://github.com/pmd/pmd/pull/2010): \[java] LawOfDemeter to support inner builder pattern - [Gregor Riegler](https://github.com/gregorriegler)
|
||||
* [#2012](https://github.com/pmd/pmd/pull/2012): \[java] Fixes 336, slf4j log4j2 support - [Mark Hall](https://github.com/markhall82)
|
||||
* [#2032](https://github.com/pmd/pmd/pull/2032): \[core] Allow adding SourceCode directly into CPD - [Nathan Braun](https://github.com/nbraun-Google)
|
||||
* [#2047](https://github.com/pmd/pmd/pull/2047): \[java] Fix computation of metrics with annotations - [Andi](https://github.com/andipabst)
|
||||
|
@ -168,7 +168,8 @@ public class LawOfDemeterRule extends AbstractJavaRule {
|
||||
|
||||
private boolean isNotBuilder() {
|
||||
return baseType != StringBuffer.class && baseType != StringBuilder.class
|
||||
&& !"StringBuilder".equals(baseTypeName) && !"StringBuffer".equals(baseTypeName);
|
||||
&& !"StringBuilder".equals(baseTypeName) && !"StringBuffer".equals(baseTypeName)
|
||||
&& !methodName.endsWith("Builder");
|
||||
}
|
||||
|
||||
private static List<ASTPrimarySuffix> findSuffixesWithoutArguments(ASTPrimaryExpression expr) {
|
||||
|
@ -269,6 +269,20 @@ public class Test {
|
||||
final FooBuilder fooBuilder = FooBuilder.newBuilder();
|
||||
fooBuilder.withBar();
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#2010 False Positive for Law of Demeter</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Test {
|
||||
public void bar() {
|
||||
// Inner Builder pattern chained
|
||||
final Bar bar = Bar.newBuilder()
|
||||
.withFoo("foo")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
Reference in New Issue
Block a user