Search in sources :

Example 1 with JavaOperationQualifiedName

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

the class JavaMultifileVisitorTest method testBothClassesOperationsAreThere.

@Test
public void testBothClassesOperationsAreThere() {
    parseAndVisitForClass(MultifileVisitorTestData2.class);
    parseAndVisitForClass(MultifileVisitorTestData2.class);
    final ProjectMirror toplevel = PackageStats.INSTANCE;
    final JavaOperationSigMask operationSigMask = new JavaOperationSigMask();
    JavaQualifiedName clazz = QualifiedNameFactory.ofClass(MultifileVisitorTestData2.class);
    JavaQualifiedName clazz2 = QualifiedNameFactory.ofClass(MultifileVisitorTestData2.class);
    String[] opNames = { "getX()", "getY()", "setX(String)", "setY(String)", "mymethod1()", "mymethod2()", "mystatic1()", "mystatic2(String)", "mystatic2(String, String)" };
    Role[] roles = { Role.GETTER_OR_SETTER, Role.GETTER_OR_SETTER, Role.GETTER_OR_SETTER, Role.GETTER_OR_SETTER, Role.METHOD, Role.METHOD, Role.STATIC, Role.STATIC, Role.STATIC };
    for (int i = 0; i < opNames.length; i++) {
        operationSigMask.restrictRolesTo(roles[i]);
        JavaOperationQualifiedName name1 = (JavaOperationQualifiedName) QualifiedNameFactory.ofString(clazz.toString() + "#" + opNames[i]);
        JavaOperationQualifiedName name2 = (JavaOperationQualifiedName) QualifiedNameFactory.ofString(clazz2.toString() + "#" + opNames[i]);
        assertTrue(toplevel.hasMatchingSig(name1, operationSigMask));
        assertTrue(toplevel.hasMatchingSig(name2, operationSigMask));
    }
}
Also used : Role(net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature.Role) JavaOperationSigMask(net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask) JavaOperationQualifiedName(net.sourceforge.pmd.lang.java.qname.JavaOperationQualifiedName) JavaQualifiedName(net.sourceforge.pmd.lang.java.ast.JavaQualifiedName) Test(org.junit.Test)

Example 2 with JavaOperationQualifiedName

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

the class JavaQualifiedNameTest method testConstructorWithParams.

@Test
public void testConstructorWithParams() {
    final String TEST = "package bar; class Bzaz{ public Bzaz(int j, String k){}}";
    List<ASTConstructorDeclaration> nodes = getNodes(ASTConstructorDeclaration.class, TEST);
    for (ASTConstructorDeclaration declaration : nodes) {
        JavaOperationQualifiedName qname = declaration.getQualifiedName();
        assertEquals("bar.Bzaz#Bzaz(int, String)", qname.toString());
        assertNotNull(qname.getOperation());
        assertEquals("Bzaz(int, String)", qname.getOperation());
    }
}
Also used : JavaOperationQualifiedName(net.sourceforge.pmd.lang.java.qname.JavaOperationQualifiedName) Test(org.junit.Test)

Example 3 with JavaOperationQualifiedName

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

the class JavaQualifiedNameTest method testConstructor.

@Test
public void testConstructor() {
    final String TEST = "package bar; class Bzaz{ public Bzaz(){}}";
    List<ASTConstructorDeclaration> nodes = getNodes(ASTConstructorDeclaration.class, TEST);
    for (ASTConstructorDeclaration declaration : nodes) {
        JavaOperationQualifiedName qname = declaration.getQualifiedName();
        assertEquals("bar.Bzaz#Bzaz()", qname.toString());
        assertNotNull(qname.getOperation());
        assertEquals("Bzaz()", qname.getOperation());
    }
}
Also used : JavaOperationQualifiedName(net.sourceforge.pmd.lang.java.qname.JavaOperationQualifiedName) Test(org.junit.Test)

Example 4 with JavaOperationQualifiedName

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

the class JavaQualifiedNameTest method testMethod.

@Test
public void testMethod() {
    final String TEST = "package bar; class Bzaz{ public void foo(){}}";
    List<ASTMethodDeclaration> nodes = getNodes(ASTMethodDeclaration.class, TEST);
    for (ASTMethodDeclaration declaration : nodes) {
        JavaOperationQualifiedName qname = declaration.getQualifiedName();
        assertEquals("bar.Bzaz#foo()", qname.toString());
        assertNotNull(qname.getOperation());
        assertEquals("foo()", qname.getOperation());
    }
}
Also used : JavaOperationQualifiedName(net.sourceforge.pmd.lang.java.qname.JavaOperationQualifiedName) Test(org.junit.Test)

Example 5 with JavaOperationQualifiedName

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

the class JavaQualifiedNameTest method testParseOperation.

@Test
public void testParseOperation() {
    JavaOperationQualifiedName noparams = (JavaOperationQualifiedName) QualifiedNameFactory.ofString("foo.bar.Bzaz$Bolg#bar()");
    JavaOperationQualifiedName params = (JavaOperationQualifiedName) QualifiedNameFactory.ofString("foo.bar.Bzaz#bar(String, int)");
    assertEquals("bar()", noparams.getOperation());
    assertEquals("bar(String, int)", params.getOperation());
}
Also used : JavaOperationQualifiedName(net.sourceforge.pmd.lang.java.qname.JavaOperationQualifiedName) Test(org.junit.Test)

Aggregations

JavaOperationQualifiedName (net.sourceforge.pmd.lang.java.qname.JavaOperationQualifiedName)8 Test (org.junit.Test)8 JavaOperationSigMask (net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask)2 ASTMethodDeclaration (net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration)1 ASTMethodOrConstructorDeclaration (net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration)1 JavaQualifiedName (net.sourceforge.pmd.lang.java.ast.JavaQualifiedName)1 JavaOperationSignature (net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature)1 Role (net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature.Role)1