From b2dc358abac1e6d0c68c8c07f278a8197b9f3eb2 Mon Sep 17 00:00:00 2001 From: Harsh Kukreja Date: Mon, 27 Apr 2020 09:09:07 +0530 Subject: [PATCH 1/4] Operator Wrap check --- .../errorprone/CloneMethodMustImplementCloneableRule.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloneMethodMustImplementCloneableRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloneMethodMustImplementCloneableRule.java index 0566a1ee45..495e9bf31c 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloneMethodMustImplementCloneableRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloneMethodMustImplementCloneableRule.java @@ -91,8 +91,8 @@ public class CloneMethodMustImplementCloneableRule extends AbstractJavaRule { // Is the clone method just throwing CloneNotSupportedException? final ASTClassOrInterfaceDeclaration classOrInterface = node.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class); - if (classOrInterface != null && //Don't analyze enums, which cannot subclass clone() - (node.isFinal() || classOrInterface.isFinal())) { + if (classOrInterface != null //Don't analyze enums, which cannot subclass clone() + && (node.isFinal() || classOrInterface.isFinal())) { if (node.findDescendantsOfType(ASTBlock.class).size() == 1) { final List blocks = node.findDescendantsOfType(ASTBlockStatement.class); if (blocks.size() == 1) { From 4192f04c1d1f39e8ce25e33fa2a10ff40ec0dba7 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Mon, 27 Apr 2020 19:41:33 +0200 Subject: [PATCH 2/4] [apex] clarify AvoidGlobalModifier, refs #2298 --- .../AvoidGlobalModifierRule.java | 4 +++ .../bestpractices/xml/AvoidGlobalModifier.xml | 26 ++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AvoidGlobalModifierRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AvoidGlobalModifierRule.java index 095c20bc38..a07bcee7c0 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AvoidGlobalModifierRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AvoidGlobalModifierRule.java @@ -39,6 +39,10 @@ public class AvoidGlobalModifierRule extends AbstractApexRule { addViolation(data, node); } + // Note, the rule reports the whole class, since that's enough and stops to visit right here. + // It also doesn't use rulechain, since it the top level type needs to global. + // if a member is global, that class has to be global as well to be valid apex. + // See also https://github.com/pmd/pmd/issues/2298 return data; } diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/bestpractices/xml/AvoidGlobalModifier.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/bestpractices/xml/AvoidGlobalModifier.xml index 470fbdee69..a182455e52 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/bestpractices/xml/AvoidGlobalModifier.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/bestpractices/xml/AvoidGlobalModifier.xml @@ -28,26 +28,32 @@ global interface Foo { Global method 1 + 1 - + ]]> + Global inner interface 1 + 1 - + ]]> + #1348 [apex] AvoidGlobalModifierRule gives warning even when its a REST webservice - false positive From 9416a8fa65a8a00967570a67492824a8dac2fa45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Mon, 27 Apr 2020 21:25:23 +0200 Subject: [PATCH 3/4] Update release notes, refs #2448 --- docs/pages/release_notes.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index b8f8783555..f6837bea9b 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -20,5 +20,8 @@ This is a {{ site.pmd.release_type }} release. ### External Contributions +* [#2448](https://github.com/pmd/pmd/pull/2448): \[java] Operator Wrap check - [Harsh Kukreja](https://github.com/harsh-kukreja) + + {% endtocmaker %} From 0adb7c86357228d5c23a5a4dddbbe7043786a889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Tue, 28 Apr 2020 08:23:27 +0200 Subject: [PATCH 4/4] Add some DeprecatedAttribute annotations This improves warnings for XPath rules --- .../java/net/sourceforge/pmd/lang/java/ast/ASTArguments.java | 2 ++ .../pmd/lang/java/ast/ASTConstructorDeclaration.java | 2 ++ .../net/sourceforge/pmd/lang/java/ast/ASTFieldDeclaration.java | 2 ++ .../net/sourceforge/pmd/lang/java/ast/ASTFormalParameters.java | 2 ++ .../pmd/lang/java/ast/ASTLocalVariableDeclaration.java | 2 ++ .../sourceforge/pmd/lang/java/ast/ASTVariableDeclaratorId.java | 1 + 6 files changed, 11 insertions(+) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTArguments.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTArguments.java index fd9fb5dbad..bdb9baa7f1 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTArguments.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTArguments.java @@ -5,6 +5,7 @@ package net.sourceforge.pmd.lang.java.ast; import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; public class ASTArguments extends AbstractJavaNode { @@ -35,6 +36,7 @@ public class ASTArguments extends AbstractJavaNode { * @deprecated for removal. Use {@link #size()} or {@link ASTArgumentList#size()} instead. */ @Deprecated + @DeprecatedAttribute(replaceWith = "@Size") public int getArgumentCount() { return size(); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTConstructorDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTConstructorDeclaration.java index 3e3f473bd3..656a558b04 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTConstructorDeclaration.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTConstructorDeclaration.java @@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.java.ast; import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; public class ASTConstructorDeclaration extends AbstractMethodOrConstructorDeclaration { @@ -56,6 +57,7 @@ public class ASTConstructorDeclaration extends AbstractMethodOrConstructorDeclar * @deprecated Use {@link #getArity()} */ @Deprecated + @DeprecatedAttribute(replaceWith = "@Arity") public int getParameterCount() { return getArity(); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFieldDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFieldDeclaration.java index b7023ce9ca..92d7a521a5 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFieldDeclaration.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFieldDeclaration.java @@ -8,6 +8,7 @@ import java.util.Iterator; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.SignedNode; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; import net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSignature; import net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition; @@ -177,6 +178,7 @@ public class ASTFieldDeclaration extends AbstractJavaAccessTypeNode implements D * Iterate on the {@linkplain ASTVariableDeclaratorId VariableDeclaratorIds} instead */ @Deprecated + @DeprecatedAttribute(replaceWith = "VariableDeclaratorId/@Name") public String getVariableName() { ASTVariableDeclaratorId decl = getFirstDescendantOfType(ASTVariableDeclaratorId.class); if (decl != null) { diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFormalParameters.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFormalParameters.java index b492f7f2c1..a4eb5cba2f 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFormalParameters.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFormalParameters.java @@ -8,6 +8,7 @@ import java.util.Iterator; import java.util.List; import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; public class ASTFormalParameters extends AbstractJavaNode implements Iterable { @@ -34,6 +35,7 @@ public class ASTFormalParameters extends AbstractJavaNode implements Iterable 0; }