Search in sources :

Example 6 with JavaFieldSigMask

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

the class SigMaskTest method testFinalFields.

@Test
public void testFinalFields() {
    List<ASTFieldDeclaration> nodes = getOrderedNodes(ASTFieldDeclaration.class, TEST_FIELDS);
    JavaFieldSigMask mask = new JavaFieldSigMask();
    mask.forbidFinal();
    for (ASTFieldDeclaration node : nodes) {
        if (node.isFinal()) {
            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)

Example 7 with JavaFieldSigMask

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

the class SigMaskTest method testFieldvisibility.

@Test
public void testFieldvisibility() {
    List<ASTFieldDeclaration> nodes = getOrderedNodes(ASTFieldDeclaration.class, TEST_FIELDS);
    JavaFieldSigMask mask = new JavaFieldSigMask();
    mask.restrictVisibilitiesTo(Visibility.PUBLIC);
    for (ASTFieldDeclaration node : nodes) {
        if (node.isPublic()) {
            assertTrue(mask.covers(JavaFieldSignature.buildFor(node)));
        } else {
            assertFalse(mask.covers(JavaFieldSignature.buildFor(node)));
        }
    }
    mask.restrictVisibilitiesTo(Visibility.PRIVATE);
    for (ASTFieldDeclaration node : nodes) {
        if (node.isPrivate()) {
            assertTrue(mask.covers(JavaFieldSignature.buildFor(node)));
        } else {
            assertFalse(mask.covers(JavaFieldSignature.buildFor(node)));
        }
    }
    mask.restrictVisibilitiesTo(Visibility.PACKAGE);
    for (ASTFieldDeclaration node : nodes) {
        if (node.isPackagePrivate()) {
            assertTrue(mask.covers(JavaFieldSignature.buildFor(node)));
        } else {
            assertFalse(mask.covers(JavaFieldSignature.buildFor(node)));
        }
    }
    mask.restrictVisibilitiesTo(Visibility.PROTECTED);
    for (ASTFieldDeclaration node : nodes) {
        if (node.isProtected()) {
            assertTrue(mask.covers(JavaFieldSignature.buildFor(node)));
        } else {
            assertFalse(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)

Example 8 with JavaFieldSigMask

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

the class JavaMultifileVisitorTest method testBothClassesFieldsAreThere.

@Test
public void testBothClassesFieldsAreThere() {
    parseAndVisitForClass(MultifileVisitorTestData2.class);
    parseAndVisitForClass(MultifileVisitorTestData2.class);
    final ProjectMirror toplevel = PackageStats.INSTANCE;
    final JavaFieldSigMask fieldSigMask = new JavaFieldSigMask();
    JavaTypeQualifiedName clazz = QualifiedNameFactory.ofClass(MultifileVisitorTestData2.class);
    JavaTypeQualifiedName clazz2 = 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));
        assertTrue(toplevel.hasMatchingSig(clazz2, 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)

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