<commit_before>// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.actions;

import com.intellij.execution.*;
import com.intellij.execution.configurations.ConfigurationFactory;
import com.intellij.execution.configurations.ConfigurationType;
import com.intellij.execution.configurations.ConfigurationTypeUtil;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

/**
 * Supports creating run configurations from context (by right-clicking a code element in the source editor or the project view). Typically,
 * run configurations that can be created from context should extend the {@link com.intellij.execution.configurations.LocatableConfigurationBase} class.
 * @author yole
 */
public abstract class RunConfigurationProducer<T extends RunConfiguration> {
  public static final ExtensionPointName<RunConfigurationProducer> EP_NAME = ExtensionPointName.create("com.intellij.runConfigurationProducer");
  private static final Logger LOG = Logger.getInstance(RunConfigurationProducer.class);

  @NotNull
  public static List<RunConfigurationProducer<?>> getProducers(@NotNull Project project) {
    RunConfigurationProducerService runConfigurationProducerService = RunConfigurationProducerService.getInstance(project);
    List<RunConfigurationProducer> allProducers = EP_NAME.getExtensionList();
    List<RunConfigurationProducer<?>> result = new ArrayList<>(allProducers.size());
    for (RunConfigurationProducer producer : allProducers) {
      if (!runConfigurationProducerService.isIgnored(producer)) {
        result.add(producer);
      }
    }
    return result;
  }

  private final ConfigurationFactory myConfigurationFactory;

  /**
   * @deprecated Use {@link LazyRunConfigurationProducer}.
   */
  @Deprecated
  protected RunConfigurationProducer(@NotNull ConfigurationFactory configurationFactory) {
    myConfigurationFactory = configurationFactory;
  }

  /**
   * @deprecated Use {@link LazyRunConfigurationProducer}.
   */
  @Deprecated
  protected RunConfigurationProducer(@NotNull Class<? extends ConfigurationType> type) {
    this(ConfigurationTypeUtil.findConfigurationType(type));
  }

  /**
   * Do NOT use directly.
   */
  public RunConfigurationProducer(@SuppressWarnings("unused") boolean internalUsageOnly) {
    myConfigurationFactory = null;
  }

  /**
   * @deprecated Use {@link LazyRunConfigurationProducer}.
   */
  @Deprecated
  protected RunConfigurationProducer(@NotNull ConfigurationType configurationType) {
    myConfigurationFactory = configurationType.getConfigurationFactories()[0];
  }

  @NotNull
  public ConfigurationFactory getConfigurationFactory() {
    return myConfigurationFactory;
  }

  @NotNull
  public final ConfigurationType getConfigurationType() {
    return getConfigurationFactory().getType();
  }

  /**
   * Creates a run configuration from the context.
   *
   * @param context contains the information about a location in the source code.
   * @return a container with a prepared run configuration and the context element from which it was created, or null if the context is
   * not applicable to this run configuration producer.
   */
  @Nullable
  public ConfigurationFromContext createConfigurationFromContext(@NotNull ConfigurationContext context) {
    final RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(context);
    Ref<PsiElement> ref = new Ref<>(context.getPsiLocation());
    try {
      //noinspection unchecked
      if (!setupConfigurationFromContext((T)settings.getConfiguration(), context, ref)) {
       return null;
     }
    }
    catch (ClassCastException e) {
      LOG.error(getConfigurationFactory() + " produced wrong type", e);
      return null;
    }
    return new ConfigurationFromContextImpl(this, settings, ref.get());
  }

  /**
   * Sets up a configuration based on the specified context.
   *
   * @param configuration a clone of the template run configuration of the specified type
   * @param context       contains the information about a location in the source code.
   * @param sourceElement a reference to the source element for the run configuration (by default contains the element at caret,
   *                      can be updated by the producer to point to a higher-level element in the tree).
   * @return true if the context is applicable to this run configuration producer, false if the context is not applicable and the
   * configuration should be discarded.
   */
  protected abstract boolean setupConfigurationFromContext(@NotNull T configuration,
                                                           @NotNull ConfigurationContext context,
                                                           @NotNull Ref<PsiElement> sourceElement);

  /**
   * Checks if the specified configuration was created from the specified context.
   *
   * @param configuration a configuration instance.
   * @param context       contains the information about a location in the source code.
   * @return true if this configuration was created from the specified context, false otherwise.
   */
  public abstract boolean isConfigurationFromContext(@NotNull T configuration, @NotNull ConfigurationContext context);
<commit_msg>log producer throwable to keep others work<commit_after>// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.actions;

import com.intellij.execution.*;
import com.intellij.execution.configurations.ConfigurationFactory;
import com.intellij.execution.configurations.ConfigurationType;
import com.intellij.execution.configurations.ConfigurationTypeUtil;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

/**
 * Supports creating run configurations from context (by right-clicking a code element in the source editor or the project view). Typically,
 * run configurations that can be created from context should extend the {@link com.intellij.execution.configurations.LocatableConfigurationBase} class.
 * @author yole
 */
public abstract class RunConfigurationProducer<T extends RunConfiguration> {
  public static final ExtensionPointName<RunConfigurationProducer> EP_NAME = ExtensionPointName.create("com.intellij.runConfigurationProducer");
  private static final Logger LOG = Logger.getInstance(RunConfigurationProducer.class);

  @NotNull
  public static List<RunConfigurationProducer<?>> getProducers(@NotNull Project project) {
    RunConfigurationProducerService runConfigurationProducerService = RunConfigurationProducerService.getInstance(project);
    List<RunConfigurationProducer> allProducers = EP_NAME.getExtensionList();
    List<RunConfigurationProducer<?>> result = new ArrayList<>(allProducers.size());
    for (RunConfigurationProducer producer : allProducers) {
      if (!runConfigurationProducerService.isIgnored(producer)) {
        result.add(producer);
      }
    }
    return result;
  }

  private final ConfigurationFactory myConfigurationFactory;

  /**
   * @deprecated Use {@link LazyRunConfigurationProducer}.
   */
  @Deprecated
  protected RunConfigurationProducer(@NotNull ConfigurationFactory configurationFactory) {
    myConfigurationFactory = configurationFactory;
  }

  /**
   * @deprecated Use {@link LazyRunConfigurationProducer}.
   */
  @Deprecated
  protected RunConfigurationProducer(@NotNull Class<? extends ConfigurationType> type) {
    this(ConfigurationTypeUtil.findConfigurationType(type));
  }

  /**
   * Do NOT use directly.
   */
  public RunConfigurationProducer(@SuppressWarnings("unused") boolean internalUsageOnly) {
    myConfigurationFactory = null;
  }

  /**
   * @deprecated Use {@link LazyRunConfigurationProducer}.
   */
  @Deprecated
  protected RunConfigurationProducer(@NotNull ConfigurationType configurationType) {
    myConfigurationFactory = configurationType.getConfigurationFactories()[0];
  }

  @NotNull
  public ConfigurationFactory getConfigurationFactory() {
    return myConfigurationFactory;
  }

  @NotNull
  public final ConfigurationType getConfigurationType() {
    return getConfigurationFactory().getType();
  }

  /**
   * Creates a run configuration from the context.
   *
   * @param context contains the information about a location in the source code.
   * @return a container with a prepared run configuration and the context element from which it was created, or null if the context is
   * not applicable to this run configuration producer.
   */
  @Nullable
  public ConfigurationFromContext createConfigurationFromContext(@NotNull ConfigurationContext context) {
    final RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(context);
    Ref<PsiElement> ref = new Ref<>(context.getPsiLocation());
    try {
      //noinspection unchecked
      if (!setupConfigurationFromContext((T)settings.getConfiguration(), context, ref)) {
       return null;
     }
    }
    catch (ClassCastException e) {
      LOG.error(getConfigurationFactory() + " produced wrong type", e);
      return null;
    }
    catch (ProcessCanceledException e) {
      throw e;
    }
    catch (Throwable e) {
      LOG.error(e);
      return null;
    }
    return new ConfigurationFromContextImpl(this, settings, ref.get());
  }

  /**
   * Sets up a configuration based on the specified context.
   *
   * @param configuration a clone of the template run configuration of the specified type
   * @param context       contains the information about a location in the source code.
   * @param sourceElement a reference to the source element for the run configuration (by default contains the element at caret,
   *                      can be updated by the producer to point to a higher-level element in the tree).
   * @return true if the context is applicable to this run configuration producer, false if the context is not applicable and the
   * configuration should be discarded.
   */
  protected abstract boolean setupConfigurationFromContext(@NotNull T configuration,
                                                           @NotNull ConfigurationContext context,
                                                           @NotNull Ref<PsiElement> sourceElement);

  /**
   * Checks if the specified configuration was created from the specified context.
   *
   * @param configuration a configuration instance.
   * @param context       contains the information about a location in the source code.
   * @return true if this configuration was created from the specified context, false otherwise.
   */
  public abstract boolean isConfigurationFromContext(@NotNull T configuration, @NotNull ConfigurationContext context);

{'fraction_non_alphanumeric': 0.07447813761704321, 'fraction_numerical': 0.0018898720041233572, 'mean_word_length': 4.144498453380469, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3637234', 'n_tokens_mistral': 2794, 'n_tokens_neox': 2735, 'n_words': 899}