Search in sources :

Example 1 with JavaSignature

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

the class SignatureTest method visibilityTest.

// common to operation and field signatures
@Test
public void visibilityTest() {
    final String TEST = "class Bzaz{ " + "public int bar;" + "String k;" + "protected double d;" + "private int i;" + "protected int x;" + "public Bzaz(){} " + "void bar(){} " + "protected void foo(int x){}" + "private Bzaz(int y){}" + "}";
    List<ASTMethodOrConstructorDeclaration> operationDeclarations = getOrderedNodes(ASTMethodOrConstructorDeclaration.class, TEST);
    List<ASTFieldDeclaration> fieldDeclarations = getOrderedNodes(ASTFieldDeclaration.class, TEST);
    List<JavaSignature> sigs = new ArrayList<>();
    for (ASTMethodOrConstructorDeclaration node : operationDeclarations) {
        sigs.add(JavaOperationSignature.buildFor(node));
    }
    // operations
    assertEquals(Visibility.PUBLIC, sigs.get(0).visibility);
    assertEquals(Visibility.PACKAGE, sigs.get(1).visibility);
    assertEquals(Visibility.PROTECTED, sigs.get(2).visibility);
    assertEquals(Visibility.PRIVATE, sigs.get(3).visibility);
    sigs.clear();
    for (ASTFieldDeclaration node : fieldDeclarations) {
        sigs.add(JavaFieldSignature.buildFor(node));
    }
    // fields
    assertEquals(Visibility.PUBLIC, sigs.get(0).visibility);
    assertEquals(Visibility.PACKAGE, sigs.get(1).visibility);
    assertEquals(Visibility.PROTECTED, sigs.get(2).visibility);
    assertEquals(Visibility.PRIVATE, sigs.get(3).visibility);
}
Also used : ASTFieldDeclaration(net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration) ArrayList(java.util.ArrayList) JavaSignature(net.sourceforge.pmd.lang.java.multifile.signature.JavaSignature) ASTMethodOrConstructorDeclaration(net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 ASTFieldDeclaration (net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration)1 ASTMethodOrConstructorDeclaration (net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration)1 JavaSignature (net.sourceforge.pmd.lang.java.multifile.signature.JavaSignature)1 Test (org.junit.Test)1