Fix tests
This commit is contained in:
1 parent
c7b4ec962c
commit
0307300891
6 files changed
+30
-22
No files matched your search
+20
-5
@@ -6,13 +6,17 @@ package net.sourceforge.pmd.lang.java.ast.internal;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTArrayType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTEnumDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTFormalParameter;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTFormalParameters;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTRecordDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTType;
|
||||
|
||||
/**
|
||||
* @author Clément Fournier
|
||||
@@ -39,10 +43,7 @@ public final class PrettyPrintingUtil {
|
||||
}
|
||||
first = false;
|
||||
|
||||
sb.append(param.getTypeNode().getTypeImage());
|
||||
if (param.isVarargs()) {
|
||||
sb.append("...");
|
||||
}
|
||||
prettyPrintTypeNode(param.getTypeNode(), sb);
|
||||
}
|
||||
|
||||
sb.append(')');
|
||||
@@ -50,11 +51,25 @@ public final class PrettyPrintingUtil {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void prettyPrintTypeNode(ASTType t, StringBuilder sb) {
|
||||
if (t instanceof ASTPrimitiveType) {
|
||||
sb.append(((ASTPrimitiveType) t).getKind().getSimpleName());
|
||||
} else if (t instanceof ASTClassOrInterfaceType) {
|
||||
sb.append(((ASTClassOrInterfaceType) t).getSimpleName());
|
||||
} else if (t instanceof ASTArrayType) {
|
||||
prettyPrintTypeNode(((ASTArrayType) t).getElementType(), sb);
|
||||
int depth = ((ASTArrayType) t).getArrayDepth();
|
||||
for (int i = 0; i < depth; i++) {
|
||||
sb.append("[]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a normalized method name. This just looks at the image of the types of the parameters.
|
||||
*/
|
||||
public static String displaySignature(ASTMethodOrConstructorDeclaration node) {
|
||||
ASTFormalParameters params = node.getFirstDescendantOfType(ASTFormalParameters.class);
|
||||
ASTFormalParameters params = node.getFormalParameters();
|
||||
String name = node instanceof ASTMethodDeclaration ? node.getName() : node.getImage();
|
||||
|
||||
return displaySignature(name, params);
|
||||
|
||||
@@ -45,6 +45,7 @@ import net.sourceforge.pmd.lang.metrics.MetricsUtil;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("PMD.UnusedFormalParameter") // #2838
|
||||
public final class JavaMetrics {
|
||||
|
||||
|
||||
@@ -298,7 +299,7 @@ public final class JavaMetrics {
|
||||
}
|
||||
}
|
||||
|
||||
private static int computeAtfd(JavaNode node, MetricOptions options) {
|
||||
private static int computeAtfd(JavaNode node, MetricOptions ignored) {
|
||||
MutableInt result = new MutableInt(0);
|
||||
node.acceptVisitor(new AtfdBaseVisitor(), result);
|
||||
return result.getValue();
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import net.sourceforge.pmd.lang.metrics.MetricOptions;
|
||||
*
|
||||
* @author Andreas Pabst
|
||||
*/
|
||||
public class ClassFanOutVisitor extends JavaVisitorBase<Set<JClassSymbol>, Void> {
|
||||
public final class ClassFanOutVisitor extends JavaVisitorBase<Set<JClassSymbol>, Void> {
|
||||
|
||||
private static final ClassFanOutVisitor INCLUDE_JLANG = new ClassFanOutVisitor(true);
|
||||
private static final ClassFanOutVisitor EXCLUDE_JLANG = new ClassFanOutVisitor(false);
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public class JavaMetricsProviderTest {
|
||||
|
||||
Map<Metric<?, ?>, Number> results = provider.computeAllMetricsFor(type);
|
||||
|
||||
assertEquals(10, results.size());
|
||||
assertEquals(9, results.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -587,7 +587,7 @@ fun TreeNodeWrapper<Node, *>.switchLabel(assertions: NodeSpec<ASTSwitchLabel> =
|
||||
fun TreeNodeWrapper<Node, *>.switchDefaultLabel(assertions: NodeSpec<ASTSwitchLabel> = EmptyAssertions) =
|
||||
child<ASTSwitchLabel>(ignoreChildren = assertions == EmptyAssertions) {
|
||||
it::isDefault shouldBe true
|
||||
it::getExprList shouldBe emptyList()
|
||||
it.exprList.toList() shouldBe emptyList()
|
||||
assertions()
|
||||
}
|
||||
|
||||
|
||||
+5
-13
@@ -149,19 +149,17 @@ public enum EnumWithInterfaces implements InterfaceWithBound<int[]> {
|
||||
<test-code>
|
||||
<description>Consider enum methods 2</description>
|
||||
<expected-problems>2</expected-problems>
|
||||
<expected-linenumbers>9,15</expected-linenumbers>
|
||||
<expected-linenumbers>5,10</expected-linenumbers>
|
||||
<code><![CDATA[
|
||||
package net.sourceforge.pmd.lang.java.rule.bestpractices.missingoverride;
|
||||
|
||||
public enum EnumWithInterfaces implements InterfaceWithBound<int[]> {
|
||||
Foo {
|
||||
@Override
|
||||
public void handle(int[] ints) {
|
||||
super.handle(ints);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void handle(int[] ints) {
|
||||
|
||||
}
|
||||
@@ -173,8 +171,8 @@ public enum EnumWithInterfaces implements InterfaceWithBound<int[]> {
|
||||
<test-code>
|
||||
<description>Consider methods with array parameters</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages> <!--FIXME should be arrayParams(String, int[], StringBuilder[]) - caused by #910 -->
|
||||
<message>The method 'arrayParams(String, int, StringBuilder)' is missing an @Override annotation.</message>
|
||||
<expected-messages>
|
||||
<message>The method 'arrayParams(String, int[], StringBuilder[])' is missing an @Override annotation.</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
package net.sourceforge.pmd.lang.java.rule.bestpractices.missingoverride;
|
||||
@@ -224,22 +222,16 @@ public enum EnumWithAnonClass {
|
||||
<description>Consider method inherited from generic supertype</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>The method 'supports(ASTAnyTypeDeclaration)' is missing an @Override annotation.</message>
|
||||
<message>The method 'handle(int[])' is missing an @Override annotation.</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
package net.sourceforge.pmd.lang.java.rule.bestpractices.missingoverride;
|
||||
|
||||
public enum EnumWithInterfaces implements InterfaceWithBound<int[]> {
|
||||
Foo {
|
||||
@Override
|
||||
public void handle(int[] ints) {
|
||||
super.handle(ints);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void handle(int[] ints) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,7 +296,7 @@ public class SubclassWithGenericMethod extends AbstractClass {
|
||||
<description>Consider varargs parameter</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>The method 'setProperty(MultiValuePropertyDescriptor, V...)' is missing an @Override annotation.</message>
|
||||
<message>The method 'setProperty(MultiValuePropertyDescriptor, V[])' is missing an @Override annotation.</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
package net.sourceforge.pmd.lang.rule;
|
||||
|
||||
Reference in new issue
Block a user