use of net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode in project pmd by pmd.
the class ClassTypeResolverTest method testFieldAccess.
@Test
public void testFieldAccess() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(FieldAccess.class);
List<AbstractJavaTypeNode> expressions = convertList(acu.findChildNodesWithXPath("//StatementExpression/PrimaryExpression"), AbstractJavaTypeNode.class);
int index = 0;
// param.field = 10;
assertEquals(Integer.TYPE, expressions.get(index).getType());
assertEquals(Integer.TYPE, getChildType(expressions.get(index++), 0));
// local.field = 10;
assertEquals(Integer.TYPE, expressions.get(index).getType());
assertEquals(Integer.TYPE, getChildType(expressions.get(index++), 0));
// f.f.f.field = 10;
assertEquals(Integer.TYPE, expressions.get(index).getType());
assertEquals(Integer.TYPE, getChildType(expressions.get(index++), 0));
// (this).f.f.field = 10;
assertEquals(Integer.TYPE, expressions.get(index).getType());
assertEquals(FieldAccess.class, getChildType(expressions.get(index), 0));
assertEquals(FieldAccess.class, getChildType(expressions.get(index), 1));
assertEquals(FieldAccess.class, getChildType(expressions.get(index), 2));
assertEquals(Integer.TYPE, getChildType(expressions.get(index++), 3));
// field = 10;
assertEquals(Integer.TYPE, expressions.get(index).getType());
assertEquals(Integer.TYPE, getChildType(expressions.get(index++), 0));
// Make sure we got them all
assertEquals("All expressions not tested", index, expressions.size());
}
use of net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode in project pmd by pmd.
the class ClassTypeResolverTest method testMethodMostSpecific.
@Test
public void testMethodMostSpecific() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(MethodMostSpecific.class);
List<AbstractJavaTypeNode> expressions = convertList(acu.findChildNodesWithXPath("//VariableInitializer/Expression/PrimaryExpression"), AbstractJavaTypeNode.class);
int index = 0;
// String a = moreSpecific((Number) null, (AbstractCollection) null);
assertEquals(String.class, expressions.get(index).getType());
assertEquals(String.class, getChildType(expressions.get(index), 0));
assertEquals(String.class, getChildType(expressions.get(index++), 1));
// Exception b = moreSpecific((Integer) null, (AbstractList) null);
assertEquals(Exception.class, expressions.get(index).getType());
assertEquals(Exception.class, getChildType(expressions.get(index), 0));
assertEquals(Exception.class, getChildType(expressions.get(index++), 1));
// int c = moreSpecific((Double) null, (RoleList) null);
assertEquals(int.class, expressions.get(index).getType());
assertEquals(int.class, getChildType(expressions.get(index), 0));
assertEquals(int.class, getChildType(expressions.get(index++), 1));
// Make sure we got them all
assertEquals("All expressions not tested", index, expressions.size());
}
Aggregations