package org.jetbrains.plugins.groovy.lang.resolve;

import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.AbstractElementManipulator;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;

public class GroovyStringLiteralManipulator extends AbstractElementManipulator<GrLiteral> {
  public GrLiteral handleContentChange(GrLiteral expr, TextRange range, String newContent) throws IncorrectOperationException {
    if (!(expr.getValue() instanceof String)) throw new IncorrectOperationException("cannot handle content change");
    String oldText = expr.getText();
    newContent = StringUtil.escapeStringCharacters(newContent);
    String newText = oldText.substring(0, range.getStartOffset()) + newContent + oldText.substring(range.getEndOffset());
    final GrExpression newExpr = GroovyPsiElementFactory.getInstance(expr.getProject()).createExpressionFromText(newText);
    return (GrLiteral)expr.replace(newExpr);
  }

  public TextRange getRangeInElement(final GrLiteral element) {
    return new TextRange(1, Math.max(1, element.getTextLength() - 1));
  }
}
@@ -241,24 +241,94 @@
 nException;%0A
+import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;%0A
 import org.j
@@ -496,78 +496,8 @@
 ral;
-%0Aimport org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
 %0A%0Apu
@@ -1291,16 +1291,210 @@
 ment) %7B%0A
+    final String text = element.getText();%0A    if (text.length() %3E 6 && text.startsWith(%22%5C%22%5C%22%5C%22%22) && text.endsWith(%22%5C%22%5C%22%5C%22%22)) %7B%0A      return new TextRange(3, element.getTextLength() - 3);%0A    %7D%0A
     retu

support multiline literals