Search in sources :

Example 6 with NameDeclaration

use of net.sourceforge.pmd.lang.symboltable.NameDeclaration in project pmd by pmd.

the class GlobalScopeTest method testClassDeclAppears.

@Test
public void testClassDeclAppears() {
    parseCode(TEST1);
    ASTCompilationUnit decl = acu;
    Scope scope = decl.getScope();
    Map<NameDeclaration, List<NameOccurrence>> m = scope.getDeclarations();
    ClassNameDeclaration classNameDeclaration = (ClassNameDeclaration) m.keySet().iterator().next();
    assertEquals(classNameDeclaration.getImage(), "Foo");
}
Also used : ASTCompilationUnit(net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit) Scope(net.sourceforge.pmd.lang.symboltable.Scope) List(java.util.List) NameDeclaration(net.sourceforge.pmd.lang.symboltable.NameDeclaration) Test(org.junit.Test)

Example 7 with NameDeclaration

use of net.sourceforge.pmd.lang.symboltable.NameDeclaration in project pmd by pmd.

the class ImageFinderFunctionTest method testSeveralImages.

@Test
public void testSeveralImages() {
    List<String> imgs = new ArrayList<>();
    imgs.add("Foo.foo");
    imgs.add("foo");
    ImageFinderFunction f = new ImageFinderFunction(imgs);
    ASTVariableDeclaratorId node = new ASTVariableDeclaratorId(1);
    node.setImage("foo");
    NameDeclaration decl = new VariableNameDeclaration(node);
    f.applyTo(decl);
    assertEquals(decl, f.getDecl());
}
Also used : ImageFinderFunction(net.sourceforge.pmd.lang.symboltable.ImageFinderFunction) ASTVariableDeclaratorId(net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId) ArrayList(java.util.ArrayList) NameDeclaration(net.sourceforge.pmd.lang.symboltable.NameDeclaration) Test(org.junit.Test)

Example 8 with NameDeclaration

use of net.sourceforge.pmd.lang.symboltable.NameDeclaration in project pmd by pmd.

the class ImageFinderFunctionTest method testSingleImage.

@Test
public void testSingleImage() {
    ImageFinderFunction f = new ImageFinderFunction("foo");
    ASTVariableDeclaratorId node = new ASTVariableDeclaratorId(1);
    node.setImage("foo");
    NameDeclaration decl = new VariableNameDeclaration(node);
    f.applyTo(decl);
    assertEquals(decl, f.getDecl());
}
Also used : ImageFinderFunction(net.sourceforge.pmd.lang.symboltable.ImageFinderFunction) ASTVariableDeclaratorId(net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId) NameDeclaration(net.sourceforge.pmd.lang.symboltable.NameDeclaration) Test(org.junit.Test)

Example 9 with NameDeclaration

use of net.sourceforge.pmd.lang.symboltable.NameDeclaration in project pmd by pmd.

the class LocalScopeTest method testPostfixUsageIsRecorded.

@Test
public void testPostfixUsageIsRecorded() {
    parseCode(TEST3);
    List<ASTVariableDeclaratorId> nodes = acu.findDescendantsOfType(ASTVariableDeclaratorId.class);
    ASTVariableDeclaratorId node = nodes.get(0);
    Map<NameDeclaration, List<NameOccurrence>> vars = node.getScope().getDeclarations();
    NameDeclaration decl = vars.keySet().iterator().next();
    List<NameOccurrence> usages = vars.get(decl);
    JavaNameOccurrence occ = (JavaNameOccurrence) usages.get(0);
    assertEquals(4, occ.getLocation().getBeginLine());
}
Also used : ASTVariableDeclaratorId(net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId) List(java.util.List) NameDeclaration(net.sourceforge.pmd.lang.symboltable.NameDeclaration) NameOccurrence(net.sourceforge.pmd.lang.symboltable.NameOccurrence) Test(org.junit.Test)

Example 10 with NameDeclaration

use of net.sourceforge.pmd.lang.symboltable.NameDeclaration in project pmd by pmd.

the class LocalScopeTest method testQualifiedNameOccurrence.

@Test
public void testQualifiedNameOccurrence() {
    parseCode(TEST2);
    List<ASTVariableDeclaratorId> nodes = acu.findDescendantsOfType(ASTVariableDeclaratorId.class);
    ASTVariableDeclaratorId node = nodes.get(0);
    Map<NameDeclaration, List<NameOccurrence>> vars = node.getScope().getDeclarations();
    NameDeclaration decl = vars.keySet().iterator().next();
    JavaNameOccurrence occ = (JavaNameOccurrence) vars.get(decl).get(0);
    assertEquals("b", occ.getImage());
}
Also used : ASTVariableDeclaratorId(net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId) List(java.util.List) NameDeclaration(net.sourceforge.pmd.lang.symboltable.NameDeclaration) Test(org.junit.Test)

Aggregations

NameDeclaration (net.sourceforge.pmd.lang.symboltable.NameDeclaration)49 List (java.util.List)28 Test (org.junit.Test)28 NameOccurrence (net.sourceforge.pmd.lang.symboltable.NameOccurrence)13 ASTClassOrInterfaceDeclaration (net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration)12 EnumTest (net.sourceforge.pmd.lang.java.symboltable.testdata.InnerClass.TheInnerClass.EnumTest)12 Map (java.util.Map)10 Node (net.sourceforge.pmd.lang.ast.Node)10 Scope (net.sourceforge.pmd.lang.symboltable.Scope)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)6 ASTName (net.sourceforge.pmd.lang.java.ast.ASTName)6 ImageFinderFunction (net.sourceforge.pmd.lang.symboltable.ImageFinderFunction)6 ASTMethodDeclaration (net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration)5 ASTVariableDeclaratorId (net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId)5 ASTArgumentList (net.sourceforge.pmd.lang.java.ast.ASTArgumentList)4 ASTPrimaryExpression (net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression)3 VariableNameDeclaration (net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration)3 ASTName (net.sourceforge.pmd.lang.plsql.ast.ASTName)3 ASTExtendsList (net.sourceforge.pmd.lang.java.ast.ASTExtendsList)2