Search in sources :

Example 1 with PyStringLiteralExpression

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());
}
Also used : PyStringLiteralExpression(com.jetbrains.python.psi.PyStringLiteralExpression) PyFunctionImpl(com.jetbrains.python.psi.impl.PyFunctionImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PyStringLiteralExpression

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)));
}
Also used : PyStringLiteralExpression(com.jetbrains.python.psi.PyStringLiteralExpression)

Example 3 with PyStringLiteralExpression

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));
}
Also used : PyStringLiteralExpression(com.jetbrains.python.psi.PyStringLiteralExpression) TextRange(com.intellij.openapi.util.TextRange)

Example 4 with PyStringLiteralExpression

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));
}
Also used : PyStringLiteralExpression(com.jetbrains.python.psi.PyStringLiteralExpression) TextRange(com.intellij.openapi.util.TextRange)

Example 5 with PyStringLiteralExpression

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));
}
Also used : PyStringLiteralExpression(com.jetbrains.python.psi.PyStringLiteralExpression) TextRange(com.intellij.openapi.util.TextRange)

Aggregations

PyStringLiteralExpression (com.jetbrains.python.psi.PyStringLiteralExpression)28 TextRange (com.intellij.openapi.util.TextRange)10 PsiElement (com.intellij.psi.PsiElement)6 NotNull (org.jetbrains.annotations.NotNull)5 ASTNode (com.intellij.lang.ASTNode)4 PyElementGenerator (com.jetbrains.python.psi.PyElementGenerator)4 ArrayList (java.util.ArrayList)3 Nullable (org.jetbrains.annotations.Nullable)3 PsiFile (com.intellij.psi.PsiFile)2 PsiReference (com.intellij.psi.PsiReference)2 UsageInfo (com.intellij.usageView.UsageInfo)2 PyFile (com.jetbrains.python.psi.PyFile)2 PyBlockEvaluator (com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator)2 Map (java.util.Map)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1