Search in sources :

Example 31 with ASTPrimaryExpression

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

the class ClassTypeResolverTest method testThisExpression.

@Test
public void testThisExpression() throws JaxenException {
    ASTCompilationUnit acu = parseAndTypeResolveForClass15(ThisExpression.class);
    List<ASTPrimaryExpression> expressions = convertList(acu.findChildNodesWithXPath("//PrimaryExpression"), ASTPrimaryExpression.class);
    List<ASTPrimaryPrefix> prefixes = convertList(acu.findChildNodesWithXPath("//PrimaryPrefix"), ASTPrimaryPrefix.class);
    int index = 0;
    assertEquals(ThisExpression.class, expressions.get(index).getType());
    assertEquals(ThisExpression.class, prefixes.get(index++).getType());
    assertEquals(ThisExpression.class, expressions.get(index).getType());
    assertEquals(ThisExpression.class, prefixes.get(index++).getType());
    assertEquals(ThisExpression.class, expressions.get(index).getType());
    assertEquals(ThisExpression.class, prefixes.get(index++).getType());
    assertEquals(ThisExpression.class, expressions.get(index).getType());
    assertEquals(ThisExpression.class, prefixes.get(index++).getType());
    assertEquals(ThisExpression.ThisExprNested.class, expressions.get(index).getType());
    assertEquals(ThisExpression.ThisExprNested.class, prefixes.get(index++).getType());
    // Qualified this
    assertEquals(ThisExpression.class, expressions.get(index).getType());
    assertEquals(ThisExpression.class, prefixes.get(index).getType());
    assertEquals(ThisExpression.class, ((TypeNode) expressions.get(index++).jjtGetChild(1)).getType());
    assertEquals(ThisExpression.ThisExprStaticNested.class, expressions.get(index).getType());
    assertEquals(ThisExpression.ThisExprStaticNested.class, prefixes.get(index++).getType());
    // Make sure we got them all
    assertEquals("All expressions not tested", index, expressions.size());
    assertEquals("All expressions not tested", index, prefixes.size());
}
Also used : ASTPrimaryPrefix(net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix) ThisExpression(net.sourceforge.pmd.typeresolution.testdata.ThisExpression) ASTCompilationUnit(net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit) ASTPrimaryExpression(net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression) Constraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint) Test(org.junit.Test)

Aggregations

ASTPrimaryExpression (net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression)31 Node (net.sourceforge.pmd.lang.ast.Node)23 ASTPrimaryPrefix (net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix)16 ASTName (net.sourceforge.pmd.lang.java.ast.ASTName)11 ASTPrimarySuffix (net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix)10 ASTExpression (net.sourceforge.pmd.lang.java.ast.ASTExpression)8 ASTStatementExpression (net.sourceforge.pmd.lang.java.ast.ASTStatementExpression)8 NameOccurrence (net.sourceforge.pmd.lang.symboltable.NameOccurrence)7 ASTArgumentList (net.sourceforge.pmd.lang.java.ast.ASTArgumentList)6 ASTAssignmentOperator (net.sourceforge.pmd.lang.java.ast.ASTAssignmentOperator)5 VariableNameDeclaration (net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration)5 ASTLiteral (net.sourceforge.pmd.lang.java.ast.ASTLiteral)4 ASTReturnStatement (net.sourceforge.pmd.lang.java.ast.ASTReturnStatement)4 ASTType (net.sourceforge.pmd.lang.java.ast.ASTType)4 ASTVariableDeclaratorId (net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId)4 ASTAllocationExpression (net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression)3 ASTBlockStatement (net.sourceforge.pmd.lang.java.ast.ASTBlockStatement)3 ASTEqualityExpression (net.sourceforge.pmd.lang.java.ast.ASTEqualityExpression)3 ASTIfStatement (net.sourceforge.pmd.lang.java.ast.ASTIfStatement)3 ASTLocalVariableDeclaration (net.sourceforge.pmd.lang.java.ast.ASTLocalVariableDeclaration)3