Search in sources :

Example 11 with ASTAllocationExpression

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

the class ClassTypeResolverTest method testNestedAnonymousClass.

@Test
public void testNestedAnonymousClass() throws Exception {
    Node acu = parseAndTypeResolveForClass(NestedAnonymousClass.class, "1.8");
    ASTAllocationExpression allocationExpression = acu.getFirstDescendantOfType(ASTAllocationExpression.class);
    ASTAllocationExpression nestedAllocation = // get the declaration (boundary)
    allocationExpression.getFirstDescendantOfType(ASTClassOrInterfaceBodyDeclaration.class).getFirstDescendantOfType(// and dive for the nested allocation
    ASTAllocationExpression.class);
    TypeNode child = (TypeNode) nestedAllocation.jjtGetChild(0);
    Assert.assertTrue(Converter.class.isAssignableFrom(child.getType()));
    Assert.assertSame(String.class, child.getTypeDefinition().getGenericType(0).getType());
}
Also used : TypeNode(net.sourceforge.pmd.lang.java.ast.TypeNode) Node(net.sourceforge.pmd.lang.ast.Node) AbstractJavaNode(net.sourceforge.pmd.lang.java.ast.AbstractJavaNode) AbstractJavaTypeNode(net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode) Converter(net.sourceforge.pmd.typeresolution.testdata.dummytypes.Converter) ASTAllocationExpression(net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression) TypeNode(net.sourceforge.pmd.lang.java.ast.TypeNode) AbstractJavaTypeNode(net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode) ASTClassOrInterfaceBodyDeclaration(net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration) Test(org.junit.Test)

Aggregations

ASTAllocationExpression (net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression)11 Node (net.sourceforge.pmd.lang.ast.Node)9 TypeNode (net.sourceforge.pmd.lang.java.ast.TypeNode)6 ASTLiteral (net.sourceforge.pmd.lang.java.ast.ASTLiteral)4 AbstractJavaTypeNode (net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode)4 Test (org.junit.Test)4 ASTArgumentList (net.sourceforge.pmd.lang.java.ast.ASTArgumentList)3 ASTClassOrInterfaceType (net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType)3 ASTName (net.sourceforge.pmd.lang.java.ast.ASTName)3 AbstractJavaNode (net.sourceforge.pmd.lang.java.ast.AbstractJavaNode)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ASTPrimaryExpression (net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression)2 ASTPrimarySuffix (net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix)2 ASTVariableInitializer (net.sourceforge.pmd.lang.java.ast.ASTVariableInitializer)2 Comparator (java.util.Comparator)1 Map (java.util.Map)1 RuleContext (net.sourceforge.pmd.RuleContext)1 QualifiableNode (net.sourceforge.pmd.lang.ast.QualifiableNode)1 ASTAdditiveExpression (net.sourceforge.pmd.lang.java.ast.ASTAdditiveExpression)1