use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class GeneralFiddlingTest method innerClassShouldWork.
/**
* Unit test for https://sourceforge.net/p/pmd/bugs/1325/
*/
@Test
public void innerClassShouldWork() {
ASTCompilationUnit acu = buildDFA("class Foo {" + " void bar() {" + " class X {}" + " int i;" + " }" + "}");
assertNotNull(acu);
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class GeneralFiddlingTest method test1.
@Test
public void test1() {
ASTCompilationUnit acu = buildDFA(TEST1);
ASTMethodDeclarator meth = acu.findDescendantsOfType(ASTMethodDeclarator.class).get(0);
DataFlowNode n = meth.getDataFlowNode();
List<DataFlowNode> f = n.getFlow();
assertEquals(6, f.size());
assertEquals("Undefinition(x)", String.valueOf(f.get(0).getVariableAccess().get(0)));
assertEquals(0, f.get(1).getVariableAccess().size());
assertEquals("Definition(x)", String.valueOf(f.get(2).getVariableAccess().get(0)));
assertEquals("Reference(x)", String.valueOf(f.get(3).getVariableAccess().get(0)));
assertEquals("Definition(x)", String.valueOf(f.get(4).getVariableAccess().get(0)));
assertEquals("Undefinition(x)", String.valueOf(f.get(5).getVariableAccess().get(0)));
// for (DataFlowNode dfan : f) {
// System.out.println("Flow starting on line " + dfan.getLine());
// List<VariableAccess> va = dfan.getVariableAccess();
// for (VariableAccess o : va) {
// System.out.println(" variable: " + o);
// }
// }
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class JavaRuleViolationTest method testPackageAndEnumName.
@Test
public void testPackageAndEnumName() {
ASTCompilationUnit ast = parse("package pkg; import java.util.List; public enum FooE { }");
ASTImportDeclaration importNode = ast.getFirstDescendantOfType(ASTImportDeclaration.class);
JavaRuleViolation violation = new JavaRuleViolation(null, new RuleContext(), importNode, null);
assertEquals("pkg", violation.getPackageName());
assertEquals("FooE", violation.getClassName());
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class JavaRuleViolationTest method testPackageAndMultipleClassesName.
@Test
public void testPackageAndMultipleClassesName() {
ASTCompilationUnit ast = parse("package pkg; import java.util.List; class Foo { } public class Bar { }");
ASTImportDeclaration importNode = ast.getFirstDescendantOfType(ASTImportDeclaration.class);
JavaRuleViolation violation = new JavaRuleViolation(null, new RuleContext(), importNode, null);
assertEquals("pkg", violation.getPackageName());
assertEquals("Bar", violation.getClassName());
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class JavaRuleViolationTest method testDefaultPackageAndClassName.
@Test
public void testDefaultPackageAndClassName() {
ASTCompilationUnit ast = parse("import java.util.List; public class Foo { }");
ASTImportDeclaration importNode = ast.getFirstDescendantOfType(ASTImportDeclaration.class);
JavaRuleViolation violation = new JavaRuleViolation(null, new RuleContext(), importNode, null);
assertEquals("", violation.getPackageName());
assertEquals("Foo", violation.getClassName());
}
Aggregations