Search in sources :

Example 1 with JavaOperationSigMask

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);
}
Also used : ASTCompilationUnit(net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit) ASTMethodDeclaration(net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration) JavaOperationSigMask(net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask) JavaParserVisitorAdapter(net.sourceforge.pmd.lang.java.ast.JavaParserVisitorAdapter) Test(org.junit.Test)

Example 2 with JavaOperationSigMask

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));
    }
}
Also used : Role(net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature.Role) JavaOperationSigMask(net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask) JavaOperationQualifiedName(net.sourceforge.pmd.lang.java.qname.JavaOperationQualifiedName) JavaQualifiedName(net.sourceforge.pmd.lang.java.ast.JavaQualifiedName) Test(org.junit.Test)

Example 3 with JavaOperationSigMask

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);
}
Also used : JavaOperationSigMask(net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask)

Example 4 with JavaOperationSigMask

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;
}
Also used : JavaOperationSigMask(net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask)

Example 5 with JavaOperationSigMask

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)));
        }
    }
}
Also used : JavaOperationSigMask(net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask) JavaOperationSignature(net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature) ASTMethodOrConstructorDeclaration(net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration) Test(org.junit.Test)

Aggregations

JavaOperationSigMask (net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask)8 Test (org.junit.Test)6 ASTMethodOrConstructorDeclaration (net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration)4 ASTMethodDeclaration (net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration)3 JavaOperationSignature (net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature)2 JavaOperationQualifiedName (net.sourceforge.pmd.lang.java.qname.JavaOperationQualifiedName)2 ASTCompilationUnit (net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit)1 ASTConstructorDeclaration (net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration)1 JavaParserVisitorAdapter (net.sourceforge.pmd.lang.java.ast.JavaParserVisitorAdapter)1 JavaQualifiedName (net.sourceforge.pmd.lang.java.ast.JavaQualifiedName)1 Role (net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature.Role)1