String (final GrLiteral literal) { final String text = literal.getText(); final String quote = GrStringUtil.getStartQuote(text); final String value = GrStringUtil.removeQuotes(text); final StringBuilder buffer = new StringBuilder(); buffer.append(quote); switch (quote) { case "'" -> GrStringUtil.escapeAndUnescapeSymbols(value, "", "\"$", buffer); case "'''" -> { int position = buffer.length(); GrStringUtil.escapeAndUnescapeSymbols(value, "", "\"'$n", buffer); GrStringUtil.fixAllTripleQuotes(buffer, position); } case "\"" -> { if (literal instanceof GrString) { final ASTNode node = literal.getNode(); for (ASTNode child = node.getFirstChildNode(); child != null; child = child.getTreeNext()) { final IElementType type = child.getElementType(); if (type == GroovyTokenTypes.mGSTRING_BEGIN || type == GroovyTokenTypes.mGSTRING_END) continue; if (type == GroovyElementTypes.GSTRING_INJECTION) { buffer.append(child.getText()); } else { GrStringUtil.escapeAndUnescapeSymbols(child.getText(), "", "'", buffer); } } } else { GrStringUtil.escapeAndUnescapeSymbols(value, "", "'", buffer); } } case "\"\"\"" -> { if (literal instanceof GrString) { final ASTNode node = literal.getNode(); for (ASTNode child = node.getFirstChildNode(); child != null; child = child.getTreeNext()) { final IElementType type = child.getElementType(); if (type == GroovyTokenTypes.mGSTRING_BEGIN || type == GroovyTokenTypes.mGSTRING_END) continue; if (type == GroovyElementTypes.GSTRING_INJECTION) { buffer.append(child.getText()); } else { final int position = buffer.length(); GrStringUtil.escapeAndUnescapeSymbols(child.getText(), "", "\"'n", buffer); GrStringUtil.fixAllTripleDoubleQuotes(buffer, position); } } } else { final int position = buffer.length(); GrStringUtil.escapeAndUnescapeSymbols(value, "", "\"'n", buffer); GrStringUtil.fixAllTripleDoubleQuotes(buffer, position); } } default -> { return text; } } buffer.append(quote); return buffer.toString(); }