<commit_before>package edu.cuny.citytech.defaultrefactoring.core.utils;

import static org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester.getTopLevelType;

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

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.corext.refactoring.Checks;
import org.eclipse.jdt.internal.corext.util.JdtFlags;

import edu.cuny.citytech.defaultrefactoring.core.refactorings.MigrateSkeletalImplementationToInterfaceRefactoringProcessor;

/**
 * @author <a href="mailto:<EMAIL>">Raffi
 *         Khatchadourian</a>
 * @see org.eclipse.jdt.internal.corext.refactoring.
 *      RefactoringAvailabilityTester
 */
@SuppressWarnings("restriction")
public final class RefactoringAvailabilityTester {

	private RefactoringAvailabilityTester() {
	}

	public static boolean isInterfaceMigrationAvailable(IMethod method, Optional<IProgressMonitor> monitor)
			throws JavaModelException {
		return isInterfaceMigrationAvailable(method, true, monitor);
	}

	public static boolean isInterfaceMigrationAvailable(IMethod method, boolean allowConcreteClasses,
			Optional<IProgressMonitor> monitor) throws JavaModelException {
		if (!Checks.isAvailable(method))
			return false;
		if (method.isConstructor())
			return false;
		if (JdtFlags.isNative(method))
			return false;
		if (JdtFlags.isStatic(method))
			return false;
		if (JdtFlags.isAbstract(method))
			return false;
		if (JdtFlags.isSynchronized(method))
			return false;
		if (JdtFlags.isFinal(method))
			return false;

		final IType declaring = method.getDeclaringType();
		if (declaring != null) {
			if (declaring.isInterface())
				return false; // Method is already in an interface
			else if (!allowConcreteClasses && !Flags.isAbstract(declaring.getFlags()))
				return false; // no concrete types allowed.
		}

		// ensure that there is a target method.
		IMethod targetMethod = MigrateSkeletalImplementationToInterfaceRefactoringProcessor.getTargetMethod(method,
				monitor);
		if (targetMethod == null) // no possible target.
			return false;

		return true;<commit_msg>Filter out source methods that are derived.<commit_after>package edu.cuny.citytech.defaultrefactoring.core.utils;

import static org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester.getTopLevelType;

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

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.corext.refactoring.Checks;
import org.eclipse.jdt.internal.corext.util.JdtFlags;

import edu.cuny.citytech.defaultrefactoring.core.refactorings.MigrateSkeletalImplementationToInterfaceRefactoringProcessor;

/**
 * @author <a href="mailto:<EMAIL>">Raffi
 *         Khatchadourian</a>
 * @see org.eclipse.jdt.internal.corext.refactoring.
 *      RefactoringAvailabilityTester
 */
@SuppressWarnings("restriction")
public final class RefactoringAvailabilityTester {

	private RefactoringAvailabilityTester() {
	}

	public static boolean isInterfaceMigrationAvailable(IMethod method, Optional<IProgressMonitor> monitor)
			throws JavaModelException {
		return isInterfaceMigrationAvailable(method, true, monitor);
	}

	public static boolean isInterfaceMigrationAvailable(IMethod method, boolean allowConcreteClasses,
			Optional<IProgressMonitor> monitor) throws JavaModelException {
		if (!Checks.isAvailable(method))
			return false;
		if (method.isConstructor())
			return false;
		if (JdtFlags.isNative(method))
			return false;
		if (JdtFlags.isStatic(method))
			return false;
		if (JdtFlags.isAbstract(method))
			return false;
		if (JdtFlags.isSynchronized(method))
			return false;
		if (JdtFlags.isFinal(method))
			return false;
		if (method.getResource().isDerived(IResource.CHECK_ANCESTORS))
			return false;

		final IType declaring = method.getDeclaringType();
		if (declaring != null) {
			if (declaring.isInterface())
				return false; // Method is already in an interface
			else if (!allowConcreteClasses && !Flags.isAbstract(declaring.getFlags()))
				return false; // no concrete types allowed.
		}

		// ensure that there is a target method.
		IMethod targetMethod = MigrateSkeletalImplementationToInterfaceRefactoringProcessor.getTargetMethod(method,
				monitor);
		if (targetMethod == null) // no possible target.
			return false;

		return true;
{'fraction_non_alphanumeric': 0.09833298164169656, 'fraction_numerical': 0.0, 'mean_word_length': 5.303191489361702, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '7493961', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1422, 'n_words': 293}