use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class ClassTypeResolverTest method testMethodGenericExplicit.
@Test
public void testMethodGenericExplicit() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(MethodGenericExplicit.class);
List<AbstractJavaTypeNode> expressions = convertList(acu.findChildNodesWithXPath("//VariableInitializer/Expression/PrimaryExpression"), AbstractJavaTypeNode.class);
int index = 0;
// String s = this.<String>foo();
assertEquals(String.class, expressions.get(index).getType());
assertEquals(String.class, getChildType(expressions.get(index), 1));
assertEquals(String.class, getChildType(expressions.get(index++), 2));
// 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 testUnaryLogicalOperators.
@Test
public void testUnaryLogicalOperators() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Operators.class);
List<ASTExpression> expressions = convertList(acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryLogicalOperators']]//Expression"), ASTExpression.class);
int index = 0;
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, 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 testBinaryStringPromotion.
@Test
public void testBinaryStringPromotion() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Promotion.class);
List<ASTExpression> expressions = convertList(acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryStringPromotion']]//Expression"), ASTExpression.class);
int index = 0;
assertEquals(String.class, expressions.get(index++).getType());
assertEquals(String.class, expressions.get(index++).getType());
assertEquals(String.class, expressions.get(index++).getType());
assertEquals(String.class, expressions.get(index++).getType());
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 testExtraTopLevelClass.
@Test
public void testExtraTopLevelClass() throws ClassNotFoundException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(ExtraTopLevelClass.class);
Class<?> theExtraTopLevelClass = Class.forName("net.sourceforge.pmd.typeresolution.testdata.TheExtraTopLevelClass");
// First class
ASTTypeDeclaration typeDeclaration = (ASTTypeDeclaration) acu.jjtGetChild(1);
assertEquals(ExtraTopLevelClass.class, typeDeclaration.getType());
assertEquals(ExtraTopLevelClass.class, typeDeclaration.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class).getType());
// Second class
typeDeclaration = (ASTTypeDeclaration) acu.jjtGetChild(2);
assertEquals(theExtraTopLevelClass, typeDeclaration.getType());
assertEquals(theExtraTopLevelClass, typeDeclaration.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class).getType());
}
use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit 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");
}
Aggregations