Search in sources :

Example 1 with SuperClassAOther2

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));
}
Also used : MethodType(net.sourceforge.pmd.lang.java.typeresolution.MethodType) SuperClassA2(net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassA2) ASTCompilationUnit(net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit) JavaTypeDefinition(net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition) AbstractJavaNode(net.sourceforge.pmd.lang.java.ast.AbstractJavaNode) SuperClassAOther2(net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassAOther2) Method(java.lang.reflect.Method) ASTArgumentList(net.sourceforge.pmd.lang.java.ast.ASTArgumentList) Test(org.junit.Test)

Example 2 with SuperClassAOther2

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)));
}
Also used : Variable(net.sourceforge.pmd.lang.java.typeresolution.typeinference.Variable) ASTCompilationUnit(net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit) Constraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint) AbstractJavaNode(net.sourceforge.pmd.lang.java.ast.AbstractJavaNode) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Constraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint) ASTArgumentList(net.sourceforge.pmd.lang.java.ast.ASTArgumentList) SuperClassAOther(net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassAOther) SuperClassAOther2(net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassAOther2) SuperClassA(net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassA) Test(org.junit.Test)

Aggregations

Method (java.lang.reflect.Method)2 ASTArgumentList (net.sourceforge.pmd.lang.java.ast.ASTArgumentList)2 ASTCompilationUnit (net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit)2 AbstractJavaNode (net.sourceforge.pmd.lang.java.ast.AbstractJavaNode)2 SuperClassAOther2 (net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassAOther2)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 MethodType (net.sourceforge.pmd.lang.java.typeresolution.MethodType)1 JavaTypeDefinition (net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition)1 Constraint (net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint)1 Variable (net.sourceforge.pmd.lang.java.typeresolution.typeinference.Variable)1 SuperClassA (net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassA)1 SuperClassA2 (net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassA2)1 SuperClassAOther (net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassAOther)1