<commit_before>/*-******************************************************************************
 * Copyright (c) 2016 Iwao AVE!.
 * 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:
 *    Iwao AVE! - initial API and implementation and/or initial documentation
 *******************************************************************************/

package net.harawata.mybatipse.bean;

import java.util.concurrent.ConcurrentHashMap;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeHierarchy;
import org.eclipse.jdt.core.ITypeHierarchyChangedListener;
import org.eclipse.jdt.core.JavaModelException;

import net.harawata.mybatipse.Activator;

/**
 * @author Iwao AVE!
 */
public class SupertypeHierarchyCache
{
	private static final SupertypeHierarchyCache INSTANCE = new SupertypeHierarchyCache();

	private final ConcurrentHashMap<IType, ITypeHierarchy> cache = new ConcurrentHashMap<IType, ITypeHierarchy>();

	public boolean isCollection(IType type)
	{
		return isSubtype(type, "java.util.Collection");
	}

	public boolean isList(IType type)
	{
		return isSubtype(type, "java.util.List");
	}

	public boolean isMap(IType type)
	{
		return isSubtype(type, "java.util.Map");
	}

	public boolean isSubtype(IType type, String supertypeFqn)
	{
		try
		{
			IType supertype = type.getJavaProject().findType(supertypeFqn);
			return isSubtype(type, supertype);
		}
		catch (JavaModelException e)
		{
			Activator.log(Status.ERROR, "Error while checking type hierarchy of "
				+ type.getFullyQualifiedName() + " and " + supertypeFqn);
		}
		return false;
	}

	public boolean isSubtype(IType type, IType supertype)
	{
		if (supertype == null)
			return false;

		try
		{
			ITypeHierarchy supertypes = getSupertypes(type);
			return supertypes.contains(supertype);
		}
		catch (JavaModelException e)
		{
			Activator.log(Status.ERROR, "Error while checking type hierarchy of "
				+ type.getFullyQualifiedName() + " and " + supertype.getFullyQualifiedName());<commit_msg>Log stack trace.<commit_after>/*-******************************************************************************
 * Copyright (c) 2016 Iwao AVE!.
 * 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:
 *    Iwao AVE! - initial API and implementation and/or initial documentation
 *******************************************************************************/

package net.harawata.mybatipse.bean;

import java.util.concurrent.ConcurrentHashMap;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeHierarchy;
import org.eclipse.jdt.core.ITypeHierarchyChangedListener;
import org.eclipse.jdt.core.JavaModelException;

import net.harawata.mybatipse.Activator;

/**
 * @author <NAME>!
 */
public class SupertypeHierarchyCache
{
	private static final SupertypeHierarchyCache INSTANCE = new SupertypeHierarchyCache();

	private final ConcurrentHashMap<IType, ITypeHierarchy> cache = new ConcurrentHashMap<IType, ITypeHierarchy>();

	public boolean isCollection(IType type)
	{
		return isSubtype(type, "java.util.Collection");
	}

	public boolean isList(IType type)
	{
		return isSubtype(type, "java.util.List");
	}

	public boolean isMap(IType type)
	{
		return isSubtype(type, "java.util.Map");
	}

	public boolean isSubtype(IType type, String supertypeFqn)
	{
		try
		{
			IType supertype = type.getJavaProject().findType(supertypeFqn);
			return isSubtype(type, supertype);
		}
		catch (JavaModelException e)
		{
			Activator.log(Status.ERROR, "Error while checking type hierarchy of "
				+ type.getFullyQualifiedName() + " and " + supertypeFqn, e);
		}
		return false;
	}

	public boolean isSubtype(IType type, IType supertype)
	{
		if (supertype == null)
			return false;

		try
		{
			ITypeHierarchy supertypes = getSupertypes(type);
			return supertypes.contains(supertype);
		}
		catch (JavaModelException e)
		{
			Activator.log(Status.ERROR, "Error while checking type hierarchy of "
				+ type.getFullyQualifiedName() + " and " + supertype.getFullyQualifiedName(), e);
{'fraction_non_alphanumeric': 0.16423118865866956, 'fraction_numerical': 0.003489640130861505, 'mean_word_length': 4.994771241830065, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '1919650', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1390, 'n_words': 330}