From c0f56919766f10f8a0cf6075d26fed0db1e153ee Mon Sep 17 00:00:00 2001 From: Kirill Safonov Date: Thu, 19 Feb 2009 17:53:24 +0300 Subject: [PATCH] the "optimize imports" option on reformat mxml file could / should be enabled (IDEA-19303), Optimize imports action & quick fix scope for mxml files (IDEADEV-34228) --- lang-api/src/com/intellij/lang/ImportOptimizer.java | 3 ++- lang-api/src/com/intellij/lang/LanguageImportStatements.java | 12 ++++++++++++ .../com/intellij/codeInsight/actions/LayoutCodeDialog.java | 4 ++-- .../intellij/codeInsight/actions/OptimizeImportsAction.java | 2 +- .../codeInsight/actions/OptimizeImportsProcessor.java | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lang-api/src/com/intellij/lang/ImportOptimizer.java b/lang-api/src/com/intellij/lang/ImportOptimizer.java index c9ba7ec8a2..c4c84f05c0 100644 --- a/lang-api/src/com/intellij/lang/ImportOptimizer.java +++ b/lang-api/src/com/intellij/lang/ImportOptimizer.java @@ -20,8 +20,9 @@ import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; /** - * Implementors of the inteface encapsulate optimize imports process for the language. + * Implementors of the interface encapsulate optimize imports process for the language. * @author max + * @see ImportOptimizer2 */ public interface ImportOptimizer { /** diff --git a/lang-api/src/com/intellij/lang/LanguageImportStatements.java b/lang-api/src/com/intellij/lang/LanguageImportStatements.java index 3e5d61a26f..8a59df2d32 100644 --- a/lang-api/src/com/intellij/lang/LanguageImportStatements.java +++ b/lang-api/src/com/intellij/lang/LanguageImportStatements.java @@ -3,10 +3,22 @@ */ package com.intellij.lang; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.Nullable; + public class LanguageImportStatements extends LanguageExtension { public static final LanguageImportStatements INSTANCE = new LanguageImportStatements(); private LanguageImportStatements() { super("com.intellij.lang.importOptimizer"); } + + @Nullable + public ImportOptimizer forFile(PsiFile file) { + ImportOptimizer optimizer = forLanguage(file.getLanguage()); + if (optimizer instanceof ImportOptimizer2) { + return ((ImportOptimizer2)optimizer).supports(file) ? optimizer : null; + } + return optimizer; + } } \ No newline at end of file diff --git a/lang-impl/src/com/intellij/codeInsight/actions/LayoutCodeDialog.java b/lang-impl/src/com/intellij/codeInsight/actions/LayoutCodeDialog.java index bbf1087ca8..e1c5399634 100644 --- a/lang-impl/src/com/intellij/codeInsight/actions/LayoutCodeDialog.java +++ b/lang-impl/src/com/intellij/codeInsight/actions/LayoutCodeDialog.java @@ -88,7 +88,7 @@ public class LayoutCodeDialog extends DialogWrapper { private void updateState() { myCbIncludeSubdirs.setEnabled(myRbDirectory.isSelected()); myCbOptimizeImports.setEnabled( - !myRbSelectedText.isSelected() && !(myFile != null && LanguageImportStatements.INSTANCE.forLanguage(myFile.getLanguage()) == null && myRbFile.isSelected())); + !myRbSelectedText.isSelected() && !(myFile != null && LanguageImportStatements.INSTANCE.forFile(myFile) == null && myRbFile.isSelected())); } protected JComponent createNorthPanel() { @@ -192,4 +192,4 @@ public class LayoutCodeDialog extends DialogWrapper { super.doOKAction(); setOptimizeImportsOption(isOptimizeImports()); } -} \ No newline at end of file +} diff --git a/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsAction.java b/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsAction.java index b542127731..d347d22aee 100644 --- a/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsAction.java +++ b/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsAction.java @@ -158,6 +158,6 @@ public class OptimizeImportsAction extends AnAction { } private static boolean isOptimizeImportsAvailable(final PsiFile file) { - return LanguageImportStatements.INSTANCE.forLanguage(file.getLanguage()) != null; + return LanguageImportStatements.INSTANCE.forFile(file) != null; } } diff --git a/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsProcessor.java b/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsProcessor.java index bb3a05bdb1..0e3ee31f1d 100644 --- a/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsProcessor.java +++ b/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsProcessor.java @@ -37,7 +37,7 @@ public class OptimizeImportsProcessor extends AbstractLayoutCodeProcessor { @NotNull protected Runnable preprocessFile(final PsiFile file) throws IncorrectOperationException { - final ImportOptimizer optimizer = LanguageImportStatements.INSTANCE.forLanguage(file.getLanguage()); + final ImportOptimizer optimizer = LanguageImportStatements.INSTANCE.forFile(file); return optimizer != null ? optimizer.processFile(file) : EmptyRunnable.getInstance(); } } -- 2.11.4.GIT