optimize imports for template languages (JSP, JSPX, Facelets) rubymine/112.205 rubymine/112.206
authorDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Mon, 19 Dec 2011 12:30:11 +0000 (16:30 +0400)
committerDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Mon, 19 Dec 2011 12:31:23 +0000 (16:31 +0400)
platform/lang-impl/src/com/intellij/codeInsight/actions/LayoutCodeDialog.java
platform/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsProcessor.java

index cfbc5907b75da136ec38488ecebeed282efd5ee4..4e1f6f7deccb59ff8ce24627e0e76e3042166c2b 100644 (file)
@@ -103,7 +103,7 @@ public class LayoutCodeDialog extends DialogWrapper {
     myCbIncludeSubdirs.setEnabled(myRbDirectory.isSelected());
     myCbOptimizeImports.setEnabled(
       !myRbSelectedText.isSelected() &&
-      !(myFile != null && LanguageImportStatements.INSTANCE.forFile(myFile) == null && myRbFile.isSelected()));
+      !(myFile != null && LanguageImportStatements.INSTANCE.forFile(myFile).isEmpty() && myRbFile.isSelected()));
 
     final boolean canTargetVcsChanges = canTargetVcsRegions();
     myCbOnlyVcsChangedRegions.setEnabled(canTargetVcsChanges);
index d16b9dcf3b46578aa72e494c2bea58c35134f423..f6ce2f44134ebff3e229cb0d66aea7cf9c103551 100644 (file)
@@ -17,7 +17,6 @@
 package com.intellij.codeInsight.actions;
 
 import com.intellij.codeInsight.CodeInsightBundle;
-import com.intellij.lang.ImportOptimizer;
 import com.intellij.lang.LanguageImportStatements;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.Project;
@@ -27,6 +26,7 @@ import com.intellij.psi.PsiFile;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NotNull;
 
+import java.util.List;
 import java.util.concurrent.FutureTask;
 
 public class OptimizeImportsProcessor extends AbstractLayoutCodeProcessor {
@@ -58,11 +58,16 @@ public class OptimizeImportsProcessor extends AbstractLayoutCodeProcessor {
   }
 
   @NotNull
-  protected FutureTask<Boolean> preprocessFile(@NotNull final PsiFile file, boolean processChangedTextOnly)
-    throws IncorrectOperationException
-  {
-    final ImportOptimizer optimizer = LanguageImportStatements.INSTANCE.forFile(file);
-    Runnable runnable = optimizer != null ? optimizer.processFile(file) : EmptyRunnable.getInstance();
+  protected FutureTask<Boolean> preprocessFile(@NotNull final PsiFile file, boolean processChangedTextOnly) throws IncorrectOperationException {
+    final List<Runnable> optimizers = LanguageImportStatements.INSTANCE.forFile(file);
+    Runnable runnable = optimizers.isEmpty() ? EmptyRunnable.getInstance() : new Runnable() {
+      @Override
+      public void run() {
+        for (Runnable optimizer : optimizers) {
+          optimizer.run();
+        }
+      }
+    };
     return new FutureTask<Boolean>(runnable, true);
   }
 }