Skip to content

Commit

Permalink
Merge pull request #4170 from adangel:issue-4140-doc-max-lang-version
Browse files Browse the repository at this point in the history
[doc] Rule doc: add maximum language version #4170
  • Loading branch information
adangel committed Oct 28, 2022
2 parents 66d67c7 + 21cca4b commit 2f515e5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/pages/release_notes.md
Expand Up @@ -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
Expand Down
Expand Up @@ -392,6 +392,12 @@ private void generateRuleSetIndex(Map<Language, List<RuleSet>> rulesets) throws
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("");

Expand Down
2 changes: 2 additions & 0 deletions pmd-doc/src/test/resources/expected/sample.md
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion pmd-doc/src/test/resources/rulesets/ruledoctest/sample.xml
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion pmd-java/src/main/resources/category/java/bestpractices.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 2f515e5

Please sign in to comment.