use of net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition in project pmd by pmd.
the class ClassTypeResolverTest method testJavaTypeDefinitionGetSuperTypeSet.
@Test
public void testJavaTypeDefinitionGetSuperTypeSet() {
JavaTypeDefinition originalTypeDef = forClass(List.class, forClass(Integer.class));
Set<JavaTypeDefinition> set = originalTypeDef.getSuperTypeSet();
assertEquals(set.size(), 4);
assertTrue(set.contains(forClass(Object.class)));
assertTrue(set.contains(originalTypeDef));
assertTrue(set.contains(forClass(Collection.class, forClass(Integer.class))));
assertTrue(set.contains(forClass(Iterable.class, forClass(Integer.class))));
}
use of net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition 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.lang.java.typeresolution.typedefinition.JavaTypeDefinition in project pmd by pmd.
the class ClassTypeResolverTest method testJavaTypeDefinitionEquals.
@Test
public void testJavaTypeDefinitionEquals() {
JavaTypeDefinition a = forClass(Integer.class);
JavaTypeDefinition b = forClass(Integer.class);
// test non-generic types
assertEquals(a, b);
assertNotEquals(a, null);
// test generic arg equality
b = forClass(List.class, a);
a = forClass(List.class, a);
assertEquals(a, b);
a = forClass(List.class, forClass(String.class));
assertNotEquals(a, b);
assertNotEquals(b, a);
// test raw vs proper, proper vs raw
a = forClass(JavaTypeDefinitionEquals.class);
b = forClass(JavaTypeDefinitionEquals.class, forClass(List.class, a));
assertEquals(a, b);
assertEquals(b, a);
}
use of net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition in project pmd by pmd.
the class ClassTypeResolverTest method testMethodInitialBounds.
@Test
public void testMethodInitialBounds() throws NoSuchMethodException {
JavaTypeDefinition context = forClass(GenericMethodsImplicit.class, forClass(Thread.class));
List<Variable> variables = new ArrayList<>();
List<Bound> initialBounds = new ArrayList<>();
Method method = GenericMethodsImplicit.class.getMethod("foo");
MethodTypeResolution.produceInitialBounds(method, context, variables, initialBounds);
assertEquals(initialBounds.size(), 6);
// A
assertTrue(initialBounds.contains(new Bound(variables.get(0), forClass(Object.class), SUBTYPE)));
// B
assertTrue(initialBounds.contains(new Bound(variables.get(1), forClass(Number.class), SUBTYPE)));
assertTrue(initialBounds.contains(new Bound(variables.get(1), forClass(Runnable.class), SUBTYPE)));
// C
assertTrue(initialBounds.contains(new Bound(variables.get(2), variables.get(3), SUBTYPE)));
assertTrue(initialBounds.contains(new Bound(variables.get(2), forClass(Object.class), SUBTYPE)));
// D
assertTrue(initialBounds.contains(new Bound(variables.get(3), forClass(Thread.class), SUBTYPE)));
}
Aggregations