Search in sources :

Example 1 with JavaFieldSigMask

use of net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSigMask in project pmd by pmd.

the class SigMaskTest method testEmptyFieldMask.

/**
 * Ensure any field is covered by a newly created mask.
 */
@Test
public void testEmptyFieldMask() {
    List<ASTFieldDeclaration> nodes = getOrderedNodes(ASTFieldDeclaration.class, TEST_FIELDS);
    SigMask<JavaFieldSignature> mask = new JavaFieldSigMask();
    for (ASTFieldDeclaration node : nodes) {
        assertTrue(mask.covers(JavaFieldSignature.buildFor(node)));
    }
}
Also used : ASTFieldDeclaration(net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration) JavaFieldSigMask(net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSigMask) JavaFieldSignature(net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSignature) Test(org.junit.Test)

Example 2 with JavaFieldSigMask

use of net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSigMask in project pmd by pmd.

the class JavaMultifileVisitorTest method testFieldsAreThere.

@Test
public void testFieldsAreThere() {
    parseAndVisitForClass(MultifileVisitorTestData2.class);
    final ProjectMirror toplevel = PackageStats.INSTANCE;
    final JavaFieldSigMask fieldSigMask = new JavaFieldSigMask();
    JavaTypeQualifiedName clazz = QualifiedNameFactory.ofClass(MultifileVisitorTestData2.class);
    String[] fieldNames = { "x", "y", "z", "t" };
    Visibility[] visibilities = { Visibility.PUBLIC, Visibility.PRIVATE, Visibility.PROTECTED, Visibility.PACKAGE };
    for (int i = 0; i < fieldNames.length; i++) {
        fieldSigMask.restrictVisibilitiesTo(visibilities[i]);
        assertTrue(toplevel.hasMatchingSig(clazz, fieldNames[i], fieldSigMask));
    }
}
Also used : Visibility(net.sourceforge.pmd.lang.java.multifile.signature.JavaSignature.Visibility) JavaFieldSigMask(net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSigMask) JavaTypeQualifiedName(net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName) Test(org.junit.Test)

Example 3 with JavaFieldSigMask

use of net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSigMask in project pmd by pmd.

the class PackageStatsTest method testAddField.

@Test
public void testAddField() {
    final String TEST = "package org.foo; class Boo{ " + "public String bar;}";
    ASTFieldDeclaration node = getOrderedNodes(ASTFieldDeclaration.class, TEST).get(0);
    JavaTypeQualifiedName qname = (JavaTypeQualifiedName) QualifiedNameFactory.ofString("org.foo.Boo");
    String fieldName = "bar";
    JavaFieldSignature signature = JavaFieldSignature.buildFor(node);
    assertFalse(pack.hasMatchingSig(qname, fieldName, new JavaFieldSigMask()));
    ClassStats clazz = pack.getClassStats(qname, true);
    clazz.addField(fieldName, signature);
    assertTrue(pack.hasMatchingSig(qname, fieldName, new JavaFieldSigMask()));
}
Also used : ASTFieldDeclaration(net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration) JavaFieldSigMask(net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSigMask) JavaTypeQualifiedName(net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName) JavaFieldSignature(net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSignature) Test(org.junit.Test)

Example 4 with JavaFieldSigMask

use of net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSigMask in project pmd by pmd.

the class NopaMetric method computeFor.

@Override
public double computeFor(ASTAnyTypeDeclaration node, MetricOptions options) {
    JavaFieldSigMask mask = new JavaFieldSigMask();
    mask.restrictVisibilitiesTo(Visibility.PUBLIC);
    return (double) countMatchingFieldSigs(node, mask);
}
Also used : JavaFieldSigMask(net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSigMask)

Example 5 with JavaFieldSigMask

use of net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSigMask in project pmd by pmd.

the class SigMaskTest method testStaticFields.

@Test
public void testStaticFields() {
    List<ASTFieldDeclaration> nodes = getOrderedNodes(ASTFieldDeclaration.class, TEST_FIELDS);
    JavaFieldSigMask mask = new JavaFieldSigMask();
    mask.forbidStatic();
    for (ASTFieldDeclaration node : nodes) {
        if (node.isStatic()) {
            assertFalse(mask.covers(JavaFieldSignature.buildFor(node)));
        } else {
            assertTrue(mask.covers(JavaFieldSignature.buildFor(node)));
        }
    }
}
Also used : ASTFieldDeclaration(net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration) JavaFieldSigMask(net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSigMask) Test(org.junit.Test)

Aggregations

JavaFieldSigMask (net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSigMask)8 Test (org.junit.Test)7 ASTFieldDeclaration (net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration)5 JavaTypeQualifiedName (net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName)3 JavaFieldSignature (net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSignature)2 Visibility (net.sourceforge.pmd.lang.java.multifile.signature.JavaSignature.Visibility)2