use of net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask in project pmd by pmd.
the class JavaMultifileVisitorTest method testOperationsAreThere.
@Test
public void testOperationsAreThere() {
ASTCompilationUnit acu = parseAndVisitForClass(MultifileVisitorTestData2.class);
final ProjectMirror toplevel = PackageStats.INSTANCE;
final JavaOperationSigMask opMask = new JavaOperationSigMask();
// We could parse qnames from string but probably simpler to do that
acu.jjtAccept(new JavaParserVisitorAdapter() {
@Override
public Object visit(ASTMethodDeclaration node, Object data) {
assertTrue(toplevel.hasMatchingSig(node.getQualifiedName(), opMask));
return data;
}
}, null);
}
use of net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask in project pmd by pmd.
the class JavaMultifileVisitorTest method testBothClassesOperationsAreThere.
@Test
public void testBothClassesOperationsAreThere() {
parseAndVisitForClass(MultifileVisitorTestData2.class);
parseAndVisitForClass(MultifileVisitorTestData2.class);
final ProjectMirror toplevel = PackageStats.INSTANCE;
final JavaOperationSigMask operationSigMask = new JavaOperationSigMask();
JavaQualifiedName clazz = QualifiedNameFactory.ofClass(MultifileVisitorTestData2.class);
JavaQualifiedName clazz2 = QualifiedNameFactory.ofClass(MultifileVisitorTestData2.class);
String[] opNames = { "getX()", "getY()", "setX(String)", "setY(String)", "mymethod1()", "mymethod2()", "mystatic1()", "mystatic2(String)", "mystatic2(String, String)" };
Role[] roles = { Role.GETTER_OR_SETTER, Role.GETTER_OR_SETTER, Role.GETTER_OR_SETTER, Role.GETTER_OR_SETTER, Role.METHOD, Role.METHOD, Role.STATIC, Role.STATIC, Role.STATIC };
for (int i = 0; i < opNames.length; i++) {
operationSigMask.restrictRolesTo(roles[i]);
JavaOperationQualifiedName name1 = (JavaOperationQualifiedName) QualifiedNameFactory.ofString(clazz.toString() + "#" + opNames[i]);
JavaOperationQualifiedName name2 = (JavaOperationQualifiedName) QualifiedNameFactory.ofString(clazz2.toString() + "#" + opNames[i]);
assertTrue(toplevel.hasMatchingSig(name1, operationSigMask));
assertTrue(toplevel.hasMatchingSig(name2, operationSigMask));
}
}
use of net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask in project pmd by pmd.
the class NoamMetric method computeFor.
@Override
public double computeFor(ASTAnyTypeDeclaration node, MetricOptions options) {
JavaOperationSigMask mask = new JavaOperationSigMask();
mask.restrictRolesTo(Role.GETTER_OR_SETTER);
mask.restrictVisibilitiesTo(Visibility.PUBLIC);
return (double) countMatchingOpSigs(node, mask);
}
use of net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask in project pmd by pmd.
the class WocMetric method computeFor.
@Override
public double computeFor(ASTAnyTypeDeclaration node, MetricOptions options) {
JavaOperationSigMask mask = new JavaOperationSigMask();
mask.forbid(Role.CONSTRUCTOR, Role.GETTER_OR_SETTER);
mask.restrictVisibilitiesTo(Visibility.PUBLIC);
int functionalMethods = countMatchingOpSigs(node, mask);
mask.coverAllRoles();
int totalPublicMethods = countMatchingOpSigs(node, mask);
return functionalMethods / (double) totalPublicMethods;
}
use of net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask 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