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)); }
@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(); } }
@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); }
@NotNull @Override public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() { return new JSStringLiteralEscaper<PsiLanguageInjectionHost>(this) { @Override protected boolean isRegExpLiteral() { return false; } }; }
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)); }
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)); }
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)); }
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)); }
@NotNull @Override public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() { return new StringLiteralEscaper(this); }
@NotNull @Override public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() { return LiteralTextEscaper.createSimple(this); }
@NotNull @Override public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() { return new FusionDslTextEscaper(this); }
@Override @NotNull public LiteralTextEscaper<PsiCommentImpl> createLiteralTextEscaper() { return new CommentLiteralEscaper(this); }
LeafPatcher(Place shreds, List<LiteralTextEscaper<? extends PsiLanguageInjectionHost>> escapers) { myShreds = shreds; myEscapers = escapers; }
@NotNull @Override public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() { return new GrLiteralEscaper(this); }
@NotNull public LiteralTextEscaper<JFlexJavaCode> createLiteralTextEscaper() { return new EmbeddedJavaLiteralTextEscaper(this); }
@NotNull @Override public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() { return null; }
@Override @Nonnull public LiteralTextEscaper<PsiCommentImpl> createLiteralTextEscaper() { return new CommentLiteralEscaper(this); }
@Override @NotNull public LiteralTextEscaper<XmlAttributeValueImpl> createLiteralTextEscaper() { return new XmlAttributeLiteralEscaper(this); }
@Override @NotNull public LiteralTextEscaper<XmlTextImpl> createLiteralTextEscaper() { return new XmlTextLiteralEscaper(this); }