From b386966e34fba65d08471a14e333661cc3d744de Mon Sep 17 00:00:00 2001 From: Michail Plushnikov Date: Wed, 12 Mar 2014 19:22:21 +0100 Subject: [PATCH] Fixed #37: Delombok of files included as library failes --- .../plugin/action/delombok/BaseDelombokAction.java | 3 +++ .../plugin/action/delombok/BaseDelombokHandler.java | 12 +++++++----- .../plugin/action/lombok/BaseLombokAction.java | 9 ++++++++- .../plugin/action/lombok/BaseLombokHandler.java | 10 ++++++---- lombok-plugin/src/main/resources/META-INF/plugin.xml | 1 + 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/delombok/BaseDelombokAction.java b/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/delombok/BaseDelombokAction.java index 571d40a50..5774ae427 100644 --- a/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/delombok/BaseDelombokAction.java +++ b/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/delombok/BaseDelombokAction.java @@ -198,6 +198,9 @@ protected boolean isValidForFile(@NotNull Project project, @NotNull Editor edito if (file instanceof PsiCompiledElement) { return false; } + if (!file.isWritable()) { + return false; + } PsiDocumentManager.getInstance(project).commitAllDocuments(); diff --git a/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/delombok/BaseDelombokHandler.java b/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/delombok/BaseDelombokHandler.java index a13002d64..3a0c67527 100644 --- a/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/delombok/BaseDelombokHandler.java +++ b/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/delombok/BaseDelombokHandler.java @@ -40,6 +40,13 @@ protected BaseDelombokHandler(AbstractProcessor... lombokProcessors) { this.lombokProcessors = new ArrayList(Arrays.asList(lombokProcessors)); } + public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @NotNull PsiClass psiClass) { + if (psiFile.isWritable()) { + invoke(project, psiClass); + finish(project, psiFile); + } + } + public void invoke(@NotNull Project project, @NotNull PsiJavaFile psiFile) { for (PsiClass psiClass : psiFile.getClasses()) { invoke(project, psiClass); @@ -51,11 +58,6 @@ public void invoke(@NotNull Project project, @NotNull PsiJavaFile psiFile) { finish(project, psiFile); } - public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @NotNull PsiClass psiClass) { - invoke(project, psiClass); - finish(project, psiFile); - } - private void invoke(Project project, PsiClass psiClass) { for (AbstractProcessor lombokProcessor : lombokProcessors) { processClass(project, psiClass, lombokProcessor); diff --git a/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/lombok/BaseLombokAction.java b/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/lombok/BaseLombokAction.java index 70cae1ca2..05677b939 100644 --- a/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/lombok/BaseLombokAction.java +++ b/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/lombok/BaseLombokAction.java @@ -2,6 +2,10 @@ import com.intellij.codeInsight.CodeInsightActionHandler; import com.intellij.codeInsight.generation.actions.BaseGenerateAction; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.NotNull; public abstract class BaseLombokAction extends BaseGenerateAction { @@ -9,5 +13,8 @@ protected BaseLombokAction(CodeInsightActionHandler handler) { super(handler); } - + @Override + protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { + return file.isWritable() && super.isValidForFile(project, editor, file); + } } diff --git a/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/lombok/BaseLombokHandler.java b/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/lombok/BaseLombokHandler.java index 4c4ac71fb..59f5bb4dd 100644 --- a/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/lombok/BaseLombokHandler.java +++ b/lombok-plugin/src/main/java/de/plushnikov/intellij/plugin/action/lombok/BaseLombokHandler.java @@ -34,11 +34,13 @@ public boolean startInWriteAction() { } public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { - PsiClass psiClass = OverrideImplementUtil.getContextClass(project, editor, file, false); - if (null != psiClass) { - processClass(psiClass); + if (file.isWritable()) { + PsiClass psiClass = OverrideImplementUtil.getContextClass(project, editor, file, false); + if (null != psiClass) { + processClass(psiClass); - UndoUtil.markPsiFileForUndo(file); + UndoUtil.markPsiFileForUndo(file); + } } } diff --git a/lombok-plugin/src/main/resources/META-INF/plugin.xml b/lombok-plugin/src/main/resources/META-INF/plugin.xml index a53463aad..a0de3cb4e 100644 --- a/lombok-plugin/src/main/resources/META-INF/plugin.xml +++ b/lombok-plugin/src/main/resources/META-INF/plugin.xml @@ -157,6 +157,7 @@
  • Fixed #17: Cyclic parent child relation
  • Fixed #34: Lombok plugin crashes
  • Fixed #36: Possible class cast exception
  • +
  • Fixed #37: Delombok of files included as library failes
  • 0.8.2