Search in sources :

Example 6 with GoStringLiteral

use of com.goide.psi.GoStringLiteral in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoStringLiteralEscaperTest method testDecodeHexCharString.

public void testDecodeHexCharString() {
    GoStringLiteral expr = createStringFromText("\\x41");
    assertNotNull(expr);
    String a = decodeRange(expr, TextRange.create(1, 5));
    assertEquals("A", a);
}
Also used : GoStringLiteral(com.goide.psi.GoStringLiteral)

Example 7 with GoStringLiteral

use of com.goide.psi.GoStringLiteral in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoConvertStringToByteQuickFix method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement element = descriptor.getPsiElement();
    if (!(element instanceof GoConditionalExpr) || !element.isValid()) {
        return;
    }
    GoConditionalExpr expr = (GoConditionalExpr) element;
    GoStringLiteral literal = ContainerUtil.findInstance(Arrays.asList(expr.getLeft(), expr.getRight()), GoStringLiteral.class);
    if (literal == null || !isSingleCharLiteral(literal)) {
        return;
    }
    literal.replace(createExpression(project, extractSingleCharFromText(literal)));
}
Also used : GoConditionalExpr(com.goide.psi.GoConditionalExpr) GoStringLiteral(com.goide.psi.GoStringLiteral) PsiElement(com.intellij.psi.PsiElement)

Example 8 with GoStringLiteral

use of com.goide.psi.GoStringLiteral in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoStringLiteralEscaperTest method testDecodeShortUnicodeCharString.

public void testDecodeShortUnicodeCharString() {
    GoStringLiteral expr = createStringFromText("\\u8a9e");
    assertNotNull(expr);
    String a = decodeRange(expr, TextRange.create(1, 7));
    assertEquals("語", a);
}
Also used : GoStringLiteral(com.goide.psi.GoStringLiteral)

Example 9 with GoStringLiteral

use of com.goide.psi.GoStringLiteral in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoStringLiteralEscaperTest method testDecodeEscapedString.

// region decode tests
public void testDecodeEscapedString() {
    GoStringLiteral expr = createStringFromText("\\t\\n\\b");
    assertNotNull(expr);
    String a = decodeRange(expr, TextRange.create(1, 7));
    assertEquals("\t\n\b", a);
}
Also used : GoStringLiteral(com.goide.psi.GoStringLiteral)

Example 10 with GoStringLiteral

use of com.goide.psi.GoStringLiteral in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoStringLiteralEscaperTest method testEscaperOffsetInStringHostSubString.

public void testEscaperOffsetInStringHostSubString() {
    GoStringLiteral expr = createStringFromText("\\nfoo");
    assertNotNull(expr);
    LiteralTextEscaper<? extends PsiLanguageInjectionHost> escaper = expr.createLiteralTextEscaper();
    TextRange fooOnly = TextRange.create(3, 6);
    escaper.decode(fooOnly, new StringBuilder());
    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 : GoStringLiteral(com.goide.psi.GoStringLiteral) TextRange(com.intellij.openapi.util.TextRange)

Aggregations

GoStringLiteral (com.goide.psi.GoStringLiteral)16 TextRange (com.intellij.openapi.util.TextRange)5 GoConditionalExpr (com.goide.psi.GoConditionalExpr)1 PsiElement (com.intellij.psi.PsiElement)1