diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorMatchingSuperFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorMatchingSuperFix.java index 85ca0d50f817..0aed69749f15 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorMatchingSuperFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorMatchingSuperFix.java @@ -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 diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorMatchingSuper/beforeSameSignatureConstructorAlreadyPresent.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorMatchingSuper/beforeSameSignatureConstructorAlreadyPresent.java new file mode 100644 index 000000000000..6468b49dabfb --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorMatchingSuper/beforeSameSignatureConstructorAlreadyPresent.java @@ -0,0 +1,9 @@ +// "Create constructor matching super" "false" +class A { + public A(int i) { + } +} +class B extends A { + public B(int i) { + } +} \ No newline at end of file