Merge pull request #4170 from adangel:issue-4140-doc-max-lang-version

[doc] Rule doc: add maximum language version #4170
This commit is contained in:
Andreas Dangel
2022-10-28 10:04:29 +02:00
5 changed files with 22 additions and 2 deletions

View File

@ -38,6 +38,8 @@ The rule is part of the quickstart.xml ruleset.
* doc
* [#4144](https://github.com/pmd/pmd/pull/4144): \[doc] Update docs to reflect supported languages
* [#4163](https://github.com/pmd/pmd/issues/4163): \[doc] Broken links on page "Architecture Decisions"
* java-bestpractices
* [#4140](https://github.com/pmd/pmd/issues/4140): \[java] \[doc] AccessorClassGeneration violations hidden with Java 11
* java-codestyle
* [#4139](https://github.com/pmd/pmd/issues/4139): \[java] UnnecessaryFullyQualifiedName FP when the same simple class name exists in the current package
* java-documentation

View File

@ -392,6 +392,12 @@ public class RuleDocGenerator {
lines.add("");
}
if (rule.getMaximumLanguageVersion() != null) {
lines.add("**Maximum Language Version:** "
+ rule.getLanguage().getName() + " " + rule.getMaximumLanguageVersion().getVersion());
lines.add("");
}
lines.addAll(EscapeUtils.escapeLines(toLines(stripIndentation(rule.getDescription()))));
lines.add("");

View File

@ -155,6 +155,8 @@ Avoid jumbled loop incrementers - its usually a mistake, and is confusing even i
**Minimum Language Version:** Java 1.5
**Maximum Language Version:** Java 11
Override both `public boolean Object.equals(Object other)`, and `public int Object.hashCode()`, or override neither.
Even if you are inheriting a `hashCode()` from a parent class, consider implementing hashCode and explicitly
delegating to your superclass.

View File

@ -89,7 +89,8 @@ public class Bar {
message="Ensure you override both equals() and hashCode()"
class="net.sourceforge.pmd.lang.java.rule.errorprone.OverrideBothEqualsAndHashcodeRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_sample.html#overridebothequalsandhashcode"
minimumLanguageVersion="1.5">
minimumLanguageVersion="1.5"
maximumLanguageVersion="11">
<description>
Override both `public boolean Object.equals(Object other)`, and `public int Object.hashCode()`, or override neither.
Even if you are inheriting a `hashCode()` from a parent class, consider implementing hashCode and explicitly

View File

@ -42,11 +42,15 @@ public abstract class Foo {
class="net.sourceforge.pmd.lang.java.rule.bestpractices.AccessorClassGenerationRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#accessorclassgeneration">
<description>
Instantiation by way of private constructors from outside of the constructor's class often causes the
Instantiation by way of private constructors from outside the constructor's class often causes the
generation of an accessor. A factory method, or non-privatization of the constructor can eliminate this
situation. The generated class file is actually an interface. It gives the accessing class the ability
to invoke a new hidden package scope constructor that takes the interface as a supplementary parameter.
This turns a private constructor effectively into one with package scope, and is challenging to discern.
_Note:_ This rule is only executed for Java 10 or lower.
Since Java 11, [JEP 181: Nest-Based Access Control](https://openjdk.org/jeps/181) has been implemented. This
means that in Java 11 and above accessor classes are not generated anymore.
</description>
<priority>3</priority>
<example>
@ -74,6 +78,11 @@ public class Outer {
When accessing private fields / methods from another class, the Java compiler will generate accessor methods
with package-private visibility. This adds overhead, and to the dex method count on Android. This situation can
be avoided by changing the visibility of the field / method from private to package-private.
_Note:_ This rule is only executed for Java 10 or lower.
Since Java 11, [JEP 181: Nest-Based Access Control](https://openjdk.org/jeps/181) has been implemented. This
means that in Java 11 and above accessor classes are not generated anymore.
</description>
<priority>3</priority>
<example>