[java] Don't suggest generating broken overload constructors

In implicit and anonymous classes, constructors can't be declared. #IDEA-359731 Fixed

GitOrigin-RevId: 76e978d04052dffd955bfac6c1016fa707201b29
This commit is contained in:
Bart van Helvert
2024-09-25 22:45:37 +02:00
committed by intellij-monorepo-bot
parent 941408d4c8
commit 690f1167ff
3 changed files with 21 additions and 0 deletions

View File

@@ -50,6 +50,9 @@ public final class DefineParamsDefaultValueAction extends PsiBasedModCommandActi
if (containingClass == null || (containingClass.isInterface() && !PsiUtil.isAvailable(JavaFeature.EXTENSION_METHODS, method))) {
return null;
}
if ((containingClass instanceof PsiImplicitClass || containingClass instanceof PsiAnonymousClass) && method.isConstructor()) {
return null; // constructors can't be declared here, code is broken so don't suggest generating more broken code
}
if (containingClass.isAnnotationType()) {
// Method with parameters in annotation is a compilation error; there's no sense to create overload
return null;

View File

@@ -0,0 +1,16 @@
// "Generate overloaded constructor with default parameter values" "false"
class Bar {
interface Foo {
void bar();
}
public void bar() {
Foo foo = new Foo() {
Foo(String str<caret>) {
}
@Override
public void bar() { }
};
}
}

View File

@@ -0,0 +1,2 @@
// "Generate overloaded constructor with default parameter values" "false"
Foo(String str<caret>)