use of net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassAOther2 in project pmd by pmd.
the class ClassTypeResolverTest method testMethodParameterization.
@Test
public void testMethodParameterization() throws JaxenException, NoSuchMethodException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(GenericMethodsImplicit.class);
List<AbstractJavaNode> expressions = convertList(acu.findChildNodesWithXPath("//ArgumentList"), AbstractJavaNode.class);
JavaTypeDefinition context = forClass(GenericMethodsImplicit.class, forClass(Thread.class));
Method method = GenericMethodsImplicit.class.getMethod("bar", Object.class, Object.class, Integer.class, Object.class);
ASTArgumentList argList = (ASTArgumentList) expressions.get(0);
MethodType inferedMethod = MethodTypeResolution.parameterizeInvocation(context, method, argList);
assertEquals(inferedMethod.getParameterTypes().get(0), forClass(SuperClassA2.class));
assertEquals(inferedMethod.getParameterTypes().get(1), forClass(SuperClassA2.class));
assertEquals(inferedMethod.getParameterTypes().get(2), forClass(Integer.class));
assertEquals(inferedMethod.getParameterTypes().get(3), forClass(SuperClassAOther2.class));
}
use of net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassAOther2 in project pmd by pmd.
the class ClassTypeResolverTest method testMethodInitialConstraints.
@Test
public void testMethodInitialConstraints() throws NoSuchMethodException, JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(GenericMethodsImplicit.class);
List<AbstractJavaNode> expressions = convertList(acu.findChildNodesWithXPath("//ArgumentList"), AbstractJavaNode.class);
List<Variable> variables = new ArrayList<>();
for (int i = 0; i < 2; ++i) {
variables.add(new Variable());
}
Method method = GenericMethodsImplicit.class.getMethod("bar", Object.class, Object.class, Integer.class, Object.class);
ASTArgumentList argList = (ASTArgumentList) expressions.get(0);
List<Constraint> constraints = MethodTypeResolution.produceInitialConstraints(method, argList, variables);
assertEquals(constraints.size(), 3);
// A
assertTrue(constraints.contains(new Constraint(forClass(SuperClassA.class), variables.get(0), LOOSE_INVOCATION)));
assertTrue(constraints.contains(new Constraint(forClass(SuperClassAOther.class), variables.get(0), LOOSE_INVOCATION)));
// B
assertTrue(constraints.contains(new Constraint(forClass(SuperClassAOther2.class), variables.get(1), LOOSE_INVOCATION)));
}
Aggregations