Search in sources :

Example 11 with JavaTypeQualifiedName

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

the class JavaQualifiedNameTest method testParseLocalClasses.

@Test
public void testParseLocalClasses() {
    final String SIMPLE = "foo.bar.Bzaz$1Local";
    final String NESTED = "foo.Bar$1Local$Nested";
    JavaTypeQualifiedName simple = (JavaTypeQualifiedName) QualifiedNameFactory.ofString(SIMPLE);
    JavaTypeQualifiedName nested = (JavaTypeQualifiedName) QualifiedNameFactory.ofString(NESTED);
    assertNotNull(simple);
    assertTrue(simple.isLocalClass());
    assertFalse(simple.isAnonymousClass());
    assertNotNull(nested);
    assertFalse(nested.isLocalClass());
    assertFalse(simple.isAnonymousClass());
    assertEquals(SIMPLE, simple.toString());
    assertEquals(NESTED, nested.toString());
}
Also used : JavaTypeQualifiedName(net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName) Test(org.junit.Test)

Example 12 with JavaTypeQualifiedName

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

the class JavaQualifiedNameTest method testParseAnonymousClass.

@Test
public void testParseAnonymousClass() {
    final String SIMPLE = "Bzaz$12$13";
    JavaTypeQualifiedName simple = (JavaTypeQualifiedName) QualifiedNameFactory.ofString(SIMPLE);
    assertNotNull(simple);
    assertTrue(simple.isAnonymousClass());
    assertFalse(simple.isLocalClass());
    assertEquals("12", simple.getClassList().get(1));
    assertEquals("13", simple.getClassList().get(2));
    assertEquals(SIMPLE, simple.toString());
}
Also used : JavaTypeQualifiedName(net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName) Test(org.junit.Test)

Example 13 with JavaTypeQualifiedName

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

the class JavaQualifiedNameTest method testPackage.

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

Example 14 with JavaTypeQualifiedName

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

Example 15 with JavaTypeQualifiedName

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

the class PackageStatsTest method testAddClass.

@Test
public void testAddClass() {
    JavaTypeQualifiedName qname = (JavaTypeQualifiedName) QualifiedNameFactory.ofString("org.foo.Boo");
    assertNull(pack.getClassStats(qname, false));
    assertNotNull(pack.getClassStats(qname, true));
    // now it's added, this shouldn't return null
    assertNotNull(pack.getClassStats(qname, false));
}
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