GrString (GrStringInjection injection, GrLiteral literal) { GrString grString = (GrString)injection.getParent(); final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(grString.getProject()); String literalText; //wrap last injection in inserted literal if it needed // e.g.: "bla bla ${foo}bla bla" and {foo} is replaced if (literal instanceof GrString) { final GrStringInjection[] injections = ((GrString)literal).getInjections(); if (injections.length > 0) { GrStringInjection last = injections[injections.length - 1]; if (last.getExpression() != null) { if (!checkBraceIsUnnecessary(last.getExpression(), injection.getNextSibling())) { wrapInjection(last); } } } literalText = removeQuotes(literal.getText()); } else { final String text = removeQuotes(literal.getText()); boolean escapeDoubleQuotes = !text.contains("\n") && grString.isPlainString(); literalText = escapeSymbolsForGString(text, escapeDoubleQuotes, true); } if (literalText.contains("\n")) { wrapGStringInto(grString, TRIPLE_DOUBLE_QUOTES); } final GrExpression expression = factory.createExpressionFromText("\"\"\"${}" + literalText + "\"\"\""); expression.getFirstChild().delete();//quote expression.getFirstChild().delete();//empty injection final ASTNode node = grString.getNode(); if (expression.getFirstChild() != null) { if (expression.getFirstChild() == expression.getLastChild()) { node.replaceChild(injection.getNode(), expression.getFirstChild().getNode()); } else { node.addChildren(expression.getFirstChild().getNode(), expression.getLastChild().getNode(), injection.getNode()); node.removeChild(injection.getNode()); } } return grString; }