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));
}
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();
}
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));
}
Aggregations