<commit_before>package com.bkahlert.nebula.information;

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

import org.apache.log4j.Logger;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.text.AbstractInformationControl;
import org.eclipse.jface.text.IInformationControlExtension2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.menus.IMenuService;

import com.bkahlert.nebula.SourceProvider;
import com.bkahlert.nebula.information.extender.IInformationControlExtender;

/**
 * This is a typed version of the {@link IInformationControlExtension2}.<br>
 * Instead of having to override
 * {@link IInformationControlExtension2#setInput(Object)} you have to override
 * {@link #load(Object)} that returns a boolean whether to show information or
 * not.
 * <p>
 * <strong>Make sure to override
 * {@link #getInformationPresenterControlCreator()} if you want to allow the
 * user to hover the popup and get an enhanced version.</strong>
 * <p>
 * Using the {@link IInformationControlExtender}s {@link InformationControl}s
 * can be extended.
 * 
 * @author bkahlert
 * 
 * @param <INFORMATION>
 */
public abstract class InformationControl<INFORMATION> extends
		AbstractInformationControl implements IInformationControlExtension2 {

	private static final Logger LOGGER = Logger
			.getLogger(InformationControl.class);

	@SuppressWarnings("unchecked")
	protected static <INFORMATION> List<IInformationControlExtender<INFORMATION>> getExtenders(
			ClassLoader classLoader, Class<INFORMATION> targetInformationClass) {
		IConfigurationElement[] config = Platform.getExtensionRegistry()
				.getConfigurationElementsFor("com.bkahlert.nebula.information");
		final List<IInformationControlExtender<INFORMATION>> extenders = new ArrayList<IInformationControlExtender<INFORMATION>>();
		for (IConfigurationElement configElement : config) {
			try {
				Object instance = configElement
						.createExecutableExtension("extenderClass");
				if (instance instanceof IInformationControlExtender<?>) {
					IInformationControlExtender<?> extender = (IInformationControlExtender<?>) instance;
					Class<?> informationClass = extender.getInformationClass();

					boolean sameClass = informationClass == targetInformationClass;
					if (!sameClass) {
						boolean sameClassByForeignClassLoader = false;
						if (classLoader != null) {
							try {
								sameClassByForeignClassLoader = classLoader
										.loadClass(informationClass.getName()) == targetInformationClass;
							} catch (ClassNotFoundException e) {
							}
						}
						if (!sameClassByForeignClassLoader) {
							boolean sameClassByOwnClassLoader = false;
							try {
								sameClassByOwnClassLoader = Class
										.forName(informationClass.getName()) == targetInformationClass;
							} catch (ClassNotFoundException e) {
							}
							if (!sameClassByOwnClassLoader) {
								LOGGER.warn(IInformationControlExtender.class
										.getSimpleName()
										+ " for type "
										+ extender.getInformationClass()
												.getSimpleName()
										+ " is not compatible with "
										+ targetInformationClass
												.getSimpleName());
								continue;
							}
						}
					}

					try {
						extenders
								.add((IInformationControlExtender<INFORMATION>) extender);
					} catch (ClassCastException ex) {
						LOGGER.error(
								IInformationControlExtender.class
										.getSimpleName()
										+ " could not be cast.", ex);
					}
				}
			} catch (CoreException e2) {
				LOGGER.error("Error instantiating "
						+ configElement.getAttribute("extenderClass"));
			}
		}
		return extenders;
	}

	private ClassLoader extenderInformationClassLoader;<commit_msg>[LOG]<commit_after>package com.bkahlert.nebula.information;

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

import org.apache.log4j.Logger;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.text.AbstractInformationControl;
import org.eclipse.jface.text.IInformationControlExtension2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.menus.IMenuService;

import com.bkahlert.nebula.SourceProvider;
import com.bkahlert.nebula.information.extender.IInformationControlExtender;

/**
 * This is a typed version of the {@link IInformationControlExtension2}.<br>
 * Instead of having to override
 * {@link IInformationControlExtension2#setInput(Object)} you have to override
 * {@link #load(Object)} that returns a boolean whether to show information or
 * not.
 * <p>
 * <strong>Make sure to override
 * {@link #getInformationPresenterControlCreator()} if you want to allow the
 * user to hover the popup and get an enhanced version.</strong>
 * <p>
 * Using the {@link IInformationControlExtender}s {@link InformationControl}s
 * can be extended.
 * 
 * @author bkahlert
 * 
 * @param <INFORMATION>
 */
public abstract class InformationControl<INFORMATION> extends
		AbstractInformationControl implements IInformationControlExtension2 {

	private static final Logger LOGGER = Logger
			.getLogger(InformationControl.class);

	@SuppressWarnings("unchecked")
	protected static <INFORMATION> List<IInformationControlExtender<INFORMATION>> getExtenders(
			ClassLoader classLoader, Class<INFORMATION> targetInformationClass) {
		IConfigurationElement[] config = Platform.getExtensionRegistry()
				.getConfigurationElementsFor("com.bkahlert.nebula.information");
		final List<IInformationControlExtender<INFORMATION>> extenders = new ArrayList<IInformationControlExtender<INFORMATION>>();
		for (IConfigurationElement configElement : config) {
			try {
				Object instance = configElement
						.createExecutableExtension("extenderClass");
				if (instance instanceof IInformationControlExtender<?>) {
					IInformationControlExtender<?> extender = (IInformationControlExtender<?>) instance;
					Class<?> informationClass = extender.getInformationClass();

					boolean sameClass = informationClass == targetInformationClass;
					if (!sameClass) {
						boolean sameClassByForeignClassLoader = false;
						if (classLoader != null) {
							try {
								sameClassByForeignClassLoader = classLoader
										.loadClass(informationClass.getName()) == targetInformationClass;
							} catch (ClassNotFoundException e) {
							}
						}
						if (!sameClassByForeignClassLoader) {
							boolean sameClassByOwnClassLoader = false;
							try {
								sameClassByOwnClassLoader = Class
										.forName(informationClass.getName()) == targetInformationClass;
							} catch (ClassNotFoundException e) {
								LOGGER.error(e);
							}
							if (!sameClassByOwnClassLoader) {
								LOGGER.info(IInformationControlExtender.class
										.getSimpleName()
										+ " for type "
										+ extender.getInformationClass()
												.getSimpleName()
										+ " is not compatible with "
										+ targetInformationClass
												.getSimpleName());
								continue;
							}
						}
					}

					try {
						extenders
								.add((IInformationControlExtender<INFORMATION>) extender);
					} catch (ClassCastException ex) {
						LOGGER.error(
								IInformationControlExtender.class
										.getSimpleName()
										+ " could not be cast.", ex);
					}
				}
			} catch (CoreException e2) {
				LOGGER.error("Error instantiating "
						+ configElement.getAttribute("extenderClass"));
			}
		}
		return extenders;
	}

	private ClassLoader extenderInformationClassLoader;
{'fraction_non_alphanumeric': 0.09500549517645622, 'fraction_numerical': 0.001465380388325803, 'mean_word_length': 3.9847839318320144, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2401835', 'n_tokens_mistral': 2842, 'n_tokens_neox': 2189, 'n_words': 474}