[java] typeresolution: add test for generic wildcard method parameters

This commit is contained in:
Andreas Dangel
2017-10-05 22:28:00 +02:00
parent efb78e9f79
commit 716e21221c
6 changed files with 58 additions and 1 deletions

View File

@ -638,7 +638,10 @@ public final class MethodTypeResolution {
// right now we only check if generic arguments are the same
// TODO: add support for wildcard types
// (future note: can't call subtype as it is recursively, infinite types)
return parameter.equals(argSuper);
//return parameter.equals(argSuper);
// TODO: this ignores the check for generic types!!
return parameter.getType().equals(argSuper.getType());
}
int indexOfParameter = PRIMITIVE_SUBTYPE_ORDER.indexOf(parameter.getType());

View File

@ -89,6 +89,7 @@ import net.sourceforge.pmd.typeresolution.testdata.Literals;
import net.sourceforge.pmd.typeresolution.testdata.MethodAccessibility;
import net.sourceforge.pmd.typeresolution.testdata.MethodFirstPhase;
import net.sourceforge.pmd.typeresolution.testdata.MethodGenericExplicit;
import net.sourceforge.pmd.typeresolution.testdata.MethodGenericParam;
import net.sourceforge.pmd.typeresolution.testdata.MethodMostSpecific;
import net.sourceforge.pmd.typeresolution.testdata.MethodPotentialApplicability;
import net.sourceforge.pmd.typeresolution.testdata.MethodSecondPhase;
@ -1659,6 +1660,11 @@ public class ClassTypeResolverTest {
parseAndTypeResolveForClass(SubTypeUsage.class, "1.8");
}
@Test
public void testMethodWildcardParam() throws Exception {
parseAndTypeResolveForClass(MethodGenericParam.class, "1.8");
}
private JavaTypeDefinition getChildTypeDef(Node node, int childIndex) {
return ((TypeNode) node.jjtGetChild(childIndex)).getTypeDefinition();
}

View File

@ -0,0 +1,18 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.typeresolution.testdata;
import net.sourceforge.pmd.typeresolution.testdata.dummytypes.ParametrizedSubType;
import net.sourceforge.pmd.typeresolution.testdata.dummytypes.WildcardMethod;
public class MethodGenericParam {
public void foo() {
ParametrizedSubType type = new ParametrizedSubType();
WildcardMethod m = new WildcardMethod();
m.useWildcard(type);
}
}

View File

@ -0,0 +1,9 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.typeresolution.testdata.dummytypes;
public class GenericSuperType<T> {
}

View File

@ -0,0 +1,9 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.typeresolution.testdata.dummytypes;
public class ParametrizedSubType extends GenericSuperType<String> {
}

View File

@ -0,0 +1,12 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.typeresolution.testdata.dummytypes;
public class WildcardMethod {
public void useWildcard(GenericSuperType<?> param) {
}
}