Search in sources :

Example 1 with JavaOperationSignature

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

the class SignatureTest method isAbstractOperationTest.

@Test
public void isAbstractOperationTest() {
    final String TEST = "abstract class Bzaz{ int x; " + "public static abstract void foo();" + "protected abstract int bar(int x);" + "int getX(){return x;}" + "void setX(int a){x=a;}" + "public void doSomething(){}}";
    List<ASTMethodOrConstructorDeclaration> nodes = getOrderedNodes(ASTMethodOrConstructorDeclaration.class, TEST);
    List<JavaOperationSignature> sigs = new ArrayList<>();
    for (ASTMethodOrConstructorDeclaration node : nodes) {
        sigs.add(JavaOperationSignature.buildFor(node));
    }
    assertTrue(sigs.get(0).isAbstract);
    assertTrue(sigs.get(1).isAbstract);
    assertFalse(sigs.get(2).isAbstract);
    assertFalse(sigs.get(3).isAbstract);
    assertFalse(sigs.get(4).isAbstract);
}
Also used : ArrayList(java.util.ArrayList) JavaOperationSignature(net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature) ASTMethodOrConstructorDeclaration(net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration) Test(org.junit.Test)

Example 2 with JavaOperationSignature

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

the class SignatureTest method operationRoleTest.

@Test
public void operationRoleTest() {
    final String TEST = "class Bzaz{ int x; " + "public static void foo(){} " + "Bzaz(){} " + "int getX(){return x;}" + " void setX(int a){x=a;}" + " public void doSomething(){}}";
    List<ASTMethodOrConstructorDeclaration> nodes = getOrderedNodes(ASTMethodOrConstructorDeclaration.class, TEST);
    List<JavaOperationSignature> sigs = new ArrayList<>();
    for (ASTMethodOrConstructorDeclaration node : nodes) {
        sigs.add(JavaOperationSignature.buildFor(node));
    }
    assertEquals(Role.STATIC, sigs.get(0).role);
    assertEquals(Role.CONSTRUCTOR, sigs.get(1).role);
    assertEquals(Role.GETTER_OR_SETTER, sigs.get(2).role);
    assertEquals(Role.GETTER_OR_SETTER, sigs.get(3).role);
    assertEquals(Role.METHOD, sigs.get(4).role);
}
Also used : ArrayList(java.util.ArrayList) JavaOperationSignature(net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature) ASTMethodOrConstructorDeclaration(net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration) Test(org.junit.Test)

Example 3 with JavaOperationSignature

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

the class SigMaskTest method testEmptyOperationMask.

/**
 * Ensure any non-abstract method is covered by a newly created mask.
 */
@Test
public void testEmptyOperationMask() {
    List<ASTMethodOrConstructorDeclaration> nodes = getOrderedNodes(ASTMethodOrConstructorDeclaration.class, TEST_OPERATIONS);
    SigMask<JavaOperationSignature> mask = new JavaOperationSigMask();
    for (ASTMethodOrConstructorDeclaration node : nodes) {
        if (node.isAbstract()) {
            assertFalse(mask.covers(JavaOperationSignature.buildFor(node)));
        } else {
            assertTrue(mask.covers(JavaOperationSignature.buildFor(node)));
        }
    }
}
Also used : JavaOperationSigMask(net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask) JavaOperationSignature(net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature) ASTMethodOrConstructorDeclaration(net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration) Test(org.junit.Test)

Example 4 with JavaOperationSignature

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

the class PackageStatsTest method testAddOperation.

@Test
public void testAddOperation() {
    final String TEST = "package org.foo; class Boo{ " + "public void foo(){}}";
    ASTMethodOrConstructorDeclaration node = getOrderedNodes(ASTMethodDeclaration.class, TEST).get(0);
    JavaOperationQualifiedName qname = node.getQualifiedName();
    JavaOperationSignature signature = JavaOperationSignature.buildFor(node);
    assertFalse(pack.hasMatchingSig(qname, new JavaOperationSigMask()));
    ClassStats clazz = pack.getClassStats(qname.getClassName(), true);
    clazz.addOperation("foo()", signature);
    assertTrue(pack.hasMatchingSig(qname, new JavaOperationSigMask()));
}
Also used : ASTMethodDeclaration(net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration) JavaOperationSigMask(net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask) JavaOperationSignature(net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature) JavaOperationQualifiedName(net.sourceforge.pmd.lang.java.qname.JavaOperationQualifiedName) ASTMethodOrConstructorDeclaration(net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration) Test(org.junit.Test)

Aggregations

ASTMethodOrConstructorDeclaration (net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration)4 JavaOperationSignature (net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 JavaOperationSigMask (net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask)2 ASTMethodDeclaration (net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration)1 JavaOperationQualifiedName (net.sourceforge.pmd.lang.java.qname.JavaOperationQualifiedName)1