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