diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java index 23d6b17d8ec9..efe1de220d43 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java @@ -58,6 +58,7 @@ import org.jdom.JDOMException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; import java.io.IOException; import java.io.InputStream; @@ -557,6 +558,17 @@ public class Configuration extends SimpleModificationTracker implements Persiste return changed; } + @TestOnly + public void withInjections(List injections, Runnable runnable) { + replaceInjections(injections, ContainerUtil.emptyList(), true); + try { + runnable.run(); + } + finally { + replaceInjections(ContainerUtil.emptyList(), injections, true); + } + } + public static class AdvancedConfiguration { // runtime pattern validation instrumentation @NotNull private InstrumentationType myInstrumentationType = InstrumentationType.ASSERT; diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectLanguageAction.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectLanguageAction.java index 5b66555fe453..c03295a8bc23 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectLanguageAction.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectLanguageAction.java @@ -57,9 +57,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; +import java.util.*; import java.util.List; public class InjectLanguageAction implements IntentionAction, LowPriorityAction { @@ -116,9 +114,14 @@ public class InjectLanguageAction implements IntentionAction, LowPriorityAction @NotNull PsiFile file) { if (editor instanceof EditorWindow) return null; int offset = editor.getCaretModel().getOffset(); - PsiLanguageInjectionHost host = PsiTreeUtil.getParentOfType(file.findElementAt(offset), PsiLanguageInjectionHost.class, false); - if (host == null) return null; - return host.isValidHost()? host : null; + FileViewProvider vp = file.getViewProvider(); + for (Language language : vp.getLanguages()) { + PsiLanguageInjectionHost host = PsiTreeUtil.getParentOfType(vp.findElementAt(offset, language), PsiLanguageInjectionHost.class, false); + if (host != null && host.isValidHost()) { + return host; + } + } + return null; } public void invoke(@NotNull Project project, diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/BaseInjection.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/BaseInjection.java index 74789b644cb1..e4b941d88f28 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/BaseInjection.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/BaseInjection.java @@ -15,6 +15,7 @@ */ package org.intellij.plugins.intelliLang.inject.config; +import com.intellij.lang.Language; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressManager; @@ -33,6 +34,7 @@ import com.intellij.util.ArrayUtil; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import org.intellij.lang.annotations.RegExp; +import org.intellij.plugins.intelliLang.inject.InjectedLanguage; import org.intellij.plugins.intelliLang.inject.InjectorUtils; import org.jdom.CDATA; import org.jdom.Element; @@ -70,6 +72,19 @@ public class BaseInjection implements Injection, PersistentStateComponent helper = getCompiler(); myDisplayName = StringUtil.notNullize(element.getChildText("display-name")); myInjectedLanguageId = StringUtil.notNullize(element.getAttributeValue("language")); diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/InjectionPlace.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/InjectionPlace.java index 766db641e1c3..668f5d71ebf5 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/InjectionPlace.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/InjectionPlace.java @@ -19,7 +19,6 @@ package org.intellij.plugins.intelliLang.inject.config; import com.intellij.patterns.ElementPattern; import com.intellij.psi.PsiElement; import com.intellij.util.ArrayFactory; -import org.jetbrains.annotations.NotNull; /** * @author Gregory.Shrago @@ -32,10 +31,10 @@ public class InjectionPlace { public static final ArrayFactory ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new InjectionPlace[count]; private final boolean myEnabled; - private final ElementPattern myElementPattern; + private final ElementPattern myElementPattern; - public InjectionPlace(final ElementPattern myElementPattern, final boolean enabled) { + public InjectionPlace(ElementPattern myElementPattern, boolean enabled) { this.myElementPattern = myElementPattern; myEnabled = enabled; } @@ -48,7 +47,7 @@ public class InjectionPlace { return myElementPattern.toString(); } - public ElementPattern getElementPattern() { + public ElementPattern getElementPattern() { return myElementPattern; } diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/ui/BaseInjectionPanel.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/ui/BaseInjectionPanel.java index 76523605d550..293a77e7d63c 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/ui/BaseInjectionPanel.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/ui/BaseInjectionPanel.java @@ -118,7 +118,7 @@ public class BaseInjectionPanel extends AbstractInjectionPanel { places.add(new InjectionPlace(myHelper.compileElementPattern(text), enabled)); } for (InjectionPlace place : places) { - ElementPattern pattern = place.getElementPattern(); + ElementPattern pattern = place.getElementPattern(); if (pattern instanceof PatternCompilerImpl.LazyPresentablePattern) { try { ((PatternCompilerImpl.LazyPresentablePattern)pattern).compile(); diff --git a/plugins/IntelliLang/xml-support/org/intellij/plugins/intelliLang/inject/xml/XmlLanguageInjectionSupport.java b/plugins/IntelliLang/xml-support/org/intellij/plugins/intelliLang/inject/xml/XmlLanguageInjectionSupport.java index 45333f53706d..b932aefb72ed 100644 --- a/plugins/IntelliLang/xml-support/org/intellij/plugins/intelliLang/inject/xml/XmlLanguageInjectionSupport.java +++ b/plugins/IntelliLang/xml-support/org/intellij/plugins/intelliLang/inject/xml/XmlLanguageInjectionSupport.java @@ -183,9 +183,9 @@ public class XmlLanguageInjectionSupport extends AbstractLanguageInjectionSuppor AbstractTagInjection result; final InjectionPlace place = injection.getInjectionPlaces()[0]; - final ElementPattern rootPattern = place.getElementPattern(); - final ElementPatternCondition rootCondition = rootPattern.getCondition(); - final Class elementClass = rootCondition.getInitialCondition().getAcceptedClass(); + final ElementPattern rootPattern = place.getElementPattern(); + final ElementPatternCondition rootCondition = rootPattern.getCondition(); + final Class elementClass = rootCondition.getInitialCondition().getAcceptedClass(); if (XmlAttribute.class.equals(elementClass)) { result = new XmlAttributeInjection().copyFrom(injection); } @@ -194,7 +194,7 @@ public class XmlLanguageInjectionSupport extends AbstractLanguageInjectionSuppor } else return null; result.setInjectionPlaces(InjectionPlace.EMPTY_ARRAY); - for (PatternCondition condition : rootCondition.getConditions()) { + for (PatternCondition condition : rootCondition.getConditions()) { final String value = extractValue(condition); if ("withLocalName".equals(condition.getDebugMethodName())) { if (value == null) return null;