@Override
 public void getLanguagesToInject(
     @NotNull final MultiHostRegistrar injectionPlacesRegistrar, @NotNull PsiElement context) {
   final PsiLanguageInjectionHost host = (PsiLanguageInjectionHost) context;
   InjectedLanguagePlaces placesRegistrar =
       (language, rangeInsideHost, prefix, suffix) ->
           injectionPlacesRegistrar
               .startInjecting(language)
               .addPlace(prefix, suffix, host, rangeInsideHost)
               .doneInjecting();
   for (LanguageInjector injector :
       Extensions.getExtensions(LanguageInjector.EXTENSION_POINT_NAME)) {
     injector.getLanguagesToInject(host, placesRegistrar);
   }
 }
 public void getLanguagesToInject(
     @NotNull final MultiHostRegistrar registrar, @NotNull final PsiElement host) {
   Pair<ASTNode, ASTNode> pair = parseConditionalCommentBoundaries(host);
   if (pair == null) {
     return;
   }
   final TextRange textRange = host.getTextRange();
   final int startOffset = textRange.getStartOffset();
   Language language = host.getParent().getLanguage();
   ASTNode conditionalStart = pair.first;
   ASTNode conditionalEnd = pair.second;
   TextRange range =
       new TextRange(
           conditionalStart.getTextRange().getEndOffset() - startOffset,
           conditionalEnd.getStartOffset() - startOffset);
   registrar
       .startInjecting(language)
       .addPlace(null, null, (PsiLanguageInjectionHost) host, range)
       .doneInjecting();
 }
  @Override
  public void getLanguagesToInject(
      @NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) {
    // check that we have angular directives indexed before injecting
    final Project project = context.getProject();
    if (!AngularIndexUtil.hasAngularJS(project)) return;

    final PsiElement parent = context.getParent();
    if (context instanceof XmlAttributeValueImpl && parent instanceof XmlAttribute) {
      final String value = context.getText();
      final int start = value.startsWith("'") || value.startsWith("\"") ? 1 : 0;
      final int end = value.endsWith("'") || value.endsWith("\"") ? 1 : 0;
      final int length = value.length();
      if (AngularAttributesRegistry.isAngularExpressionAttribute((XmlAttribute) parent)
          && length > 1) {
        registrar
            .startInjecting(AngularJSLanguage.INSTANCE)
            .addPlace(
                null, null, (PsiLanguageInjectionHost) context, new TextRange(start, length - end))
            .doneInjecting();
        return;
      }
      if (AngularAttributesRegistry.isJSONAttribute((XmlAttribute) parent) && length > 1) {
        registrar
            .startInjecting(JsonLanguage.INSTANCE)
            .addPlace(
                null, null, (PsiLanguageInjectionHost) context, new TextRange(start, length - end))
            .doneInjecting();
        return;
      }
      if (AngularAttributesRegistry.isEventAttribute(
              ((XmlAttribute) parent).getName(), ((XmlAttribute) parent).getProject())
          && length > 1) {
        registrar
            .startInjecting(JavascriptLanguage.INSTANCE)
            .addPlace(
                null, null, (PsiLanguageInjectionHost) context, new TextRange(start, length - end))
            .doneInjecting();
        return;
      }
    }

    if (context instanceof XmlTextImpl || context instanceof XmlAttributeValueImpl) {
      final String start = AngularJSBracesUtil.getInjectionStart(project);
      final String end = AngularJSBracesUtil.getInjectionEnd(project);

      if (AngularJSBracesUtil.hasConflicts(start, end, context)) return;

      final String text = context.getText();
      int startIndex;
      int endIndex = -1;
      do {
        startIndex = text.indexOf(start, endIndex);
        int afterStart = startIndex + start.length();
        endIndex = startIndex >= 0 ? text.indexOf(end, afterStart) : -1;
        endIndex =
            endIndex > 0 ? endIndex : ElementManipulators.getValueTextRange(context).getEndOffset();
        final PsiElement injectionCandidate =
            startIndex >= 0 ? context.findElementAt(startIndex) : null;
        if (injectionCandidate != null
            && injectionCandidate.getNode().getElementType() != XmlTokenType.XML_COMMENT_CHARACTERS
            && !(injectionCandidate instanceof OuterLanguageElement)) {
          if (afterStart > endIndex) {
            LOG.error(
                "Braces: "
                    + start
                    + ","
                    + end
                    + "\n"
                    + "Text: \""
                    + text
                    + "\""
                    + "\n"
                    + "Interval: ("
                    + afterStart
                    + ","
                    + endIndex
                    + ")"
                    + "\n"
                    + "File: "
                    + context.getContainingFile().getName()
                    + ", language:"
                    + context.getContainingFile().getLanguage());
          }
          registrar
              .startInjecting(AngularJSLanguage.INSTANCE)
              .addPlace(
                  null,
                  null,
                  (PsiLanguageInjectionHost) context,
                  new TextRange(afterStart, endIndex))
              .doneInjecting();
        }
      } while (startIndex >= 0);
    }
  }