Java 类com.intellij.psi.LiteralTextEscaper 实例源码

项目:intellij-ce-playground    文件:PyStringLiteralTest.java   
public void testEscaperOffsetInEscapedBackslash() {
  final PyStringLiteralExpression expr = createLiteralFromText("'XXX foo.\\\\bar YYY'");
  assertNotNull(expr);
  final LiteralTextEscaper<? extends PsiLanguageInjectionHost> escaper = expr.createLiteralTextEscaper();
  final TextRange range = TextRange.create(5, 14);
  assertEquals(5, escaper.getOffsetInHost(0, range));
  assertEquals(6, escaper.getOffsetInHost(1, range));
  assertEquals(7, escaper.getOffsetInHost(2, range));
  assertEquals(8, escaper.getOffsetInHost(3, range));
  assertEquals(9, escaper.getOffsetInHost(4, range));
  assertEquals(11, escaper.getOffsetInHost(5, range));
  assertEquals(12, escaper.getOffsetInHost(6, range));
  assertEquals(13, escaper.getOffsetInHost(7, range));
  assertEquals(14, escaper.getOffsetInHost(8, range));
  assertEquals(-1, escaper.getOffsetInHost(9, range));
}
项目:intellij-ce-playground    文件:BaseInjection.java   
@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, new Function<TextRange, TextRange>() {
      public TextRange fun(TextRange s) {
        return new TextRange(textEscaper.getOffsetInHost(s.getStartOffset(), textRange), textEscaper.getOffsetInHost(s.getEndOffset(), textRange));
      }
    }) : Collections.<TextRange>emptyList();
  }
}
项目:tools-idea    文件:BaseInjection.java   
@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, new Function<TextRange, TextRange>() {
      public TextRange fun(TextRange s) {
        return new TextRange(textEscaper.getOffsetInHost(s.getStartOffset(), textRange), textEscaper.getOffsetInHost(s.getEndOffset(), textRange));
      }
    }) : Collections.<TextRange>emptyList();
  }
}
项目:consulo-csharp    文件:CSharpConstantExpressionImpl.java   
@NotNull
@Override
@RequiredReadAction
public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper()
{
    IElementType elementType = getLiteralType();
    if(elementType == CSharpTokens.STRING_LITERAL)
    {
        return new CSharpStringLiteralEscaper<>(this);
    }
    else if(elementType == CSharpTokens.VERBATIM_STRING_LITERAL)
    {
        return LiteralTextEscaper.createSimple(this);
    }
    throw new IllegalArgumentException("Unknown " + elementType);
}
项目:intellij-ce-playground    文件:JsonStringLiteralMixin.java   
@NotNull
@Override
public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() {
  return new JSStringLiteralEscaper<PsiLanguageInjectionHost>(this) {
    @Override
    protected boolean isRegExpLiteral() {
      return false;
    }
  };
}
项目:intellij-ce-playground    文件:PyStringLiteralTest.java   
public void testEscaperOffsetInHost() {
  final PyStringLiteralExpression expr = createLiteralFromText("'\\nfoo'");
  assertNotNull(expr);
  final LiteralTextEscaper<? extends PsiLanguageInjectionHost> escaper = expr.createLiteralTextEscaper();
  final TextRange newLineFoo = TextRange.create(1, 6);
  assertEquals(1, escaper.getOffsetInHost(0, newLineFoo));
  assertEquals(3, escaper.getOffsetInHost(1, newLineFoo));
  assertEquals(4, escaper.getOffsetInHost(2, newLineFoo));
  assertEquals(5, escaper.getOffsetInHost(3, newLineFoo));
  assertEquals(6, escaper.getOffsetInHost(4, newLineFoo));
  assertEquals(-1, escaper.getOffsetInHost(5, newLineFoo));
}
项目:intellij-ce-playground    文件:PyStringLiteralTest.java   
public void testEscaperOffsetInHostSubString() {
  final PyStringLiteralExpression expr = createLiteralFromText("'\\nfoo'");
  assertNotNull(expr);
  final LiteralTextEscaper<? extends PsiLanguageInjectionHost> escaper = expr.createLiteralTextEscaper();
  final TextRange fooOnly = TextRange.create(3, 6);
  assertEquals(3, escaper.getOffsetInHost(0, fooOnly));
  assertEquals(4, escaper.getOffsetInHost(1, fooOnly));
  assertEquals(5, escaper.getOffsetInHost(2, fooOnly));
  assertEquals(6, escaper.getOffsetInHost(3, fooOnly));
  assertEquals(-1, escaper.getOffsetInHost(4, fooOnly));
}
项目:intellij-ce-playground    文件:PyStringLiteralTest.java   
public void testEscaperOffsetInSingleCharString() {
  final PyStringLiteralExpression expr = createLiteralFromText("'c'");
  assertNotNull(expr);
  final LiteralTextEscaper<? extends PsiLanguageInjectionHost> escaper = expr.createLiteralTextEscaper();
  final TextRange range = TextRange.create(1, 2);
  assertEquals(1, escaper.getOffsetInHost(0, range));
  assertEquals(2, escaper.getOffsetInHost(1, range));
  assertEquals(-1, escaper.getOffsetInHost(2, range));
}
项目:intellij-ce-playground    文件:PyStringLiteralTest.java   
public void testEscaperOffsetInSingleEscapedCharString() {
  final PyStringLiteralExpression expr = createLiteralFromText("'\\n'");
  assertNotNull(expr);
  final LiteralTextEscaper<? extends PsiLanguageInjectionHost> escaper = expr.createLiteralTextEscaper();
  final TextRange range = TextRange.create(1, 3);
  assertEquals(1, escaper.getOffsetInHost(0, range));
  assertEquals(3, escaper.getOffsetInHost(1, range));
  assertEquals(-1, escaper.getOffsetInHost(2, range));
}
项目:js-graphql-intellij-plugin    文件:JSGraphQLTemplateFragmentPsiElement.java   
@NotNull
@Override
public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() {
    return new JSStringLiteralEscaper<PsiLanguageInjectionHost>(this) {
        @Override
        protected boolean isRegExpLiteral() {
            return false;
        }
    };
}
项目:AppleScript-IDEA    文件:AppleScriptStringLiteralExpressionBase.java   
@NotNull
@Override
public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() {
  return new StringLiteralEscaper(this);
}
项目:hybris-integration-intellij-idea-plugin    文件:ImpexStringMixin.java   
@NotNull
@Override
public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() {
    return LiteralTextEscaper.createSimple(this);
}
项目:intellij-neos    文件:FusionValueDslContentImplMixin.java   
@NotNull
@Override
public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() {
    return new FusionDslTextEscaper(this);
}
项目:intellij-ce-playground    文件:PsiCommentImpl.java   
@Override
@NotNull
public LiteralTextEscaper<PsiCommentImpl> createLiteralTextEscaper() {
  return new CommentLiteralEscaper(this);
}
项目:intellij-ce-playground    文件:LeafPatcher.java   
LeafPatcher(Place shreds, List<LiteralTextEscaper<? extends PsiLanguageInjectionHost>> escapers) {
  myShreds = shreds;
  myEscapers = escapers;
}
项目:intellij-ce-playground    文件:GrStringContentImpl.java   
@NotNull
@Override
public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() {
  return new GrLiteralEscaper(this);
}
项目:intellij-ce-playground    文件:GrRegexImpl.java   
@NotNull
@Override
public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() {
  return new GrLiteralEscaper(this);
}
项目:idea-jflex    文件:JFlexJavaCodeImpl.java   
@NotNull
public LiteralTextEscaper<JFlexJavaCode> createLiteralTextEscaper() {
    return new EmbeddedJavaLiteralTextEscaper(this);
}
项目:consulo-unity3d    文件:ShaderCGScript.java   
@NotNull
@Override
public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper()
{
    return LiteralTextEscaper.createSimple(this);
}
项目:tools-idea    文件:PsiCommentImpl.java   
@Override
@NotNull
public LiteralTextEscaper<PsiCommentImpl> createLiteralTextEscaper() {
  return new CommentLiteralEscaper(this);
}
项目:tools-idea    文件:LeafPatcher.java   
LeafPatcher(Place shreds, List<LiteralTextEscaper<? extends PsiLanguageInjectionHost>> escapers) {
  myShreds = shreds;
  myEscapers = escapers;
}
项目:tools-idea    文件:GrStringContentImpl.java   
@NotNull
@Override
public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() {
  return new GrLiteralEscaper(this);
}
项目:tools-idea    文件:GrStringImpl.java   
@NotNull
@Override
public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() {
  return new GrLiteralEscaper(this);
}
项目:tools-idea    文件:GrRegexImpl.java   
@NotNull
@Override
public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() {
  return null;
}
项目:consulo    文件:PsiCommentImpl.java   
@Override
@Nonnull
public LiteralTextEscaper<PsiCommentImpl> createLiteralTextEscaper() {
  return new CommentLiteralEscaper(this);
}
项目:consulo-xml    文件:XmlAttributeValueImpl.java   
@Override
@NotNull
public LiteralTextEscaper<XmlAttributeValueImpl> createLiteralTextEscaper() {
  return new XmlAttributeLiteralEscaper(this);
}
项目:consulo-xml    文件:XmlTextImpl.java   
@Override
@NotNull
public LiteralTextEscaper<XmlTextImpl> createLiteralTextEscaper()
{
    return new XmlTextLiteralEscaper(this);
}
项目:consulo-javascript    文件:JSLiteralExpressionImpl.java   
@NotNull
@Override
public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper()
{
    return LiteralTextEscaper.createSimple(this);
}