diff --git a/RegExpSupport/src/org/intellij/lang/regexp/surroundWith/SimpleSurroundDescriptor.java b/RegExpSupport/src/org/intellij/lang/regexp/surroundWith/SimpleSurroundDescriptor.java index 704ffde1944c..8c6d85687f1a 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/surroundWith/SimpleSurroundDescriptor.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/surroundWith/SimpleSurroundDescriptor.java @@ -47,7 +47,12 @@ public class SimpleSurroundDescriptor implements SurroundDescriptor { return SURROUNDERS; } - private PsiElement[] findElementsInRange(PsiFile file, int startOffset, int endOffset) { + @Override + public boolean isExclusive() { + return false; + } + + private PsiElement[] findElementsInRange(PsiFile file, int startOffset, int endOffset) { // adjust start/end PsiElement element1 = file.findElementAt(startOffset); PsiElement element2 = file.findElementAt(endOffset - 1); diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaExpressionSurroundDescriptor.java b/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaExpressionSurroundDescriptor.java index bf295d453de8..9ff214c3f1df 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaExpressionSurroundDescriptor.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaExpressionSurroundDescriptor.java @@ -65,4 +65,9 @@ public class JavaExpressionSurroundDescriptor implements SurroundDescriptor { } return mySurrounders; } + + @Override + public boolean isExclusive() { + return false; + } } diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaStatementsSurroundDescriptor.java b/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaStatementsSurroundDescriptor.java index b53cd3fb641a..1d2c94a2831a 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaStatementsSurroundDescriptor.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaStatementsSurroundDescriptor.java @@ -48,6 +48,11 @@ public class JavaStatementsSurroundDescriptor implements SurroundDescriptor { return SURROUNDERS; } + @Override + public boolean isExclusive() { + return false; + } + @NotNull public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) { final PsiElement[] statements = CodeInsightUtil.findStatementsInRange(file, startOffset, endOffset); diff --git a/platform/lang-api/src/com/intellij/lang/surroundWith/SurroundDescriptor.java b/platform/lang-api/src/com/intellij/lang/surroundWith/SurroundDescriptor.java index fac1520fcb43..34b80aaec021 100644 --- a/platform/lang-api/src/com/intellij/lang/surroundWith/SurroundDescriptor.java +++ b/platform/lang-api/src/com/intellij/lang/surroundWith/SurroundDescriptor.java @@ -51,4 +51,6 @@ public interface SurroundDescriptor { */ @NotNull Surrounder[] getSurrounders(); + + boolean isExclusive(); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java index 91972927595b..15404e5792a3 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java @@ -108,6 +108,19 @@ public class SurroundWithHandler implements CodeInsightActionHandler { surroundDescriptors.addAll(LanguageSurrounders.INSTANCE.allForLanguage(l)); if (l != baseLanguage) surroundDescriptors.addAll(LanguageSurrounders.INSTANCE.allForLanguage(baseLanguage)); + int exclusiveCount = 0; + List exclusiveSurroundDescriptors = new ArrayList(); + for (SurroundDescriptor sd : surroundDescriptors) { + if (sd.isExclusive()) { + exclusiveCount++; + exclusiveSurroundDescriptors.add(sd); + } + } + + if (exclusiveCount > 0) { + surroundDescriptors = exclusiveSurroundDescriptors; + } + if (surrounder != null) { invokeSurrounderInTests(project, editor, file, surrounder, startOffset, endOffset, surroundDescriptors); return null; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/GroovySurroundDescriptor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/GroovySurroundDescriptor.java index 22bf1d80ee16..0db6cb2b1f21 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/GroovySurroundDescriptor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/GroovySurroundDescriptor.java @@ -59,6 +59,11 @@ public class GroovySurroundDescriptor implements SurroundDescriptor { return ourSurrounders; } + @Override + public boolean isExclusive() { + return false; + } + @NotNull public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) { return GroovyRefactoringUtil.findStatementsInRange(file, startOffset, endOffset, true); diff --git a/xml/impl/src/com/intellij/lang/xml/XmlSurroundDescriptor.java b/xml/impl/src/com/intellij/lang/xml/XmlSurroundDescriptor.java index 8007d16ed2c5..f0683d3bbb06 100644 --- a/xml/impl/src/com/intellij/lang/xml/XmlSurroundDescriptor.java +++ b/xml/impl/src/com/intellij/lang/xml/XmlSurroundDescriptor.java @@ -64,6 +64,11 @@ public class XmlSurroundDescriptor implements SurroundDescriptor { return new Surrounder[0]; //everything is in live templates now } + @Override + public boolean isExclusive() { + return false; + } + protected boolean isEnabled(final TemplateImpl template) { final TemplateContext context = template.getTemplateContext(); return context.isEnabled(new XmlContextType()) || context.isEnabled(new HtmlContextType());