forked from phoedos/pmd
[java] typeresolution: add test for generic wildcard method parameters
This commit is contained in:
@ -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());
|
||||
|
@ -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();
|
||||
}
|
||||
|
18
pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/MethodGenericParam.java
vendored
Normal file
18
pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/MethodGenericParam.java
vendored
Normal 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);
|
||||
}
|
||||
}
|
@ -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> {
|
||||
|
||||
}
|
@ -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> {
|
||||
|
||||
}
|
@ -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) {
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user