disable constructor matching super when appropriate candidate already present

IDEA-113427
This commit is contained in:
Anna Kozlova
2018-06-26 09:18:42 +03:00
parent 4f73487a62
commit 002134fe5b
2 changed files with 26 additions and 2 deletions
@@ -61,8 +61,23 @@ public class CreateConstructorMatchingSuperFix extends BaseIntentionAction {
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!myClass.isValid() || !myClass.getManager().isInProject(myClass)) return false;
setText(QuickFixBundle.message("create.constructor.matching.super"));
return true;
PsiClass base = myClass.getSuperClass();
if (base == null) return false;
PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(base, myClass, PsiSubstitutor.EMPTY);
for (PsiMethod baseConstructor: base.getConstructors()) {
if (PsiUtil.isAccessible(baseConstructor, myClass, null)) {
PsiMethod derived = GenerateMembersUtil.substituteGenericMethod(baseConstructor, substitutor, myClass);
String className = myClass.getName();
LOG.assertTrue(className != null);
derived.setName(className);
if (myClass.findMethodBySignature(derived, false) == null) {
setText(QuickFixBundle.message("create.constructor.matching.super"));
return true;
}
}
}
return false;
}
@Override
@@ -0,0 +1,9 @@
// "Create constructor matching super" "false"
class A {
public A(int i) {
}
}
class B extends A {
public B<caret>(int i) {
}
}