<commit_before>/*******************************************************************************
 * Copyright (c) 2007, 2008 <NAME> and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     <NAME> - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylyn.wikitext.core;

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.internal.wikitext.core.util.EclipseServiceLocator;
import org.eclipse.mylyn.internal.wikitext.core.validation.ValidationRules;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;
import org.eclipse.mylyn.wikitext.core.util.ServiceLocator;
import org.eclipse.mylyn.wikitext.core.validation.MarkupValidator;
import org.eclipse.mylyn.wikitext.core.validation.ValidationRule;
import org.osgi.framework.BundleContext;

/**
 * 
 * 
 * @author <NAME>
 */
public class WikiTextPlugin extends Plugin {

	private static final String EXTENSION_MARKUP_LANGUAGE = "markupLanguage"; //$NON-NLS-1$

	private static final String EXTENSION_VALIDATION_RULES = "markupValidationRule"; //$NON-NLS-1$

	private static WikiTextPlugin plugin;

	private SortedMap<String, Class<? extends MarkupLanguage>> languageByName;

	private Map<String, Class<? extends MarkupLanguage>> languageByFileExtension;

	private Map<String, String> languageExtensionByLanguage;

	private Map<String, ValidationRules> validationRulesByLanguageName;

	public WikiTextPlugin() {
	}

	@Override
	public void start(BundleContext context) throws Exception {
		super.start(context);
		ServiceLocator.setImplementation(EclipseServiceLocator.class);
		plugin = this;
	}

	@Override
	public void stop(BundleContext context) throws Exception {
		if (plugin == this) {
			plugin = null;
		}
		super.stop(context);
	}

	public static WikiTextPlugin getDefault() {
		return plugin;
	}

	/**
	 * Get a markup language by name.
	 * 
	 * @param name
	 *            the name of the markup language to retrieve
	 * 
	 * @return the markup language or null if there is no markup language known by the given name
	 * 
	 * @see #getMarkupLanguageNames()
	 */
	public MarkupLanguage getMarkupLanguage(String name) {
		if (languageByName == null) {
			initializeMarkupLanguages();
		}
		Class<? extends MarkupLanguage> languageClass = languageByName.get(name);
		if (languageClass != null) {
			return instantiateMarkupLanguage(name, languageClass);
		}
		return null;
	}

	private MarkupLanguage instantiateMarkupLanguage(String name, Class<? extends MarkupLanguage> languageClass) {
		try {
			MarkupLanguage language = languageClass.newInstance();
			language.setName(name);
			language.setExtendsLanguage(languageExtensionByLanguage.get(name));
			return language;
		} catch (Exception e) {
			log(IStatus.ERROR, MessageFormat.format(Messages.getString("WikiTextPlugin.2"), name, //$NON-NLS-1$
					languageClass.getName(), e.getMessage()), e);
		}
		return null;<commit_msg>Permit lookup by Java FQN<commit_after>/*******************************************************************************
 * Copyright (c) 2007, 2008 <NAME> and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     <NAME> - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylyn.wikitext.core;

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.internal.wikitext.core.util.EclipseServiceLocator;
import org.eclipse.mylyn.internal.wikitext.core.validation.ValidationRules;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;
import org.eclipse.mylyn.wikitext.core.util.ServiceLocator;
import org.eclipse.mylyn.wikitext.core.validation.MarkupValidator;
import org.eclipse.mylyn.wikitext.core.validation.ValidationRule;
import org.osgi.framework.BundleContext;

/**
 * 
 * 
 * @author <NAME>
 */
public class WikiTextPlugin extends Plugin {

	private static final String EXTENSION_MARKUP_LANGUAGE = "markupLanguage"; //$NON-NLS-1$

	private static final String EXTENSION_VALIDATION_RULES = "markupValidationRule"; //$NON-NLS-1$

	private static WikiTextPlugin plugin;

	private SortedMap<String, Class<? extends MarkupLanguage>> languageByName;

	private Map<String, Class<? extends MarkupLanguage>> languageByFileExtension;

	private Map<String, String> languageExtensionByLanguage;

	private Map<String, ValidationRules> validationRulesByLanguageName;

	public WikiTextPlugin() {
	}

	@Override
	public void start(BundleContext context) throws Exception {
		super.start(context);
		ServiceLocator.setImplementation(EclipseServiceLocator.class);
		plugin = this;
	}

	@Override
	public void stop(BundleContext context) throws Exception {
		if (plugin == this) {
			plugin = null;
		}
		super.stop(context);
	}

	public static WikiTextPlugin getDefault() {
		return plugin;
	}

	/**
	 * Get a markup language by name.
	 * 
	 * @param name
	 *            the name of the markup language to retrieve
	 * 
	 * @return the markup language or null if there is no markup language known by the given name
	 * 
	 * @see #getMarkupLanguageNames()
	 */
	public MarkupLanguage getMarkupLanguage(String name) {
		if (languageByName == null) {
			initializeMarkupLanguages();
		}
		Class<? extends MarkupLanguage> languageClass = languageByName.get(name);
		if (languageClass == null) {
			// if not found by name, attempt to lookup by class name. 
			for (Class<? extends MarkupLanguage> clazz : languageByName.values()) {
				if (clazz.getName().equals(name)) {
					languageClass = clazz;
					break;
				}
			}
		}
		if (languageClass != null) {
			return instantiateMarkupLanguage(name, languageClass);
		}
		return null;
	}

	private MarkupLanguage instantiateMarkupLanguage(String name, Class<? extends MarkupLanguage> languageClass) {
		try {
			MarkupLanguage language = languageClass.newInstance();
			language.setName(name);
			language.setExtendsLanguage(languageExtensionByLanguage.get(name));
			return language;
		} catch (Exception e) {
			log(IStatus.ERROR, MessageFormat.format(Messages.getString("WikiTextPlugin.2"), name, //$NON-NLS-1$
					languageClass.getName(), e.getMessage()), e);
		}
		return null;
{'fraction_non_alphanumeric': 0.14077734740216374, 'fraction_numerical': 0.004274075063443301, 'mean_word_length': 5.0, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6545382', 'n_tokens_mistral': 2308, 'n_tokens_neox': 2107, 'n_words': 522}