diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/MethodTypeResolution.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/MethodTypeResolution.java index f8c212d8f3..024f3a04c0 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/MethodTypeResolution.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/MethodTypeResolution.java @@ -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()); diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/ClassTypeResolverTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/ClassTypeResolverTest.java index c76e6eb39d..03db83a5fa 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/ClassTypeResolverTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/ClassTypeResolverTest.java @@ -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(); } diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/MethodGenericParam.java b/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/MethodGenericParam.java new file mode 100644 index 0000000000..2db2f7d534 --- /dev/null +++ b/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/MethodGenericParam.java @@ -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); + } +} diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/dummytypes/GenericSuperType.java b/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/dummytypes/GenericSuperType.java new file mode 100644 index 0000000000..e884b6f870 --- /dev/null +++ b/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/dummytypes/GenericSuperType.java @@ -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 { + +} diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/dummytypes/ParametrizedSubType.java b/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/dummytypes/ParametrizedSubType.java new file mode 100644 index 0000000000..01d6ea971b --- /dev/null +++ b/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/dummytypes/ParametrizedSubType.java @@ -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 { + +} diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/dummytypes/WildcardMethod.java b/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/dummytypes/WildcardMethod.java new file mode 100644 index 0000000000..275d06e632 --- /dev/null +++ b/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/dummytypes/WildcardMethod.java @@ -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) { + + } +}