use of com.jetbrains.python.psi.PyStringLiteralExpression in project intellij-community by JetBrains.
the class PyFunctionElementType method createStub.
@NotNull
public PyFunctionStub createStub(@NotNull final PyFunction psi, final StubElement parentStub) {
PyFunctionImpl function = (PyFunctionImpl) psi;
String message = function.extractDeprecationMessage();
final PyStringLiteralExpression docStringExpression = function.getDocStringExpression();
final String typeComment = function.getTypeCommentAnnotation();
return new PyFunctionStubImpl(psi.getName(), PyPsiUtils.strValue(docStringExpression), message, function.isAsync(), typeComment, parentStub, getStubElementType());
}
use of com.jetbrains.python.psi.PyStringLiteralExpression in project intellij-community by JetBrains.
the class PyStringLiteralTest method testEscaperDecode.
public void testEscaperDecode() {
final PyStringLiteralExpression expr = createLiteralFromText("'\\nfoo'");
assertNotNull(expr);
assertEquals("fo", decodeRange(expr, TextRange.create(3, 5)));
assertEquals("\n", decodeRange(expr, TextRange.create(1, 3)));
}
use of com.jetbrains.python.psi.PyStringLiteralExpression 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.jetbrains.python.psi.PyStringLiteralExpression 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.jetbrains.python.psi.PyStringLiteralExpression 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