use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class PyStringLiteralExpressionImpl method getDecodedFragments.
@Override
@NotNull
public List<Pair<TextRange, String>> getDecodedFragments() {
if (myDecodedFragments == null) {
final List<Pair<TextRange, String>> result = new ArrayList<>();
final int elementStart = getTextRange().getStartOffset();
final boolean unicodeByDefault = isUnicodeByDefault();
for (ASTNode node : getStringNodes()) {
final String text = node.getText();
final TextRange textRange = getNodeTextRange(text);
final int offset = node.getTextRange().getStartOffset() - elementStart + textRange.getStartOffset();
final String encoded = textRange.substring(text);
final boolean hasRawPrefix = PyStringLiteralUtil.isRawPrefix(PyStringLiteralUtil.getPrefix(text));
final boolean hasUnicodePrefix = PyStringLiteralUtil.isUnicodePrefix(PyStringLiteralUtil.getPrefix(text));
result.addAll(getDecodedFragments(encoded, offset, hasRawPrefix, unicodeByDefault || hasUnicodePrefix));
}
myDecodedFragments = result;
}
return myDecodedFragments;
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class PyStringLiteralExpressionImpl method getStringValueTextRanges.
@NotNull
public List<TextRange> getStringValueTextRanges() {
if (valueTextRanges == null) {
int elStart = getTextRange().getStartOffset();
List<TextRange> ranges = new ArrayList<>();
for (ASTNode node : getStringNodes()) {
TextRange range = getNodeTextRange(node.getText());
int nodeOffset = node.getStartOffset() - elStart;
ranges.add(TextRange.from(nodeOffset + range.getStartOffset(), range.getLength()));
}
valueTextRanges = Collections.unmodifiableList(ranges);
}
return valueTextRanges;
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class PyStringLiteralTest method testEscaperOffsetInEscapedBackslash.
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));
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class PyStringLiteralTest method testEscaperOffsetInHostSubString.
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));
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class PyStringLiteralTest method testEscaperOffsetInSingleEscapedCharString.
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));
}
Aggregations