[java] TypeResolution - support basic method overriding
This commit is contained in:
@ -447,8 +447,10 @@ public final class MethodTypeResolution {
|
||||
}
|
||||
}
|
||||
|
||||
// search it's supertype
|
||||
if (!contextClass.equals(Object.class)) {
|
||||
// search it's supertype - but only, if there has been no method in the contextClass found.
|
||||
// if there is already a method, it will override the methods defined in the supertypes.
|
||||
// TODO: we'll need to check, whether the method is abstract...
|
||||
if (!contextClass.equals(Object.class) && result.isEmpty()) {
|
||||
result.addAll(getApplicableMethods(context.resolveTypeDefinition(contextClass.getGenericSuperclass()),
|
||||
methodName, typeArguments, argArity, accessingClass));
|
||||
}
|
||||
|
@ -97,6 +97,7 @@ import net.sourceforge.pmd.typeresolution.testdata.MethodThirdPhase;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.NestedAnonymousClass;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.Operators;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.Promotion;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.SubTypeUsage;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.SuperExpression;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.ThisExpression;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.dummytypes.Converter;
|
||||
@ -1653,6 +1654,11 @@ public class ClassTypeResolverTest {
|
||||
parseAndTypeResolveForString("public class Foo { public static <T extends @NonNull Enum<?>> T getEnum() { return null; } }", "1.8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodOverrides() throws Exception {
|
||||
parseAndTypeResolveForClass(SubTypeUsage.class, "1.8");
|
||||
}
|
||||
|
||||
private JavaTypeDefinition getChildTypeDef(Node node, int childIndex) {
|
||||
return ((TypeNode) node.jjtGetChild(childIndex)).getTypeDefinition();
|
||||
}
|
||||
|
15
pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/SubTypeUsage.java
vendored
Normal file
15
pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/SubTypeUsage.java
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 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.SubType;
|
||||
|
||||
public class SubTypeUsage {
|
||||
|
||||
public void foo() {
|
||||
SubType var = new SubType();
|
||||
var.myMethod();
|
||||
}
|
||||
}
|
13
pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/dummytypes/SubType.java
vendored
Normal file
13
pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/dummytypes/SubType.java
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.typeresolution.testdata.dummytypes;
|
||||
|
||||
public class SubType extends SuperType {
|
||||
|
||||
@Override
|
||||
public void myMethod() {
|
||||
super.myMethod();
|
||||
}
|
||||
}
|
12
pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/dummytypes/SuperType.java
vendored
Normal file
12
pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/dummytypes/SuperType.java
vendored
Normal 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 SuperType {
|
||||
|
||||
public void myMethod() {
|
||||
// this will be overridden by a SubType
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user