Merge branch '7.0.x' into cleanup-abstract-node

This commit is contained in:
Clément Fournier
2020-04-29 09:19:00 +02:00
10 changed files with 37 additions and 12 deletions

View File

@ -25,5 +25,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 %}

View File

@ -33,6 +33,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;
}

View File

@ -28,26 +28,32 @@ global interface Foo {
<test-code>
<description>Global method</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>1</expected-linenumbers>
<code><![CDATA[
global class Foo {
global Integer bar() {
}
global Integer bar() {
// Note, the rule reports the whole class, since that's enough:
// 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
}
}
]]></code>
</test-code>
]]></code>
</test-code>
<test-code>
<description>Global inner interface</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>1</expected-linenumbers>
<code><![CDATA[
global class Foo {
global interface Bar {
}
global interface Bar {
// Note, the rule reports the whole class, since that's enough:
// 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
}
}
]]></code>
</test-code>
]]></code>
</test-code>
<test-code>
<description>#1348 [apex] AvoidGlobalModifierRule gives warning even when its a REST webservice - false positive</description>

View File

@ -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 {
@ -29,6 +30,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();
}

View File

@ -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 {
@ -57,6 +58,7 @@ public class ASTConstructorDeclaration extends AbstractMethodOrConstructorDeclar
* @deprecated Use {@link #getArity()}
*/
@Deprecated
@DeprecatedAttribute(replaceWith = "@Arity")
public int getParameterCount() {
return getArity();
}

View File

@ -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;
@ -178,6 +179,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) {

View File

@ -7,6 +7,8 @@ package net.sourceforge.pmd.lang.java.ast;
import java.util.Iterator;
import java.util.List;
import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute;
public class ASTFormalParameters extends AbstractJavaNode implements Iterable<ASTFormalParameter> {
@ -24,6 +26,7 @@ public class ASTFormalParameters extends AbstractJavaNode implements Iterable<AS
* @deprecated for removal. Use {@link #size()} instead.
*/
@Deprecated
@DeprecatedAttribute(replaceWith = "@Size")
public int getParameterCount() {
return size();
}

View File

@ -8,6 +8,7 @@ import java.util.Iterator;
import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute;
/**
@ -123,6 +124,7 @@ public class ASTLocalVariableDeclaration extends AbstractJavaAccessNode implemen
// It would be nice to have a way to inform XPath users of the intended replacement
// for a deprecated attribute. We may use another annotation for that.
@Deprecated
@DeprecatedAttribute(replaceWith = "VariableDeclaratorId/@Name")
public String getVariableName() {
ASTVariableDeclaratorId decl = getFirstDescendantOfType(ASTVariableDeclaratorId.class);
if (decl != null) {

View File

@ -94,6 +94,7 @@ public class ASTVariableDeclaratorId extends AbstractJavaTypeNode implements Dim
*/
@Override
@Deprecated
@DeprecatedAttribute(replaceWith = "@ArrayType")
public boolean isArray() {
return arrayDepth > 0;
}

View File

@ -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<ASTBlockStatement> blocks = node.findDescendantsOfType(ASTBlockStatement.class);
if (blocks.size() == 1) {