Search in sources :

Example 1 with JavaFieldSignature

use of net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSignature 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 JavaFieldSignature

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

the class SignatureTest method isFinalFieldTest.

@Test
public void isFinalFieldTest() {
    final String TEST = "class Bzaz{" + "public String x;" + "private int y;" + "private final int a;" + "protected final double u;" + "final long v;" + "}";
    List<ASTFieldDeclaration> nodes = getOrderedNodes(ASTFieldDeclaration.class, TEST);
    List<JavaFieldSignature> sigs = new ArrayList<>();
    for (ASTFieldDeclaration node : nodes) {
        sigs.add(JavaFieldSignature.buildFor(node));
    }
    assertFalse(sigs.get(0).isFinal);
    assertFalse(sigs.get(1).isFinal);
    assertTrue(sigs.get(2).isFinal);
    assertTrue(sigs.get(3).isFinal);
    assertTrue(sigs.get(4).isFinal);
}
Also used : ASTFieldDeclaration(net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration) ArrayList(java.util.ArrayList) JavaFieldSignature(net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSignature) Test(org.junit.Test)

Example 3 with JavaFieldSignature

use of net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSignature 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 JavaFieldSignature

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

the class SignatureTest method isStaticFieldTest.

@Test
public void isStaticFieldTest() {
    final String TEST = "class Bzaz{" + "public final String x;" + "private int y;" + "private static int a;" + "protected static final double u;" + "static long v;" + "}";
    List<ASTFieldDeclaration> nodes = getOrderedNodes(ASTFieldDeclaration.class, TEST);
    List<JavaFieldSignature> sigs = new ArrayList<>();
    for (ASTFieldDeclaration node : nodes) {
        sigs.add(JavaFieldSignature.buildFor(node));
    }
    assertFalse(sigs.get(0).isStatic);
    assertFalse(sigs.get(1).isStatic);
    assertTrue(sigs.get(2).isStatic);
    assertTrue(sigs.get(3).isStatic);
    assertTrue(sigs.get(4).isStatic);
}
Also used : ASTFieldDeclaration(net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration) ArrayList(java.util.ArrayList) JavaFieldSignature(net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSignature) Test(org.junit.Test)

Aggregations

ASTFieldDeclaration (net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration)4 JavaFieldSignature (net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSignature)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 JavaFieldSigMask (net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSigMask)2 JavaTypeQualifiedName (net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName)1