mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[analysis-api] LocalQuickFixBackedByIntentionAction: delegate startInWriteAction
GitOrigin-RevId: df06d41cbde9dda045a12d7e32f021bd2d3c4190
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3fb8f91f06
commit
2a97b0103c
+65
-60
@@ -22,76 +22,81 @@ import java.util.Objects;
|
||||
* which could be adapted using {@link LocalQuickFix#from(ModCommandAction)}.
|
||||
*/
|
||||
public class LocalQuickFixBackedByIntentionAction implements LocalQuickFix, Iconable, ReportingClassSubstitutor {
|
||||
private final @NotNull IntentionAction myAction;
|
||||
private final @NotNull IntentionAction myAction;
|
||||
|
||||
public LocalQuickFixBackedByIntentionAction(@NotNull IntentionAction action) {
|
||||
myAction = action;
|
||||
}
|
||||
public LocalQuickFixBackedByIntentionAction(@NotNull IntentionAction action) {
|
||||
myAction = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
return myAction.getText();
|
||||
}
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
return myAction.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getFamilyName() {
|
||||
return myAction.getFamilyName();
|
||||
}
|
||||
@Override
|
||||
public @NotNull String getFamilyName() {
|
||||
return myAction.getFamilyName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
myAction.invoke(project, null, getPsiFile(descriptor));
|
||||
}
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
myAction.invoke(project, null, getPsiFile(descriptor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull IntentionPreviewInfo generatePreview(@NotNull Project project, @NotNull ProblemDescriptor previewDescriptor) {
|
||||
return myAction.generatePreview(project,
|
||||
Objects.requireNonNull(IntentionPreviewUtils.getPreviewEditor()),
|
||||
Objects.requireNonNull(getPsiFile(previewDescriptor)));
|
||||
}
|
||||
@Override
|
||||
public @NotNull IntentionPreviewInfo generatePreview(@NotNull Project project, @NotNull ProblemDescriptor previewDescriptor) {
|
||||
return myAction.generatePreview(project,
|
||||
Objects.requireNonNull(IntentionPreviewUtils.getPreviewEditor()),
|
||||
Objects.requireNonNull(getPsiFile(previewDescriptor)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PsiElement getElementToMakeWritable(@NotNull PsiFile file) {
|
||||
return myAction.getElementToMakeWritable(file);
|
||||
}
|
||||
@Override
|
||||
public @Nullable PsiElement getElementToMakeWritable(@NotNull PsiFile file) {
|
||||
return myAction.getElementToMakeWritable(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Class<?> getSubstitutedClass() {
|
||||
return ReportingClassSubstitutor.getClassToReport(myAction);
|
||||
}
|
||||
|
||||
private static @Nullable PsiFile getPsiFile(@NotNull ProblemDescriptor descriptor) {
|
||||
PsiElement startElement = descriptor.getStartElement();
|
||||
if (startElement != null) {
|
||||
return startElement.getContainingFile();
|
||||
}
|
||||
PsiElement endElement = descriptor.getEndElement();
|
||||
if (endElement != null) {
|
||||
return endElement.getContainingFile();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon(@IconFlags int flags) {
|
||||
if (myAction instanceof Iconable) {
|
||||
return ((Iconable) myAction).getIcon(flags);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
LocalQuickFixBackedByIntentionAction action = (LocalQuickFixBackedByIntentionAction)o;
|
||||
|
||||
return myAction.equals(action.myAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myAction.hashCode();
|
||||
}
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return myAction.startInWriteAction();
|
||||
}
|
||||
|
||||
private static @Nullable PsiFile getPsiFile(@NotNull ProblemDescriptor descriptor) {
|
||||
PsiElement startElement = descriptor.getStartElement();
|
||||
if (startElement != null) {
|
||||
return startElement.getContainingFile();
|
||||
}
|
||||
PsiElement endElement = descriptor.getEndElement();
|
||||
if (endElement != null) {
|
||||
return endElement.getContainingFile();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon(@IconFlags int flags) {
|
||||
if (myAction instanceof Iconable) {
|
||||
return ((Iconable)myAction).getIcon(flags);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
LocalQuickFixBackedByIntentionAction action = (LocalQuickFixBackedByIntentionAction)o;
|
||||
|
||||
return myAction.equals(action.myAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myAction.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user