Search in sources :

Example 1 with LiteralTextEscaper

use of com.intellij.psi.LiteralTextEscaper in project intellij-community by JetBrains.

the class BaseInjection method getInjectedArea.

@NotNull
public List<TextRange> getInjectedArea(final PsiElement element) {
    final TextRange textRange = ElementManipulators.getValueTextRange(element);
    if (myCompiledValuePattern == null) {
        return Collections.singletonList(textRange);
    } else {
        final LiteralTextEscaper<? extends PsiLanguageInjectionHost> textEscaper = ((PsiLanguageInjectionHost) element).createLiteralTextEscaper();
        final StringBuilder sb = new StringBuilder();
        textEscaper.decode(textRange, sb);
        final List<TextRange> ranges = getMatchingRanges(myCompiledValuePattern.matcher(StringPattern.newBombedCharSequence(sb)), sb.length());
        return !ranges.isEmpty() ? ContainerUtil.map(ranges, s -> new TextRange(textEscaper.getOffsetInHost(s.getStartOffset(), textRange), textEscaper.getOffsetInHost(s.getEndOffset(), textRange))) : Collections.<TextRange>emptyList();
    }
}
Also used : Arrays(java.util.Arrays) ArrayUtil(com.intellij.util.ArrayUtil) PersistentStateComponent(com.intellij.openapi.components.PersistentStateComponent) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) CDATA(org.jdom.CDATA) Matcher(java.util.regex.Matcher) Comparing(com.intellij.openapi.util.Comparing) SmartList(com.intellij.util.SmartList) PatternCompilerFactory(com.intellij.patterns.compiler.PatternCompilerFactory) PsiLanguageInjectionHost(com.intellij.psi.PsiLanguageInjectionHost) PsiElement(com.intellij.psi.PsiElement) Logger(com.intellij.openapi.diagnostic.Logger) LiteralTextEscaper(com.intellij.psi.LiteralTextEscaper) ElementManipulators(com.intellij.psi.ElementManipulators) ProgressManager(com.intellij.openapi.progress.ProgressManager) InjectorUtils(org.intellij.plugins.intelliLang.inject.InjectorUtils) StringUtil(com.intellij.openapi.util.text.StringUtil) Key(com.intellij.openapi.util.Key) TextRange(com.intellij.openapi.util.TextRange) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) RegExp(org.intellij.lang.annotations.RegExp) StringPattern(com.intellij.patterns.StringPattern) Pattern(java.util.regex.Pattern) PatternCompiler(com.intellij.patterns.compiler.PatternCompiler) NotNull(org.jetbrains.annotations.NotNull) Element(org.jdom.Element) Collections(java.util.Collections) PsiLanguageInjectionHost(com.intellij.psi.PsiLanguageInjectionHost) TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PersistentStateComponent (com.intellij.openapi.components.PersistentStateComponent)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 Comparing (com.intellij.openapi.util.Comparing)1 Key (com.intellij.openapi.util.Key)1 TextRange (com.intellij.openapi.util.TextRange)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 StringPattern (com.intellij.patterns.StringPattern)1 PatternCompiler (com.intellij.patterns.compiler.PatternCompiler)1 PatternCompilerFactory (com.intellij.patterns.compiler.PatternCompilerFactory)1 ElementManipulators (com.intellij.psi.ElementManipulators)1 LiteralTextEscaper (com.intellij.psi.LiteralTextEscaper)1 PsiElement (com.intellij.psi.PsiElement)1 PsiLanguageInjectionHost (com.intellij.psi.PsiLanguageInjectionHost)1 ArrayUtil (com.intellij.util.ArrayUtil)1 SmartList (com.intellij.util.SmartList)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1