use of net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode in project pmd by pmd.
the class ClassTypeResolverTest method testMethodFirstPhase.
@Test
public void testMethodFirstPhase() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass(MethodFirstPhase.class, "1.8");
List<AbstractJavaTypeNode> expressions = convertList(acu.findChildNodesWithXPath("//VariableInitializer/Expression/PrimaryExpression"), AbstractJavaTypeNode.class);
int index = 0;
// int a = subtype(10, 'a', "");
assertEquals(int.class, expressions.get(index).getType());
assertEquals(int.class, getChildType(expressions.get(index), 0));
assertEquals(int.class, getChildType(expressions.get(index++), 1));
// Exception b = vararg((Object) null);
assertEquals(Exception.class, expressions.get(index).getType());
assertEquals(Exception.class, getChildType(expressions.get(index), 0));
assertEquals(Exception.class, getChildType(expressions.get(index++), 1));
// Set<String> set = new HashSet<>();
assertEquals(HashSet.class, expressions.get(index++).getType());
// List<String> myList = new ArrayList<>();
assertEquals(ArrayList.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.AbstractJavaTypeNode in project pmd by pmd.
the class ClassTypeResolverTest method testFieldAccessGenericNested.
@Test
public void testFieldAccessGenericNested() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(FieldAccessGenericNested.class);
List<AbstractJavaTypeNode> expressions = convertList(acu.findChildNodesWithXPath("//StatementExpression/PrimaryExpression"), AbstractJavaTypeNode.class);
int index = 0;
// n.field = null;
assertEquals(String.class, expressions.get(index).getType());
assertEquals(String.class, getChildType(expressions.get(index++), 0));
// n.generic.first = null;
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.AbstractJavaTypeNode in project pmd by pmd.
the class ClassTypeResolverTest method testArrayTypes.
@Test
public void testArrayTypes() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(ArrayTypes.class);
List<AbstractJavaTypeNode> expressions = convertList(acu.findChildNodesWithXPath("//VariableDeclarator"), AbstractJavaTypeNode.class);
int index = 0;
// int[] a = new int[1];
testSubtreeNodeTypes(expressions.get(index++), int[].class);
// Object[][] b = new Object[1][0];
testSubtreeNodeTypes(expressions.get(index++), Object[][].class);
// ArrayTypes[][][] c = new ArrayTypes[][][] { new ArrayTypes[1][2] };
testSubtreeNodeTypes(expressions.get(index++), ArrayTypes[][][].class);
// 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 testMethodAccessibility.
@Test
public void testMethodAccessibility() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(MethodAccessibility.class);
List<AbstractJavaTypeNode> expressions = convertList(acu.findChildNodesWithXPath("//VariableInitializer/Expression/PrimaryExpression"), AbstractJavaTypeNode.class);
int index = 0;
// SuperClassA a = inheritedA();
assertEquals(SuperClassA.class, expressions.get(index).getType());
assertEquals(SuperClassA.class, getChildType(expressions.get(index), 0));
assertEquals(SuperClassA.class, getChildType(expressions.get(index++), 1));
// SuperClassB b = inheritedB();
assertEquals(SuperClassB.class, expressions.get(index).getType());
assertEquals(SuperClassB.class, getChildType(expressions.get(index), 0));
assertEquals(SuperClassB.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.AbstractJavaTypeNode in project pmd by pmd.
the class ClassTypeResolverTest method testMethodPotentialApplicability.
@Test
public void testMethodPotentialApplicability() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(MethodPotentialApplicability.class);
List<AbstractJavaTypeNode> expressions = convertList(acu.findChildNodesWithXPath("//VariableInitializer/Expression/PrimaryExpression"), AbstractJavaTypeNode.class);
int index = 0;
// int a = vararg("");
assertEquals(int.class, expressions.get(index).getType());
assertEquals(int.class, getChildType(expressions.get(index), 0));
assertEquals(int.class, getChildType(expressions.get(index++), 1));
// int b = vararg("", 10);
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 = notVararg(0, 0);
assertEquals(String.class, expressions.get(index).getType());
assertEquals(String.class, getChildType(expressions.get(index), 0));
assertEquals(String.class, getChildType(expressions.get(index++), 1));
// Number d = noArguments();
assertEquals(Number.class, expressions.get(index).getType());
assertEquals(Number.class, getChildType(expressions.get(index), 0));
assertEquals(Number.class, getChildType(expressions.get(index++), 1));
// Number e = field.noArguments();
assertEquals(Number.class, expressions.get(index).getType());
assertEquals(Number.class, getChildType(expressions.get(index), 0));
assertEquals(Number.class, getChildType(expressions.get(index++), 1));
// int f = this.vararg("");
assertEquals(int.class, expressions.get(index).getType());
assertEquals(int.class, getChildType(expressions.get(index), 1));
assertEquals(int.class, getChildType(expressions.get(index++), 2));
// Make sure we got them all
assertEquals("All expressions not tested", index, expressions.size());
}
Aggregations