diff --git a/platform/lang-api/src/com/intellij/lang/LanguageImportStatements.java b/platform/lang-api/src/com/intellij/lang/LanguageImportStatements.java index 5fe4acefa9ce..cf7ae42ea17a 100644 --- a/platform/lang-api/src/com/intellij/lang/LanguageImportStatements.java +++ b/platform/lang-api/src/com/intellij/lang/LanguageImportStatements.java @@ -20,7 +20,11 @@ package com.intellij.lang; import com.intellij.psi.PsiFile; -import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; public class LanguageImportStatements extends LanguageExtension { public static final LanguageImportStatements INSTANCE = new LanguageImportStatements(); @@ -29,9 +33,15 @@ public class LanguageImportStatements extends LanguageExtension super("com.intellij.lang.importOptimizer"); } - @Nullable - public ImportOptimizer forFile(PsiFile file) { - ImportOptimizer optimizer = forLanguage(file.getLanguage()); - return optimizer != null && optimizer.supports(file) ? optimizer : null; + public List forFile(PsiFile file) { + List runnables = new ArrayList(); + Set optimizers = new HashSet(); + for (PsiFile psiFile : file.getViewProvider().getAllFiles()) { + ImportOptimizer optimizer = forLanguage(psiFile.getLanguage()); + if (optimizer != null && optimizer.supports(psiFile) && optimizers.add(optimizer)) { + runnables.add(optimizer.processFile(psiFile)); + } + } + return runnables; } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsAction.java b/platform/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsAction.java index 951dbecd7c3c..416e2e4bc09b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsAction.java @@ -193,6 +193,6 @@ public class OptimizeImportsAction extends AnAction { } private static boolean isOptimizeImportsAvailable(final PsiFile file) { - return LanguageImportStatements.INSTANCE.forFile(file) != null; + return !LanguageImportStatements.INSTANCE.forFile(file).isEmpty(); } } diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlUnusedNamespaceInspection.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlUnusedNamespaceInspection.java index e1acc34b9356..009a89b175cd 100644 --- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlUnusedNamespaceInspection.java +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlUnusedNamespaceInspection.java @@ -73,21 +73,21 @@ public class XmlUnusedNamespaceInspection extends XmlSuppressableInspectionTool XmlAttributeValue value = attribute.getValueElement(); assert value != null; holder.registerProblem(attribute, "Namespace declaration is never used", ProblemHighlightType.LIKE_UNUSED_SYMBOL, - new RemoveNamespaceDeclarationFix(declaredPrefix)); + new RemoveNamespaceDeclarationFix(declaredPrefix, false)); XmlTag parent = attribute.getParent(); if (declaredPrefix.length() == 0) { XmlAttribute location = getDefaultLocation(parent); if (location != null) { holder.registerProblem(location, NAMESPACE_LOCATION_IS_NEVER_USED, ProblemHighlightType.LIKE_UNUSED_SYMBOL, - new RemoveNamespaceDeclarationFix(declaredPrefix)); + new RemoveNamespaceDeclarationFix(declaredPrefix, true)); } } else { for (PsiReference reference : getLocationReferences(namespace, parent)) { if (!XmlHighlightVisitor.hasBadResolve(reference, false)) holder.registerProblemForReference(reference, ProblemHighlightType.LIKE_UNUSED_SYMBOL, NAMESPACE_LOCATION_IS_NEVER_USED, - new RemoveNamespaceDeclarationFix(declaredPrefix)); + new RemoveNamespaceDeclarationFix(declaredPrefix, true)); } } } @@ -234,9 +234,11 @@ public class XmlUnusedNamespaceInspection extends XmlSuppressableInspectionTool public static final String NAME = "Remove unused namespace declaration"; protected final String myPrefix; + private final boolean myLocationFix; - private RemoveNamespaceDeclarationFix(@Nullable String prefix) { + private RemoveNamespaceDeclarationFix(@Nullable String prefix, boolean locationFix) { myPrefix = prefix; + myLocationFix = locationFix; } @NotNull @@ -328,7 +330,9 @@ public class XmlUnusedNamespaceInspection extends XmlSuppressableInspectionTool @Override public boolean equals(Object obj) { - return obj instanceof RemoveNamespaceDeclarationFix && Comparing.equal(myPrefix, ((RemoveNamespaceDeclarationFix)obj).myPrefix); + return obj instanceof RemoveNamespaceDeclarationFix && + Comparing.equal(myPrefix, ((RemoveNamespaceDeclarationFix)obj).myPrefix) && + (myLocationFix || ((RemoveNamespaceDeclarationFix)obj).myLocationFix); } @Override @@ -342,7 +346,7 @@ public class XmlUnusedNamespaceInspection extends XmlSuppressableInspectionTool public static final String NAME = "Remove unused namespace location"; private RemoveNamespaceLocationFix(String namespace) { - super(namespace); + super(namespace, true); } @NotNull