use of net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration in project pmd by pmd.
the class ProjectMemoizerTest method visitWith.
private List<Integer> visitWith(ASTCompilationUnit acu, final boolean force) {
final JavaProjectMemoizer toplevel = JavaMetrics.getFacade().getLanguageSpecificProjectMemoizer();
final List<Integer> result = new ArrayList<>();
acu.jjtAccept(new JavaParserVisitorReducedAdapter() {
@Override
public Object visit(ASTMethodOrConstructorDeclaration node, Object data) {
MetricMemoizer<MethodLikeNode> op = toplevel.getOperationMemoizer(node.getQualifiedName());
result.add((int) JavaMetricsComputer.INSTANCE.computeForOperation(opMetricKey, node, force, MetricOptions.emptyOptions(), op));
return super.visit(node, data);
}
@Override
public Object visit(ASTAnyTypeDeclaration node, Object data) {
MetricMemoizer<ASTAnyTypeDeclaration> clazz = toplevel.getClassMemoizer(node.getQualifiedName());
result.add((int) JavaMetricsComputer.INSTANCE.computeForType(classMetricKey, node, force, MetricOptions.emptyOptions(), clazz));
return super.visit(node, data);
}
}, null);
return result;
}
use of net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration in project pmd by pmd.
the class SignatureTest method isAbstractOperationTest.
@Test
public void isAbstractOperationTest() {
final String TEST = "abstract class Bzaz{ int x; " + "public static abstract void foo();" + "protected abstract int bar(int x);" + "int getX(){return x;}" + "void setX(int a){x=a;}" + "public void doSomething(){}}";
List<ASTMethodOrConstructorDeclaration> nodes = getOrderedNodes(ASTMethodOrConstructorDeclaration.class, TEST);
List<JavaOperationSignature> sigs = new ArrayList<>();
for (ASTMethodOrConstructorDeclaration node : nodes) {
sigs.add(JavaOperationSignature.buildFor(node));
}
assertTrue(sigs.get(0).isAbstract);
assertTrue(sigs.get(1).isAbstract);
assertFalse(sigs.get(2).isAbstract);
assertFalse(sigs.get(3).isAbstract);
assertFalse(sigs.get(4).isAbstract);
}
use of net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration in project pmd by pmd.
the class SignatureTest method operationRoleTest.
@Test
public void operationRoleTest() {
final String TEST = "class Bzaz{ int x; " + "public static void foo(){} " + "Bzaz(){} " + "int getX(){return x;}" + " void setX(int a){x=a;}" + " public void doSomething(){}}";
List<ASTMethodOrConstructorDeclaration> nodes = getOrderedNodes(ASTMethodOrConstructorDeclaration.class, TEST);
List<JavaOperationSignature> sigs = new ArrayList<>();
for (ASTMethodOrConstructorDeclaration node : nodes) {
sigs.add(JavaOperationSignature.buildFor(node));
}
assertEquals(Role.STATIC, sigs.get(0).role);
assertEquals(Role.CONSTRUCTOR, sigs.get(1).role);
assertEquals(Role.GETTER_OR_SETTER, sigs.get(2).role);
assertEquals(Role.GETTER_OR_SETTER, sigs.get(3).role);
assertEquals(Role.METHOD, sigs.get(4).role);
}
use of net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration in project pmd by pmd.
the class AbstractJavaClassMetric method countMatchingOpSigs.
/**
* Counts the operations matching the signature mask in this class.
*
* @param classNode The class on which to count
* @param mask The mask
*
* @return The number of operations matching the signature mask
*/
protected int countMatchingOpSigs(ASTAnyTypeDeclaration classNode, JavaOperationSigMask mask) {
int count = 0;
List<ASTMethodOrConstructorDeclaration> decls = getMethodsAndConstructors(classNode);
for (ASTMethodOrConstructorDeclaration decl : decls) {
if (mask.covers(decl.getSignature())) {
count++;
}
}
return count;
}
use of net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration in project pmd by pmd.
the class SigMaskTest method testEmptyOperationMask.
/**
* Ensure any non-abstract method is covered by a newly created mask.
*/
@Test
public void testEmptyOperationMask() {
List<ASTMethodOrConstructorDeclaration> nodes = getOrderedNodes(ASTMethodOrConstructorDeclaration.class, TEST_OPERATIONS);
SigMask<JavaOperationSignature> mask = new JavaOperationSigMask();
for (ASTMethodOrConstructorDeclaration node : nodes) {
if (node.isAbstract()) {
assertFalse(mask.covers(JavaOperationSignature.buildFor(node)));
} else {
assertTrue(mask.covers(JavaOperationSignature.buildFor(node)));
}
}
}
Aggregations