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)));
}
}
}
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)));
}
}
}
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));
}
}
Aggregations