Merge branch '7.0.x' into antlr-touchups

This commit is contained in:
Clément Fournier
2020-06-17 20:08:08 +02:00
14 changed files with 223 additions and 20 deletions

View File

@ -1,10 +1,10 @@
repository: pmd/pmd
pmd:
version: 6.25.0-SNAPSHOT
version: 7.0.0-SNAPSHOT
previous_version: 6.24.0
date: ??-June-2020
release_type: minor
date: ??-2020
release_type: major
# release types: major, minor, bugfix

View File

@ -433,6 +433,9 @@ entries:
- title: What does 'PMD' mean?
url: /pmd_projectdocs_trivia_meaning.html
output: web, pdf
- title: Logo
url: /pmd_projectdocs_logo.html
output: web, pdf
- title: FAQ
url: /pmd_projectdocs_faq.html
output: web, pdf

BIN
docs/images/logo/PMD.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

105
docs/images/logo/PMD.svg Normal file
View File

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
inkscape:export-ydpi="50.720001"
inkscape:export-xdpi="50.720001"
inkscape:export-filename="/home/andreas/PMD/source/pmd7/docs/images/logo/pmd-logo-300px.png"
inkscape:version="1.0 (4035a4fb49, 2020-05-01)"
sodipodi:docname="PMD.svg"
xml:space="preserve"
enable-background="new 0 0 1600 1200"
viewBox="0 0 1600 1200"
y="0px"
x="0px"
id="Layer_1"
version="1.1"><metadata
id="metadata79"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs77" /><sodipodi:namedview
inkscape:pagecheckerboard="false"
inkscape:current-layer="g72"
inkscape:window-maximized="0"
inkscape:window-y="23"
inkscape:window-x="26"
inkscape:cy="600"
inkscape:cx="800"
inkscape:zoom="0.748125"
showgrid="false"
id="namedview75"
inkscape:window-height="883"
inkscape:window-width="1619"
inkscape:pageshadow="2"
inkscape:pageopacity="0"
guidetolerance="10"
gridtolerance="10"
objecttolerance="10"
borderopacity="1"
bordercolor="#666666"
pagecolor="#ffffff" />
<g
id="g72"><g
id="g947"><path
fill="none"
d="M934.8,558.4h-24.9v79.3h26.1c21.4,0,37.1-16.1,37.1-39.5C973.2,574.7,956.7,558.4,934.8,558.4z"
id="path4" /><path
fill="#58595B"
d="M569.6,682.1c-0.5-3.1-1.1-6.2-1.1-9.3c-0.1-17.6,0-35.2-0.2-52.8c-0.1-7.3-1.9-14.2-7.1-19.7 c-1.8-1.9-3.9-3.6-5.9-5.4c2-1.8,4.1-3.5,5.9-5.4c5.2-5.5,7-12.3,7.1-19.7c0.2-17.6,0.1-35.2,0.2-52.8c0-3.1,0.6-6.2,1.1-9.3 c0.6-4,3.1-6.3,7-6.8h20.8v-22.2h-14.3c-11.2-0.5-22,1-31.3,9c-7.6,6.6-10.1,15.5-10.3,25c-0.4,16.3-0.1,32.6-0.3,48.9 c0,3.6-0.4,7.2-1.3,10.7c-0.1,0.3-0.2,0.6-0.3,0.9c-1.2,3.2-3.2,5.3-5.6,6.8c-1.2,0.7-2.6,1.3-4.1,1.7c-1.3,0.4-2.4,0.6-3.2,0.9 c-0.8,0.1-1.5,0.2-2.2,0.3h-8.5v11.8v11.8h8.5c0.7,0.1,1.4,0.1,2.2,0.3c0.8,0.3,1.8,0.6,3.2,0.9c1.5,0.4,2.9,1,4.1,1.7 c2.3,1.5,4.4,3.6,5.6,6.8c0.1,0.3,0.2,0.6,0.3,0.9c0.9,3.5,1.3,7.1,1.3,10.7c0.2,16.3-0.1,32.6,0.3,48.9c0.2,9.5,2.8,18.4,10.3,25 c9.3,8.1,20.1,9.5,31.3,9h14.3v-22.2h-20.8C572.8,688.4,570.2,686.1,569.6,682.1z"
id="path60" /><path
fill="#58595B"
d="M1075.3,583.3c-0.7-0.1-1.4-0.1-2.2-0.3c-0.8-0.3-1.8-0.6-3.2-0.9c-1.5-0.4-2.9-1-4.1-1.7 c-2.3-1.5-4.4-3.6-5.6-6.8c-0.1-0.3-0.2-0.6-0.3-0.9c-0.9-3.5-1.3-7.1-1.3-10.7c-0.2-16.3,0.1-32.6-0.3-48.9 c-0.2-9.5-2.8-18.4-10.3-25c-9.3-8.1-20.1-9.5-31.3-9h-14.3v22.2h20.8c3.9,0.5,6.4,2.8,7,6.8c0.5,3.1,1.1,6.2,1.1,9.3 c0.1,17.6,0,35.2,0.2,52.8c0.1,7.3,1.9,14.2,7.1,19.7c1.8,1.9,3.9,3.6,5.9,5.4c-2,1.8-4.1,3.5-5.9,5.4c-5.2,5.5-7,12.3-7.1,19.7 c-0.2,17.6-0.1,35.2-0.2,52.8c0,3.1-0.6,6.2-1.1,9.3c-0.6,4-3.1,6.3-7,6.8h-20.8v22.2h14.3c11.2,0.5,22-1,31.3-9 c7.6-6.6,10.1-15.5,10.3-25c0.4-16.3,0.1-32.6,0.3-48.9c0-3.6,0.4-7.2,1.3-10.7c0.1-0.3,0.2-0.6,0.3-0.9c1.2-3.2,3.2-5.3,5.6-6.8 c1.2-0.7,2.6-1.3,4.1-1.7c1.3-0.4,2.4-0.6,3.2-0.9c0.8-0.1,1.5-0.2,2.2-0.3h8.5v-11.8v-11.8H1075.3z"
id="path62" /><g
id="g70">
<polygon
fill="#1DBF73"
points="791,612.3 753.7,534.1 721.4,534.1 721.4,662 747.5,662 747.5,575.8 781.5,649.1 800.3,649.1 834.3,575.8 834.3,662 860.2,662 860.2,534.1 828.1,534.1 "
id="polygon64" />
<path
fill="#1DBF73"
d="M935.3,534.1h-54.3V662h53.2c40.4,0,68.3-26.3,68.3-64C1002.6,560.2,975,534.1,935.3,534.1z M936.1,637.7 h-26.1v-79.3h24.9c21.9,0,38.4,16.3,38.4,39.8C973.2,621.6,957.5,637.7,936.1,637.7z"
id="path66" />
<path
fill="#1DBF73"
d="M723.3,525.6c-4,2.2-7.9,4.7-11.7,7.2c-7.4,5-14.1,10.3-19.8,15.2c-2.7,2.4-5.2,4.6-7.4,6.7 c-1.1,0.9-2.1,1.8-3.1,2.7c-3.4,3-6.6,6-9.7,8.8c-17,15.8-29.2,28.9-29.2,28.9l-16-18l-8-8.9l-5.7-6.4c0.6-3.1,2.9-5.7,5.7-7.9 c1.9-1.5,4-2.7,6.1-3.8c4.1-2.1,7.7-3.2,7.7-3.2l2.7,3.2l6.8,7.9l8,9.3c2.9-3,5.8-5.9,8.6-8.6c3.2-3.1,6.4-6,9.5-8.6 c2.2-1.9,4.4-3.8,6.6-5.5c2.1-1.6,4.2-3.1,6.5-4.6c-7.8-3.8-17.6-5.9-29-5.9h-54.3V662h28.9v-36.5h25.4c32.5,0,51.2-17.2,51.2-47 c0-9.9-2.3-18.4-6.7-25.1L723.3,525.6z"
id="path68" />
</g></g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -52,6 +52,7 @@ in a variety of ways, which are [documented here](pmd_userdocs_cpd.html).
The latest release of PMD can be downloaded from our [Github releases page](https://github.com/pmd/pmd/releases/latest).
The Logo is available from the [Logo Project Page](pmd_projectdocs_logo.html).
## Documentation

View File

@ -0,0 +1,20 @@
---
title: Logo
sidebar: pmd_sidebar
permalink: pmd_projectdocs_logo.html
folder: pmd/projectdocs
---
![PMD Logo](images/logo/pmd-logo-300px.png)
The following PMD Logos and Icons are licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/):
* [PMD.svg](images/logo/PMD.svg)
* [PMD.png](images/logo/PMD.png)
* [Logo (300px, transparent)](images/logo/pmd-logo-300px.png)
* [Logo (300px, white)](images/logo/pmd-logo-white-300px.png)
* [Logo (600px, transparent)](images/logo/pmd-logo-600px.png)
* [Logo (600px, white)](images/logo/pmd-logo-white-600px.png)
* [Favicon (16x16)](images/logo/favicon.ico)

View File

@ -53,10 +53,25 @@ The command line version of PMD continues to use **scala 2.13**.
* The new Java Rule {% rule "java/codestyle/UnnecessaryCast" %} (`java-codestyle`)
finds casts that are unnecessary while accessing collection elements.
#### Modified rules
* The Java rule {% rule "java/codestyle/UseDiamondOperator" %} (`java-codestyle`) now by default
finds unnecessary usages of type parameters, which are nested, involve wildcards and are used
within a ternary operator. These usages are usually only unnecessary with Java8 and later, when
the type inference in Java has been improved.
In order to avoid false positives when checking Java7 only code, the rule has the new property
`java7Compatibility`, which is disabled by default. Settings this to "true" retains
the old rule behaviour.
### Fixed Issues
* c#
* [#2551](https://github.com/pmd/pmd/issues/2551): \[c#] CPD suppression with comments doesn't work
* java-codestyle
* [#2545](https://github.com/pmd/pmd/issues/2545): \[java] UseDiamondOperator false negatives
* java-design
* [#2563](https://github.com/pmd/pmd/pull/2563): \[java] UselessOverridingMethod false negative with already public methods
* scala

View File

@ -1673,6 +1673,11 @@ Use the diamond operator to let the type be inferred automatically. With the Dia
to avoid duplication of the type parameters.
Instead, the compiler is now able to infer the parameter types for constructor calls,
which makes the code also more readable.
The diamond operator has been introduced with java 7. However, type inference has been improved further
with java8, rendering more type parameters unnecessary. This is only possible with java8 and the resulting
code won't compile with java7. If you use java7, make sure to enable `java7Compatibility` for this rule to avoid
false positives.
</description>
<priority>3</priority>
<properties>
@ -1685,15 +1690,17 @@ which makes the code also more readable.
|
//StatementExpression[AssignmentOperator and PrimaryExpression/PrimaryPrefix[not(Expression)]]
)
/Expression/PrimaryExpression[not(PrimarySuffix) and not(ancestor::ArgumentList)]
/(Expression | Expression[$java7Compatibility = false()]/ConditionalExpression | Expression[$java7Compatibility = false()]/ConditionalExpression/Expression)
/PrimaryExpression[not(PrimarySuffix) and not(ancestor::ArgumentList)]
/PrimaryPrefix
/AllocationExpression
[@AnonymousClass=false()]
[ClassOrInterfaceType/TypeArguments[@Diamond=false() and not(TypeArgument//TypeArguments)]]
[ClassOrInterfaceType/TypeArguments[@Diamond=false() and not($java7Compatibility = true() and .//TypeArgument[@Wildcard=true()])]]
[not(ArrayDimsAndInits)]
]]>
</value>
</property>
<property name="java7Compatibility" type="Boolean" description="If disabled, the rule shows also violations that are applicable for java8+" value="false" />
</properties>
<example>
<![CDATA[

View File

@ -6,8 +6,8 @@
<test-code>
<description>Use Diamond</description>
<expected-problems>2</expected-problems>
<expected-linenumbers>6,11</expected-linenumbers>
<expected-problems>3</expected-problems>
<expected-linenumbers>6,9,10</expected-linenumbers>
<code><![CDATA[
import java.util.ArrayList;
import java.util.List;
@ -17,7 +17,6 @@ public class Foo {
List<String> strings = new ArrayList<String>();
List<String> strings2 = new ArrayList<>();
List<List<String>> strings3 = new ArrayList<>();
// this is a known false negative, see at the bottom
List<List<String>> strings4 = new ArrayList<List<List<String>>>();
this.field = new ArrayList<String>();
}
@ -139,35 +138,43 @@ class Foo {
</test-code>
<!-- These tests depend on the Java version used -->
<!-- For now we keep the old behaviour of ignoring type
arguments that have type arguments themselves, ie we have
false negatives. We can improve that with better type resolution
<!-- For now we keep the old behaviour of Java 7 and ignoring type
arguments which have wildcards involved, ie we have
false negatives for Java8+. We can improve that with better type resolution
in PMD 7. -->
<test-code regressionTest="false">
<description>(J7) Version sensitive tests</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>6</expected-linenumbers>
<test-code>
<description>(J7) Version sensitive tests - avoid possible false positives on Java7</description>
<rule-property name="java7Compatibility">true</rule-property>
<expected-problems>0</expected-problems>
<code><![CDATA[
import java.lang.ref.WeakReference;
public class Foo {
private WeakReference<Class<?>> typeReference;
public void foo() {
// this should be positive in Java 8, negative in Java 7
// in java 7: no violation, in java 8 violation
typeReference = new WeakReference<Class<?>>(String.class);
// this is because in java 7, new WeakReference<>(String.class) types as WeakReference<Class<String>>
// which is incompatible with WeakReference<Class<?>>, whereas Java 8's type inference is better.
typeReference = new WeakReference<Class<?>>(String.class);
// the following is the same:
// in java 7: no violation, in java 8 violation
Class<?> type = null;
typeReference = new WeakReference<Class<?>>(type); // this should be positive on all versions
typeReference = new WeakReference<Class<?>>(type);
}
}
]]></code>
</test-code>
<test-code regressionTest="false">
<description>(J8) Version sensitive tests</description>
<test-code>
<description>(J8) Version sensitive tests - known false negatives on Java8+</description>
<expected-problems>2</expected-problems>
<expected-linenumbers>4,6</expected-linenumbers>
<expected-linenumbers>6,8</expected-linenumbers>
<code><![CDATA[
import java.lang.ref.WeakReference;
public class Foo {
private WeakReference<Class<?>> typeReference;
public void foo() {
@ -175,6 +182,51 @@ public class Foo {
Class<?> type = null;
typeReference = new WeakReference<Class<?>>(type); // pos
}
}
]]></code>
</test-code>
<test-code>
<description>False negative for nested type parameters (#2545)</description>
<rule-property name="java7Compatibility">true</rule-property>
<expected-problems>3</expected-problems>
<expected-linenumbers>7,8,17</expected-linenumbers>
<code><![CDATA[
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.lang.ref.WeakReference;
public class UseDiamondOperatorFalseNegative {
List<Map<String,Object>> l = new ArrayList<Map<String,Object>>(); // FN
WeakReference<Class<String>> typeReference = new WeakReference<Class<String>>(String.class); // FN
WeakReference<Class<?>> typeReference2 = new WeakReference<Class<?>>(String.class); // FP
public void test() {
final List<String> l2;
l2 = true ? new ArrayList<String>() : new ArrayList<String>(); // FN twice for java8+, but for java7, this is ok!
}
static {
l = new ArrayList<Map<String,Object>>(); // FN
}
}
]]></code>
</test-code>
<test-code>
<description>(J8+) False negative for Java8+ and ternary operator (#2545)</description>
<expected-problems>2</expected-problems>
<expected-linenumbers>7,7</expected-linenumbers>
<code><![CDATA[
import java.util.List;
import java.util.ArrayList;
public class UseDiamondOperatorFalseNegative {
public void test() {
final List<String> l2;
l2 = true ? new ArrayList<String>() : new ArrayList<String>(); // FN twice for java8+, but for java7, this is ok!
}
}
]]></code>
</test-code>