use of net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit in project pmd by pmd.
the class ClassTypeResolverTest method testFieldAccessStatic.
@Test
public void testFieldAccessStatic() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(FieldAccessStatic.class);
List<AbstractJavaTypeNode> expressions = convertList(acu.findChildNodesWithXPath("//StatementExpression/PrimaryExpression"), AbstractJavaTypeNode.class);
int index = 0;
// staticPrimitive = 10;
assertEquals(Integer.TYPE, expressions.get(index).getType());
assertEquals(Integer.TYPE, getChildType(expressions.get(index++), 0));
// staticGeneric.first = new Long(0);
assertEquals(Long.class, expressions.get(index).getType());
assertEquals(Long.class, getChildType(expressions.get(index++), 0));
// StaticMembers.staticPrimitive = 10;
assertEquals(Integer.TYPE, expressions.get(index).getType());
assertEquals(Integer.TYPE, getChildType(expressions.get(index++), 0));
// net.sourceforge.pmd.typeresolution.testdata.dummytypes.StaticMembers.staticPrimitive = 10;
assertEquals(Integer.TYPE, expressions.get(index).getType());
assertEquals(Integer.TYPE, getChildType(expressions.get(index++), 0));
// net.sourceforge.pmd.typeresolution.testdata.dummytypes.StaticMembers
// .staticGeneric.generic.second = new Long(10);
assertEquals(Long.class, expressions.get(index).getType());
assertEquals(Long.class, getChildType(expressions.get(index++), 0));
// staticPrimitive = "";
assertEquals(String.class, expressions.get(index).getType());
assertEquals(String.class, getChildType(expressions.get(index++), 0));
// staticChar = 3.1; // it's a double
assertEquals(Double.TYPE, expressions.get(index).getType());
assertEquals(Double.TYPE, getChildType(expressions.get(index++), 0));
// FieldAccessStatic.Nested.staticPrimitive = "";
assertEquals(String.class, expressions.get(index).getType());
assertEquals(String.class, 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.ASTCompilationUnit in project pmd by pmd.
the class ClassTypeResolverTest method testMethodTypeInference.
@Test
public void testMethodTypeInference() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(GenericMethodsImplicit.class);
List<AbstractJavaTypeNode> expressions = convertList(acu.findChildNodesWithXPath("//VariableInitializer/Expression/PrimaryExpression"), AbstractJavaTypeNode.class);
int index = 0;
// SuperClassA2 a = bar((SuperClassA) null, (SuperClassAOther) null, null, (SuperClassAOther2) null);
assertEquals(SuperClassA2.class, expressions.get(index).getType());
assertEquals(SuperClassA2.class, getChildType(expressions.get(index), 0));
assertEquals(SuperClassA2.class, getChildType(expressions.get(index++), 1));
// 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 testMethodStaticAccess.
@Test
public void testMethodStaticAccess() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(MethodStaticAccess.class);
List<AbstractJavaTypeNode> expressions = convertList(acu.findChildNodesWithXPath("//VariableInitializer/Expression/PrimaryExpression"), AbstractJavaTypeNode.class);
int index = 0;
// int a = primitiveStaticMethod();
assertEquals(int.class, expressions.get(index).getType());
assertEquals(int.class, getChildType(expressions.get(index), 0));
assertEquals(int.class, getChildType(expressions.get(index++), 1));
// StaticMembers b = staticInstanceMethod();
assertEquals(StaticMembers.class, expressions.get(index).getType());
assertEquals(StaticMembers.class, getChildType(expressions.get(index), 0));
assertEquals(StaticMembers.class, getChildType(expressions.get(index++), 1));
// int c = StaticMembers.primitiveStaticMethod();
assertEquals(int.class, expressions.get(index).getType());
assertEquals(int.class, getChildType(expressions.get(index), 0));
assertEquals(int.class, getChildType(expressions.get(index++), 1));
// String c = MethodStaticAccess.Nested.primitiveStaticMethod();
assertEquals(String.class, expressions.get(index).getType());
assertEquals(String.class, getChildType(expressions.get(index), 0));
assertEquals(String.class, getChildType(expressions.get(index++), 1));
// 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 testPrimarySimpleGenericFieldAccess.
@Test
public void testPrimarySimpleGenericFieldAccess() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(FieldAccessPrimaryGenericSimple.class);
List<AbstractJavaTypeNode> expressions = convertList(acu.findChildNodesWithXPath("//StatementExpression/PrimaryExpression"), AbstractJavaTypeNode.class);
int index = 0;
// this.genericField.first = "";
assertEquals(String.class, expressions.get(index).getType());
assertChildTypeArgsEqualTo(expressions.get(index), 1, String.class, Double.class);
assertEquals(String.class, getChildType(expressions.get(index++), 2));
// (this).genericField.second = new Double(0);
assertEquals(Double.class, expressions.get(index).getType());
assertChildTypeArgsEqualTo(expressions.get(index), 1, String.class, Double.class);
assertEquals(Double.class, getChildType(expressions.get(index++), 2));
// this.genericTypeArg.second.second = new Double(0);
assertEquals(Double.class, expressions.get(index).getType());
assertChildTypeArgsEqualTo(expressions.get(index), 2, Number.class, Double.class);
assertEquals(Double.class, getChildType(expressions.get(index++), 3));
// (this).genericField.generic.generic.generic.first = new Double(0);
assertEquals(Double.class, expressions.get(index).getType());
assertEquals(Double.class, getChildType(expressions.get(index++), 5));
// (this).fieldA = new Long(0);
assertEquals(Long.class, expressions.get(index).getType());
assertEquals(Long.class, getChildType(expressions.get(index++), 1));
// this.fieldB.generic.second = "";
assertEquals(String.class, expressions.get(index).getType());
assertEquals(String.class, getChildType(expressions.get(index++), 3));
// super.fieldA = new Long(0);
assertEquals(Long.class, expressions.get(index).getType());
assertChildTypeArgsEqualTo(expressions.get(index), 0, Long.class);
assertEquals(Long.class, getChildType(expressions.get(index++), 1));
// super.fieldB.generic.second = "";
assertEquals(String.class, expressions.get(index).getType());
assertEquals(String.class, getChildType(expressions.get(index++), 3));
// this.field.first = "";
assertEquals(String.class, expressions.get(index).getType());
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 testMethodSecondPhase.
@Test
public void testMethodSecondPhase() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(MethodSecondPhase.class);
List<AbstractJavaTypeNode> expressions = convertList(acu.findChildNodesWithXPath("//VariableInitializer/Expression/PrimaryExpression"), AbstractJavaTypeNode.class);
int index = 0;
// String a = boxing(10, "");
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 = boxing('a', "");
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 = boxing(10L, "");
assertEquals(int.class, expressions.get(index).getType());
assertEquals(int.class, getChildType(expressions.get(index), 0));
assertEquals(int.class, getChildType(expressions.get(index++), 1));
// String d = unboxing("", (Integer) 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 e = unboxing("", (Character) 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 f = unboxing("", (Byte) 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