use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project controller by opendaylight.
the class ConcreteModuleGeneratedObjectFactoryTest method test.
@Test
public void test() throws Exception {
FullyQualifiedName fqn = new FullyQualifiedName("foo.bar", "Baz");
FullyQualifiedName abstractFQN = new FullyQualifiedName("foo.bar", "AbstractBaz");
String nullableDescription = null;
ModuleMXBeanEntry moduleMXBeanEntry = mockModuleMXBeanEntry(fqn, abstractFQN, nullableDescription);
Optional<String> copyright = Optional.absent();
Optional<String> header = Optional.absent();
GeneratedObject go = new ConcreteModuleGeneratedObjectFactory().toGeneratedObject(moduleMXBeanEntry, copyright, header);
Entry<FullyQualifiedName, File> entry = go.persist(generatorOutputPath).get();
File dstFile = entry.getValue();
Node c = parse(dstFile);
assertEquals(fqn.getPackageName(), ((ASTCompilationUnit) c).getPackageDeclaration().getPackageNameImage());
assertEquals(fqn.getTypeName(), c.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class).getImage());
assertHasMethodNamed(c, "customValidation");
assertHasMethodNamed(c, "createInstance");
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class SourceFileScopeTest method testPackageIsEmptyString.
@Test
public void testPackageIsEmptyString() {
parseCode(TEST1);
ASTCompilationUnit decl = acu;
assertEquals(decl.getScope().getEnclosingScope(SourceFileScope.class).getPackageName(), "");
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class ClassTypeResolverTest method testInnerClass.
@Test
public void testInnerClass() throws ClassNotFoundException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(InnerClass.class);
Class<?> theInnerClass = Class.forName("net.sourceforge.pmd.typeresolution.testdata.InnerClass$TheInnerClass");
// Outer class
ASTTypeDeclaration typeDeclaration = acu.getFirstDescendantOfType(ASTTypeDeclaration.class);
assertEquals(InnerClass.class, typeDeclaration.getType());
ASTClassOrInterfaceDeclaration outerClassDeclaration = typeDeclaration.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class);
assertEquals(InnerClass.class, outerClassDeclaration.getType());
// Inner class
assertEquals(theInnerClass, outerClassDeclaration.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class).getType());
// Method parameter as inner class
ASTFormalParameter formalParameter = typeDeclaration.getFirstDescendantOfType(ASTFormalParameter.class);
assertEquals(theInnerClass, formalParameter.getType());
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class ClassTypeResolverTest method testMethodTypeInferenceVarargsZeroArity.
@Test
public void testMethodTypeInferenceVarargsZeroArity() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(VarargsZeroArity.class);
List<AbstractJavaTypeNode> expressions = convertList(acu.findChildNodesWithXPath("//VariableInitializer/Expression/PrimaryExpression"), AbstractJavaTypeNode.class);
int index = 0;
// int var = aMethod();
assertEquals(int.class, expressions.get(index++).getType());
// String var2 = aMethod("");
assertEquals(String.class, expressions.get(index++).getType());
// Make sure we got them all
assertEquals("All expressions not tested", index, expressions.size());
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class ClassTypeResolverTest method testAssignmentOperators.
@Test
public void testAssignmentOperators() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Operators.class);
List<ASTStatementExpression> expressions = convertList(acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = " + "'assignmentOperators']]//StatementExpression"), ASTStatementExpression.class);
int index = 0;
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
// Make sure we got them all.
assertEquals("All expressions not tested", index, expressions.size());
}
Aggregations