void (@NotNull PsiElement element, @NotNull ActionContext context, @NotNull ModPsiUpdater updater) { if (!(element instanceof GrLiteral)) return; StringBuilder buffer = new StringBuilder(); buffer.append("/"); if (GrStringUtil.isDollarSlashyString(((GrLiteral)element))) { buffer.append(GrStringUtil.removeQuotes(element.getText())); } else if (element instanceof GrLiteralImpl) { Object value = ((GrLiteralImpl)element).getValue(); if (value instanceof String) { GrStringUtil.escapeSymbolsForSlashyStrings(buffer, (String)value); } else { String rawText = GrStringUtil.removeQuotes(element.getText()); unescapeAndAppend(buffer, rawText); } } else if (element instanceof GrString) { for (PsiElement part : ((GrString)element).getAllContentParts()) { if (part instanceof GrStringContent) { unescapeAndAppend(buffer, part.getText()); } else if (part instanceof GrStringInjection) { buffer.append(part.getText()); } } } buffer.append("/"); GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(context.project()); GrExpression regex = factory.createExpressionFromText(buffer); element.replace(regex); //don't use replaceWithExpression since it can revert regex to string if regex brakes syntax }