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());
}
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());
}
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());
}
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())));
}
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());
}
Aggregations