mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-382795 [java]: fix "implement methods" quick-fix in enum constant initializer
GitOrigin-RevId: 1708354a1be7a00777c0fdae76a6fbd9fff926c0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a38401d202
commit
b036cda015
+9
-13
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
@@ -51,32 +51,28 @@ public class ImplementMethodsFix extends LocalQuickFixAndIntentionActionOnPsiEle
|
||||
@Override
|
||||
public void invoke(@NotNull Project project,
|
||||
@NotNull PsiFile psiFile,
|
||||
final @Nullable Editor editor,
|
||||
@Nullable Editor editor,
|
||||
@NotNull PsiElement startElement,
|
||||
@NotNull PsiElement endElement) {
|
||||
final PsiElement myPsiElement = startElement;
|
||||
|
||||
if (editor == null || !FileModificationService.getInstance().prepareFileForWrite(myPsiElement.getContainingFile())) return;
|
||||
if (myPsiElement instanceof PsiEnumConstant) {
|
||||
final boolean hasClassInitializer = ((PsiEnumConstant)myPsiElement).getInitializingClass() != null;
|
||||
chooseMethodsToImplement(editor, startElement,
|
||||
((PsiEnumConstant)myPsiElement).getContainingClass(),
|
||||
hasClassInitializer, chooser -> {
|
||||
if (editor == null || !FileModificationService.getInstance().prepareFileForWrite(startElement.getContainingFile())) return;
|
||||
if (startElement instanceof PsiEnumConstant constant) {
|
||||
final PsiEnumConstantInitializer aClass = constant.getInitializingClass();
|
||||
final boolean hasInitializer = aClass != null;
|
||||
chooseMethodsToImplement(editor, startElement, hasInitializer ? aClass : constant.getContainingClass(), hasInitializer , chooser -> {
|
||||
if (chooser == null) return;
|
||||
|
||||
final List<PsiMethodMember> selectedElements = chooser.getSelectedElements();
|
||||
if (selectedElements == null || selectedElements.isEmpty()) return;
|
||||
|
||||
WriteCommandAction.writeCommandAction(project, psiFile).run(() -> {
|
||||
final PsiClass psiClass = ((PsiEnumConstant)myPsiElement).getOrCreateInitializingClass();
|
||||
final PsiClass psiClass = constant.getOrCreateInitializingClass();
|
||||
OverrideImplementUtil.overrideOrImplementMethodsInRightPlace(editor, psiClass, selectedElements, chooser.getOptions());
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
OverrideImplementUtil.chooseAndImplementMethods(project, editor, (PsiClass)myPsiElement);
|
||||
OverrideImplementUtil.chooseAndImplementMethods(project, editor, (PsiClass)startElement);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
// "Implement methods" "true-preview"
|
||||
class Container {
|
||||
|
||||
private int brushColor = 0x1;
|
||||
|
||||
private enum Content {
|
||||
Value1 {
|
||||
@Override
|
||||
public int method1(Container e) {
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
Value2 {
|
||||
@Override
|
||||
public int method1(Container e) {
|
||||
return 0xff000000;
|
||||
}
|
||||
},
|
||||
Value3 {
|
||||
@Override
|
||||
public int method1(Container e) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void method2(
|
||||
Container iconEditor,
|
||||
Object g
|
||||
) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public abstract int method1(Container e);
|
||||
|
||||
public void method2(
|
||||
Container iconEditor,
|
||||
Object g
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// "Implement methods" "true-preview"
|
||||
class Container {
|
||||
|
||||
private int brushColor = 0x1;
|
||||
|
||||
private enum Content {
|
||||
Value1 {
|
||||
@Override
|
||||
public int method1(Container e) {
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
Value2 {
|
||||
@Override
|
||||
public int method1(Container e) {
|
||||
return 0xff000000;
|
||||
}
|
||||
},
|
||||
Value3<caret> {
|
||||
@Override
|
||||
public void method2(
|
||||
Container iconEditor,
|
||||
Object g
|
||||
) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public abstract int method1(Container e);
|
||||
|
||||
public void method2(
|
||||
Container iconEditor,
|
||||
Object g
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user