Fix the fix

This commit is contained in:
Clément Fournier committed 2022-01-02 16:05:15 +01:00
1 parent c56effbd36
commit 679cae5c82
3 files changed
+8 -12

No files matched your search

@@ -19,9 +19,9 @@ import net.sourceforge.pmd.lang.java.ast.JModifier;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.ast.internal.PrettyPrintingUtil;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.lang.java.symbols.JClassSymbol;
import net.sourceforge.pmd.lang.java.symbols.JMethodSymbol;
import net.sourceforge.pmd.lang.java.symbols.table.internal.SuperTypesEnumerator;
import net.sourceforge.pmd.lang.java.types.JClassType;
import net.sourceforge.pmd.lang.java.types.JMethodSig;
import net.sourceforge.pmd.lang.java.types.TypeOps;
@@ -49,7 +49,7 @@ public class MissingOverrideRule extends AbstractJavaRulechainRule {
// - may override another method (non private, non static)
// - not already annotated @Override
RelevantMethodSet relevantMethods = new RelevantMethodSet(node.getSymbol());
RelevantMethodSet relevantMethods = new RelevantMethodSet(node.getTypeMirror());
for (ASTMethodDeclaration methodDecl : node.getDeclarations(ASTMethodDeclaration.class)) {
relevantMethods.addIfRelevant(methodDecl);
@@ -88,9 +88,9 @@ public class MissingOverrideRule extends AbstractJavaRulechainRule {
// nodes that may be violations
private final Set<ASTMethodDeclaration> tracked = new LinkedHashSet<>();
private final JClassSymbol site;
private final JClassType site;
private RelevantMethodSet(JClassSymbol site) {
private RelevantMethodSet(JClassType site) {
this.site = site;
}
@@ -111,7 +111,7 @@ public class MissingOverrideRule extends AbstractJavaRulechainRule {
// we use this to only consider methods that may produce a violation,
// among the supertype methods
boolean isRelevant(JMethodSymbol superMethod) {
if (!TypeOps.isOverridableIn(superMethod, site)) {
if (!TypeOps.isOverridableIn(superMethod, site.getSymbol())) {
return false;
}
BitSet aritySet = map.get(superMethod.getSimpleName());
@@ -125,7 +125,7 @@ public class MissingOverrideRule extends AbstractJavaRulechainRule {
JMethodSig superSig) {
ASTMethodDeclaration subSig = null;
for (ASTMethodDeclaration it : tracked) {
if (TypeOps.areOverrideEquivalent(it.getGenericSignature(), superSig)) {
if (TypeOps.overrides(it.getGenericSignature(), superSig, site)) {
subSig = it;
// we assume there is a single relevant method that may match,
// otherwise it would be a compile-time error
@@ -1249,11 +1249,7 @@ public final class TypeOps {
JTypeMirror fi1 = formals1.get(i);
JTypeMirror fi2 = formals2.get(i);
// Mixing type vars with concrete types while overriding
// leads to non equivalent parameters.
boolean mixedTypeVars = fi1 instanceof JTypeVar ^ fi2 instanceof JTypeVar;
if (!isSameType(fi1.getErasure(), fi2.getErasure()) || mixedTypeVars) {
if (!isSameType(fi1.getErasure(), fi2.getErasure())) {
return false;
}
}
@@ -623,7 +623,7 @@ public enum EnumToString {
<expected-problems>1</expected-problems>
<expected-linenumbers>23</expected-linenumbers>
<code><![CDATA[
package net.sourceforge.pmd.lang.java.rule.bestpractices.missingoverride;
package test;
import java.util.Collection;