use of net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature 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.multifile.signature.JavaOperationSignature 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.multifile.signature.JavaOperationSignature 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)));
}
}
}
use of net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature in project pmd by pmd.
the class PackageStatsTest method testAddOperation.
@Test
public void testAddOperation() {
final String TEST = "package org.foo; class Boo{ " + "public void foo(){}}";
ASTMethodOrConstructorDeclaration node = getOrderedNodes(ASTMethodDeclaration.class, TEST).get(0);
JavaOperationQualifiedName qname = node.getQualifiedName();
JavaOperationSignature signature = JavaOperationSignature.buildFor(node);
assertFalse(pack.hasMatchingSig(qname, new JavaOperationSigMask()));
ClassStats clazz = pack.getClassStats(qname.getClassName(), true);
clazz.addOperation("foo()", signature);
assertTrue(pack.hasMatchingSig(qname, new JavaOperationSigMask()));
}
Aggregations