<commit_before>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Created by IntelliJ IDEA.
 * User: cdr
 * Date: Sep 4, 2007
 * Time: 7:17:07 PM
 */
package com.intellij.psi.impl.source.tree.injected;

import com.intellij.lang.ASTNode;
import com.intellij.lang.Language;
import com.intellij.lang.StdLanguages;
import com.intellij.lang.injection.ConcatenationAwareInjector;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.lang.injection.MultiHostInjector;
import com.intellij.lang.injection.MultiHostRegistrar;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.extensions.ExtensionPoint;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.ProperTextRange;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.tree.PsiCommentImpl;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.xml.*;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;

import java.util.Arrays;
import java.util.List;

public class MyTestInjector {
  private final PsiManager myPsiManager;

  @TestOnly
  public MyTestInjector(PsiManager psiManager) {
    myPsiManager = psiManager;
  }

  public void injectAll(Disposable parent) {
    injectVariousStuffEverywhere(parent, myPsiManager);

    Project project = myPsiManager.getProject();
    Language ql = Language.findLanguageByID("JPAQL");
    Language js = Language.findLanguageByID("JavaScript");
    registerForStringVarInitializer(parent, project, ql, "ql", null, null);
    registerForStringVarInitializer(parent, project, ql, "qlPrefixed", "xxx", null);
    registerForStringVarInitializer(parent, project, js, "js", null, null);
    registerForStringVarInitializer(parent, project, js, "jsSeparated", " + ", " + 'separator'");
    registerForStringVarInitializer(parent, project, js, "jsBrokenPrefix", "xx ", "");
    registerForParameterValue(parent, project, Language.findLanguageByID("Groovy"), "groovy");
  }

  private static void registerForParameterValue(Disposable parent, final Project project, final Language language, final String paramName) {
    if (language == null) return;
    final ConcatenationAwareInjector injector = new ConcatenationAwareInjector() {
      @Override
      public void getLanguagesToInject(@NotNull MultiHostRegistrar injectionPlacesRegistrar, @NotNull PsiElement... operands) {
        PsiElement operand = operands[0];
        if (!(operand instanceof PsiLiteralExpression)) return;
        if (!(operand.getParent() instanceof PsiExpressionList)) return;
        PsiExpressionList expressionList = (PsiExpressionList)operand.getParent();
        int i = ArrayUtil.indexOf(expressionList.getExpressions(), operand);
        if (!(operand.getParent().getParent() instanceof PsiMethodCallExpression)) return;
        PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)operand.getParent().getParent();
        PsiMethod method = methodCallExpression.resolveMethod();
        if (method == null) return;<commit_msg>a test for IDEA-100653 Language injection: AE at CodeCompletionHandlerBase$WatchingInsertionContext.setTailOffset() on inserting not escaped character by completion<commit_after>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Created by IntelliJ IDEA.
 * User: cdr
 * Date: Sep 4, 2007
 * Time: 7:17:07 PM
 */
package com.intellij.psi.impl.source.tree.injected;

import com.intellij.lang.ASTNode;
import com.intellij.lang.Language;
import com.intellij.lang.StdLanguages;
import com.intellij.lang.injection.ConcatenationAwareInjector;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.lang.injection.MultiHostInjector;
import com.intellij.lang.injection.MultiHostRegistrar;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.extensions.ExtensionPoint;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.ProperTextRange;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.tree.PsiCommentImpl;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.xml.*;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;

import java.util.Arrays;
import java.util.List;

public class MyTestInjector {
  private final PsiManager myPsiManager;

  @TestOnly
  public MyTestInjector(PsiManager psiManager) {
    myPsiManager = psiManager;
  }

  public void injectAll(Disposable parent) {
    injectVariousStuffEverywhere(parent, myPsiManager);

    Project project = myPsiManager.getProject();
    Language ql = Language.findLanguageByID("JPAQL");
    Language js = Language.findLanguageByID("JavaScript");
    registerForStringVarInitializer(parent, project, ql, "ql", null, null);
    registerForStringVarInitializer(parent, project, ql, "qlPrefixed", "xxx", null);
    registerForStringVarInitializer(parent, project, js, "js", null, null);
    registerForStringVarInitializer(parent, project, js, "jsSeparated", " + ", " + 'separator'");
    registerForStringVarInitializer(parent, project, js, "jsBrokenPrefix", "xx ", "");

    registerForStringVarInitializer(parent, project, Language.findLanguageByID("Oracle"), "oracle", null, null);

    registerForParameterValue(parent, project, Language.findLanguageByID("Groovy"), "groovy");
  }

  private static void registerForParameterValue(Disposable parent, final Project project, final Language language, final String paramName) {
    if (language == null) return;
    final ConcatenationAwareInjector injector = new ConcatenationAwareInjector() {
      @Override
      public void getLanguagesToInject(@NotNull MultiHostRegistrar injectionPlacesRegistrar, @NotNull PsiElement... operands) {
        PsiElement operand = operands[0];
        if (!(operand instanceof PsiLiteralExpression)) return;
        if (!(operand.getParent() instanceof PsiExpressionList)) return;
        PsiExpressionList expressionList = (PsiExpressionList)operand.getParent();
        int i = ArrayUtil.indexOf(expressionList.getExpressions(), operand);
        if (!(operand.getParent().getParent() instanceof PsiMethodCallExpression)) return;
        PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)operand.getParent().getParent();
        PsiMethod method = methodCallExpression.resolveMethod();
        if (method == null) return;
{'fraction_non_alphanumeric': 0.10082665330661322, 'fraction_numerical': 0.006513026052104208, 'mean_word_length': 5.175560711523588, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4558821', 'n_tokens_mistral': 2372, 'n_tokens_neox': 2298, 'n_words': 570}