Search in sources :

Example 1 with SuperClassA2

use of net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassA2 in project pmd by pmd.

the class TypeInferenceTest method testResolution.

@Test
public void testResolution() {
    List<Bound> bounds = new ArrayList<>();
    bounds.add(new Bound(JavaTypeDefinition.forClass(SuperClassA.class), alpha, SUBTYPE));
    bounds.add(new Bound(JavaTypeDefinition.forClass(SuperClassAOther.class), alpha, SUBTYPE));
    Map<Variable, JavaTypeDefinition> result = TypeInferenceResolver.resolveVariables(bounds);
    assertEquals(1, result.size());
    assertEquals(JavaTypeDefinition.forClass(SuperClassA2.class), result.get(alpha));
}
Also used : SuperClassA2(net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassA2) Variable(net.sourceforge.pmd.lang.java.typeresolution.typeinference.Variable) JavaTypeDefinition(net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition) Bound(net.sourceforge.pmd.lang.java.typeresolution.typeinference.Bound) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with SuperClassA2

use of net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassA2 in project pmd by pmd.

the class FieldAccessSuper method foo.

public void foo() {
    // simple super field access
    // Primary[Prefix[Name[s]]]
    s = new SuperClassA();
    // access inherited field through primary
    // Primary[ Prefix[Primary[(this)]], Suffix[s], Suffix[s2] ]
    (this).s.s2 = new SuperClassA2();
    // access inherited field, second 's' has inherited field 's2'
    // Primary[Prefix[Name[s.s.s2]]]
    s.s.s2 = new SuperClassA2();
    // field access through super
    // Primary[Prefix["super"], Suffix["field"]]
    super.s = new SuperClassA();
    // fully qualified case
    // Primary[Prefix[Name[net...FieldAccessSuper]], Suffix[this], Suffix[s]]
    net.sourceforge.pmd.typeresolution.testdata.FieldAccessSuper.this.s = new SuperClassA();
}
Also used : SuperClassA2(net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassA2) SuperClassA(net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassA)

Example 3 with SuperClassA2

use of net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassA2 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)

Aggregations

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