private static String escapeForContext(String text, PsiFile file) {
    final InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(file.getProject());
    if (injectedLanguageManager.isInjectedFragment(file)) {
      final PsiElement context = file.getContext();
      final ElementManipulator<PsiElement> manipulator = context == null ? null : ElementManipulators.getManipulator(context);
      if (manipulator != null) {
        // use element manipulator to process escape sequences correctly for all supported languages
        final PsiElement copy = context.copy(); // create a copy to avoid original element modifications
        final PsiElement newElement = manipulator.handleContentChange(copy, DUMMY + text);
        if (newElement != null) {
          final String newElementText = newElement.getText();
          final TextRange newRange = manipulator.getRangeInElement(newElement);
          return newElementText.substring(newRange.getStartOffset() + DUMMY.length(), newRange.getEndOffset());
        }
      }
      if (RegExpElementImpl.isLiteralExpression(context)) {
        // otherwise, just pretend it is a Java-style string
        return StringUtil.escapeStringCharacters(text);
      }
      else if (context instanceof XmlElement) {
        return XmlStringUtil.escapeString(text);
      }
    }
    return text;
  }
private static String escapeForContext(String text, PsiFile file)