Small corrections
This commit is contained in:
@@ -7,7 +7,7 @@ package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
public class ASTAnnotationTypeDeclaration extends AbstractJavaAccessTypeNode implements ASTAnyTypeDeclaration {
|
||||
|
||||
QualifiedName qualifiedName;
|
||||
private QualifiedName qualifiedName;
|
||||
|
||||
public ASTAnnotationTypeDeclaration(int id) {
|
||||
super(id);
|
||||
|
@@ -5,34 +5,47 @@
|
||||
package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
/**
|
||||
* Visitor adapter with convenient visit methods to e.g. treat contructors and methods the same.
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public class JavaParserVisitorReducedAdapter extends JavaParserVisitorAdapter {
|
||||
|
||||
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
|
||||
@Override
|
||||
public final Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
|
||||
return visit((ASTAnyTypeDeclaration) node, data);
|
||||
}
|
||||
|
||||
public Object visit(ASTAnnotationTypeDeclaration node, Object data) {
|
||||
|
||||
@Override
|
||||
public final Object visit(ASTAnnotationTypeDeclaration node, Object data) {
|
||||
return visit((ASTAnyTypeDeclaration) node, data);
|
||||
}
|
||||
|
||||
public Object visit(ASTEnumDeclaration node, Object data) {
|
||||
|
||||
@Override
|
||||
public final Object visit(ASTEnumDeclaration node, Object data) {
|
||||
return visit((ASTAnyTypeDeclaration) node, data);
|
||||
}
|
||||
|
||||
|
||||
public Object visit(ASTAnyTypeDeclaration node, Object data) {
|
||||
return visit((JavaNode) node, data);
|
||||
}
|
||||
|
||||
public Object visit(ASTMethodDeclaration node, Object data) {
|
||||
|
||||
@Override
|
||||
public final Object visit(ASTMethodDeclaration node, Object data) {
|
||||
return visit((ASTMethodOrConstructorDeclaration) node, data);
|
||||
}
|
||||
|
||||
public Object visit(ASTConstructorDeclaration node, Object data) {
|
||||
|
||||
@Override
|
||||
public final Object visit(ASTConstructorDeclaration node, Object data) {
|
||||
return visit((ASTMethodOrConstructorDeclaration) node, data);
|
||||
}
|
||||
|
||||
|
||||
public Object visit(ASTMethodOrConstructorDeclaration node, Object data) {
|
||||
return visit((JavaNode) node, data);
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ public final class QualifiedName {
|
||||
*
|
||||
* @return The qualified name of the node
|
||||
*/
|
||||
public static QualifiedName makeOperationOf(ASTMethodDeclaration node) {
|
||||
/* default */ static QualifiedName makeOperationOf(ASTMethodDeclaration node) {
|
||||
QualifiedName parentQname = node.getFirstParentOfType(ASTAnyTypeDeclaration.class)
|
||||
.getQualifiedName();
|
||||
|
||||
@@ -53,7 +53,7 @@ public final class QualifiedName {
|
||||
*
|
||||
* @return The qualified name of the node
|
||||
*/
|
||||
public static QualifiedName makeOperationOf(ASTConstructorDeclaration node) {
|
||||
/* default */ static QualifiedName makeOperationOf(ASTConstructorDeclaration node) {
|
||||
ASTClassOrInterfaceDeclaration parent = node.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
|
||||
|
||||
return makeOperationOf(parent.getQualifiedName(),
|
||||
@@ -82,7 +82,7 @@ public final class QualifiedName {
|
||||
*
|
||||
* @return The qualified name of the nested class
|
||||
*/
|
||||
public static QualifiedName makeNestedClassOf(QualifiedName parent, String className) {
|
||||
/* default */ static QualifiedName makeNestedClassOf(QualifiedName parent, String className) {
|
||||
QualifiedName qname = new QualifiedName();
|
||||
qname.packages = parent.packages;
|
||||
if (parent.classes[0] != null) {
|
||||
@@ -102,7 +102,7 @@ public final class QualifiedName {
|
||||
*
|
||||
* @return The qualified name of the node
|
||||
*/
|
||||
public static QualifiedName makeOuterClassOf(ASTAnyTypeDeclaration node) {
|
||||
/* default */ static QualifiedName makeOuterClassOf(ASTAnyTypeDeclaration node) {
|
||||
ASTPackageDeclaration pkg = node.getFirstParentOfType(ASTCompilationUnit.class)
|
||||
.getFirstChildOfType(ASTPackageDeclaration.class);
|
||||
|
||||
|
@@ -31,7 +31,7 @@ import net.sourceforge.pmd.lang.java.oom.signature.OperationSignature;
|
||||
* operate on a nested class, retrieve the correct ClassStats with
|
||||
* {@link PackageStats#getClassStats(QualifiedName, boolean)} then use the methods of ClassStats.
|
||||
*
|
||||
* <p>Note that at this level, entities of the DS do not manipulate QualifiedNames anymore, only Strings.
|
||||
* <p>Note that at this level, entities of the data structure do not manipulate QualifiedNames anymore, only Strings.
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
|
@@ -54,13 +54,13 @@ public final class NcssCountRule extends AbstractJavaMetricsRule {
|
||||
super.visit(node, data);
|
||||
|
||||
if (ClassMetricKey.NCSS.supports(node)) {
|
||||
int classCount = (int) Metrics.get(ClassMetricKey.NCSS, node);
|
||||
int classSize = (int) Metrics.get(ClassMetricKey.NCSS, node);
|
||||
int classHighest = (int) Metrics.get(OperationMetricKey.NCSS, node, ResultOption.HIGHEST);
|
||||
|
||||
if (classCount >= classReportLevel || classHighest >= methodReportLevel) {
|
||||
if (classSize >= classReportLevel || classHighest >= methodReportLevel) {
|
||||
String[] messageParams = {node.getTypeKind().name().toLowerCase(),
|
||||
node.getImage(),
|
||||
classCount + " (Highest = " + classHighest + ")", };
|
||||
classSize + " (Highest = " + classHighest + ")", };
|
||||
|
||||
addViolation(data, node, messageParams);
|
||||
}
|
||||
@@ -72,10 +72,10 @@ public final class NcssCountRule extends AbstractJavaMetricsRule {
|
||||
@Override
|
||||
public Object visit(ASTMethodOrConstructorDeclaration node, Object data) {
|
||||
|
||||
int cyclo = (int) Metrics.get(OperationMetricKey.NCSS, node);
|
||||
if (cyclo >= methodReportLevel) {
|
||||
int methodSize = (int) Metrics.get(OperationMetricKey.NCSS, node);
|
||||
if (methodSize >= methodReportLevel) {
|
||||
addViolation(data, node, new String[] {node instanceof ASTMethodDeclaration ? "method" : "constructor",
|
||||
node.getQualifiedName().getOperation(), "" + cyclo, });
|
||||
node.getQualifiedName().getOperation(), "" + methodSize, });
|
||||
}
|
||||
|
||||
return data;
|
||||
|
@@ -20,30 +20,41 @@ import net.sourceforge.pmd.lang.java.ast.JavaNode;
|
||||
*/
|
||||
public abstract class AbstractJavaMetricsRule extends AbstractJavaRule {
|
||||
|
||||
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
|
||||
@Override
|
||||
public final Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
|
||||
return visit((ASTAnyTypeDeclaration) node, data);
|
||||
}
|
||||
|
||||
public Object visit(ASTAnnotationTypeDeclaration node, Object data) {
|
||||
|
||||
@Override
|
||||
public final Object visit(ASTAnnotationTypeDeclaration node, Object data) {
|
||||
return visit((ASTAnyTypeDeclaration) node, data);
|
||||
}
|
||||
|
||||
public Object visit(ASTEnumDeclaration node, Object data) {
|
||||
|
||||
@Override
|
||||
public final Object visit(ASTEnumDeclaration node, Object data) {
|
||||
return visit((ASTAnyTypeDeclaration) node, data);
|
||||
}
|
||||
|
||||
|
||||
public Object visit(ASTAnyTypeDeclaration node, Object data) {
|
||||
return visit((JavaNode) node, data);
|
||||
}
|
||||
|
||||
public Object visit(ASTMethodDeclaration node, Object data) {
|
||||
|
||||
@Override
|
||||
public final Object visit(ASTMethodDeclaration node, Object data) {
|
||||
return visit((ASTMethodOrConstructorDeclaration) node, data);
|
||||
}
|
||||
|
||||
public Object visit(ASTConstructorDeclaration node, Object data) {
|
||||
|
||||
@Override
|
||||
public final Object visit(ASTConstructorDeclaration node, Object data) {
|
||||
return visit((ASTMethodOrConstructorDeclaration) node, data);
|
||||
}
|
||||
|
||||
|
||||
public Object visit(ASTMethodOrConstructorDeclaration node, Object data) {
|
||||
return visit((JavaNode) node, data);
|
||||
}
|
||||
|
Reference in New Issue
Block a user