Search in sources :

Example 1 with ASTVariableDeclaratorId

use of net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId in project pmd by pmd.

the class VariableNameDeclarationTest method testExceptionBlkParam.

@Test
public void testExceptionBlkParam() {
    ASTVariableDeclaratorId id = new ASTVariableDeclaratorId(3);
    id.testingOnlySetBeginLine(10);
    id.setImage("foo");
    ASTFormalParameter param = new ASTFormalParameter(2);
    id.jjtSetParent(param);
    param.jjtSetParent(new ASTTryStatement(1));
    VariableNameDeclaration decl = new VariableNameDeclaration(id);
    assertTrue(decl.isExceptionBlockParameter());
}
Also used : ASTVariableDeclaratorId(net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId) ASTTryStatement(net.sourceforge.pmd.lang.java.ast.ASTTryStatement) ASTFormalParameter(net.sourceforge.pmd.lang.java.ast.ASTFormalParameter) Test(org.junit.Test)

Example 2 with ASTVariableDeclaratorId

use of net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId in project pmd by pmd.

the class VariableNameDeclarationTest method testConstructor.

@Test
public void testConstructor() {
    parseCode(TEST1);
    List<ASTVariableDeclaratorId> nodes = acu.findDescendantsOfType(ASTVariableDeclaratorId.class);
    Scope s = nodes.get(0).getScope();
    NameDeclaration decl = s.getDeclarations().keySet().iterator().next();
    assertEquals("bar", decl.getImage());
    assertEquals(3, decl.getNode().getBeginLine());
}
Also used : Scope(net.sourceforge.pmd.lang.symboltable.Scope) ASTVariableDeclaratorId(net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId) NameDeclaration(net.sourceforge.pmd.lang.symboltable.NameDeclaration) Test(org.junit.Test)

Example 3 with ASTVariableDeclaratorId

use of net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId in project pmd by pmd.

the class ClassScopeTest method testContains.

@Test
public void testContains() {
    ClassNameDeclaration classDeclaration = new ClassNameDeclaration(null);
    ClassScope s = new ClassScope("Foo", classDeclaration);
    ASTVariableDeclaratorId node = new ASTVariableDeclaratorId(1);
    node.setImage("bar");
    s.addDeclaration(new VariableNameDeclaration(node));
    assertTrue(s.getDeclarations().keySet().iterator().hasNext());
}
Also used : ASTVariableDeclaratorId(net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId) Test(org.junit.Test) EnumTest(net.sourceforge.pmd.lang.java.symboltable.testdata.InnerClass.TheInnerClass.EnumTest)

Example 4 with ASTVariableDeclaratorId

use of net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId in project pmd by pmd.

the class ClassScopeTest method testContainsStaticVariablePrefixedWithClassName.

@Test
public void testContainsStaticVariablePrefixedWithClassName() {
    ClassNameDeclaration classDeclaration = new ClassNameDeclaration(null);
    ClassScope s = new ClassScope("Foo", classDeclaration);
    ASTVariableDeclaratorId node = new ASTVariableDeclaratorId(1);
    node.setImage("X");
    s.addDeclaration(new VariableNameDeclaration(node));
    JavaNode node2 = new DummyJavaNode(2);
    node2.setImage("Foo.X");
    assertTrue(s.contains(new JavaNameOccurrence(node2, node2.getImage())));
}
Also used : ASTVariableDeclaratorId(net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId) DummyJavaNode(net.sourceforge.pmd.lang.java.ast.DummyJavaNode) DummyJavaNode(net.sourceforge.pmd.lang.java.ast.DummyJavaNode) JavaNode(net.sourceforge.pmd.lang.java.ast.JavaNode) Test(org.junit.Test) EnumTest(net.sourceforge.pmd.lang.java.symboltable.testdata.InnerClass.TheInnerClass.EnumTest)

Example 5 with ASTVariableDeclaratorId

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

Aggregations

ASTVariableDeclaratorId (net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId)28 Test (org.junit.Test)13 Node (net.sourceforge.pmd.lang.ast.Node)10 NameOccurrence (net.sourceforge.pmd.lang.symboltable.NameOccurrence)9 ASTType (net.sourceforge.pmd.lang.java.ast.ASTType)6 NameDeclaration (net.sourceforge.pmd.lang.symboltable.NameDeclaration)6 ASTClassOrInterfaceType (net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType)5 ASTName (net.sourceforge.pmd.lang.java.ast.ASTName)5 ASTFormalParameter (net.sourceforge.pmd.lang.java.ast.ASTFormalParameter)4 ASTPrimaryExpression (net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression)4 List (java.util.List)3 ASTStatementExpression (net.sourceforge.pmd.lang.java.ast.ASTStatementExpression)3 ASTVariableDeclarator (net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator)3 ArrayList (java.util.ArrayList)2 ASTConstructorDeclaration (net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration)2 ASTExpression (net.sourceforge.pmd.lang.java.ast.ASTExpression)2 ASTFormalParameters (net.sourceforge.pmd.lang.java.ast.ASTFormalParameters)2 ASTLocalVariableDeclaration (net.sourceforge.pmd.lang.java.ast.ASTLocalVariableDeclaration)2 ASTMethodDeclaration (net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration)2 ASTMethodDeclarator (net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator)2