Search in sources :

Example 1 with JavaTypeQualifiedName

use of net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName 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 2 with JavaTypeQualifiedName

use of net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName 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 3 with JavaTypeQualifiedName

use of net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName in project pmd by pmd.

the class JavaQualifiedNameTest method testNestedClass.

@Test
public void testNestedClass() {
    final String TEST = "package foo.bar; class Bzaz{ class Bor{ class Foo{}}}";
    List<ASTClassOrInterfaceDeclaration> nodes = getNodes(ASTClassOrInterfaceDeclaration.class, TEST);
    for (ASTClassOrInterfaceDeclaration coid : nodes) {
        JavaTypeQualifiedName qname = coid.getQualifiedName();
        switch(coid.getImage()) {
            case "Foo":
                assertEquals("foo.bar.Bzaz$Bor$Foo", qname.toString());
                assertEquals(3, qname.getClassList().size());
                break;
            default:
                break;
        }
    }
}
Also used : JavaTypeQualifiedName(net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName) Test(org.junit.Test)

Example 4 with JavaTypeQualifiedName

use of net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName in project pmd by pmd.

the class JavaQualifiedNameTest method testEmptyPackage.

@Test
public void testEmptyPackage() {
    final String TEST = "class Foo {}";
    List<ASTClassOrInterfaceDeclaration> nodes = getNodes(ASTClassOrInterfaceDeclaration.class, TEST);
    for (ASTClassOrInterfaceDeclaration coid : nodes) {
        JavaTypeQualifiedName qname = coid.getQualifiedName();
        assertEquals("Foo", qname.toString());
        assertTrue(qname.getPackageList().isEmpty());
        assertTrue(qname.isUnnamedPackage());
        assertEquals(1, qname.getClassList().size());
    }
}
Also used : JavaTypeQualifiedName(net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName) Test(org.junit.Test)

Example 5 with JavaTypeQualifiedName

use of net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName in project pmd by pmd.

the class JavaQualifiedNameTest method testGetType.

@Test
public void testGetType() {
    JavaTypeQualifiedName qname = QualifiedNameFactory.ofClass(ASTAdditiveExpression.class);
    assertEquals(qname.getType(), ASTAdditiveExpression.class);
}
Also used : JavaTypeQualifiedName(net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName) Test(org.junit.Test)

Aggregations

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