IDEA-177145 - ignored the cases when ctor doesn't call a corresponding super ctor

GitOrigin-RevId: 0466cc0cb990b643474771fbf010eebcfb21fbd4
This commit is contained in:
Ilyas Selimov
2020-07-07 06:01:30 +00:00
committed by intellij-monorepo-bot
parent 95f61a978b
commit 91c13f98ec
3 changed files with 42 additions and 7 deletions
@@ -88,16 +88,11 @@ public class JavaPsiConstructorUtil {
return null;
}
return findConstructorInSuperWithParameterTypes(constructor, PsiType.EMPTY_ARRAY);
}
@Nullable
public static PsiMethod findConstructorInSuperWithParameterTypes(@NotNull PsiMethod constructor, PsiType @NotNull [] parameterTypes) {
PsiClass containingClass = constructor.getContainingClass();
if (containingClass != null) {
PsiClass superClass = containingClass.getSuperClass();
if (superClass != null && superClass.getName() != null) {
MethodSignature defConstructor = MethodSignatureUtil.createMethodSignature(superClass.getName(), parameterTypes,
MethodSignature defConstructor = MethodSignatureUtil.createMethodSignature(superClass.getName(), PsiType.EMPTY_ARRAY,
PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY, true);
return MethodSignatureUtil.findMethodBySignature(superClass, defConstructor, false);
}
@@ -94,7 +94,14 @@ public class ParameterNameDiffersFromOverriddenParameterInspection
@Nullable
private PsiMethod getSuperMethod(@NotNull PsiMethod method) {
if (method.isConstructor()) {
return JavaPsiConstructorUtil.findConstructorInSuperWithParameterTypes(method, method.getSignature(PsiSubstitutor.EMPTY).getParameterTypes());
PsiMethod superCtor = JavaPsiConstructorUtil.findConstructorInSuper(method);
if (superCtor == null) return null;
PsiClass superClass = superCtor.getContainingClass();
if (superClass == null || CommonClassNames.JAVA_LANG_OBJECT.equals(superClass.getQualifiedName()) ||
superCtor.getParameters().length != method.getParameters().length) {
return null;
}
return superCtor;
}
return MethodUtils.getSuper(method);
}
@@ -20,4 +20,37 @@ class Sub extends Super {
@Override
void overloaded(String <warning descr="Parameter name 'string' is different from parameter 'str' overridden">string</warning>) {
}
}
class A<T> {
A(T name, int age) {}
A() {}
}
class B<T> extends A<T> {
B(T <warning descr="Parameter name 'street' is different from parameter 'name' overridden">street</warning>,
int <warning descr="Parameter name 'number' is different from parameter 'age' overridden">number</warning>) {
super(street, number);
}
}
class C {
C(String name, int age) {}
C() {}
}
class D extends C {
D(String street, int number) {
super();
}
}
class E {
E(String name, int age) {}
}
class F extends E {
F(String name, int age, int weight) {
super(name, age);
}
}