/**
 * 
 */
package edu.cuny.citytech.defaultrefactoring.core.utils;

import java.util.Optional;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring;
import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;

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

/**
 * @author <a href="mailto:rkhatchadourian@citytech.cuny.edu">Raffi
 *         Khatchadourian</a>
 *
 */
@SuppressWarnings("restriction")
public final class Util {
	private Util() {
	}

	public static Refactoring createRefactoring(IJavaProject project, IMethod[] methods, Optional<IProgressMonitor> monitor)
			throws JavaModelException {
		CodeGenerationSettings settings = JavaPreferencesSettings.getCodeGenerationSettings(project);
		MigrateSkeletalImplementationToInterfaceRefactoringProcessor processor = new MigrateSkeletalImplementationToInterfaceRefactoringProcessor(
				methods, settings, monitor);
		return new ProcessorBasedRefactoring(processor);
	}

	public static Refactoring createRefactoring(IMethod[] methods, Optional<IProgressMonitor> monitor) throws JavaModelException {
		IJavaProject project = null;

		if (methods != null && methods.length > 0)
			project = methods[0].getJavaProject();

		return createRefactoring(project, methods, monitor);
	}

	public static Refactoring createRefactoring(IMethod[] methods) throws JavaModelException {
		return createRefactoring(methods, Optional.empty());
	}

	public static Refactoring createRefactoring() throws JavaModelException {
		RefactoringProcessor processor = new MigrateSkeletalImplementationToInterfaceRefactoringProcessor();
		return new ProcessorBasedRefactoring(processor);
	}

	public static edu.cuny.citytech.refactoring.common.core.Refactoring createRefactoring(
			final Refactoring refactoring) {
		return new edu.cuny.citytech.refactoring.common.core.Refactoring() {

			public String getName() {
				return refactoring.getName();
			}

			public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
				return refactoring.createChange(pm);
			}

			public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
					throws CoreException, OperationCanceledException {
				return refactoring.checkInitialConditions(pm);
			}

			public RefactoringStatus checkFinalConditions(IProgressMonitor pm)
					throws CoreException, OperationCanceledException {
				return refactoring.checkFinalConditions(pm);
			}
		};
	}
}

@@ -1165,32 +1165,46 @@
 %0A%09public static 
+ProcessorBased
 Refactoring crea
@@ -1249,33 +1249,36 @@
 ethod%5B%5D methods,
- 
+%0A%09%09%09
 Optional%3CIProgre
@@ -1296,20 +1296,499 @@
 monitor)
-%0A%09%09%09
+ throws JavaModelException %7B%0A%09%09MigrateSkeletalImplementationToInterfaceRefactoringProcessor processor = createMigrateSkeletalImplementationToInterfaceRefactoringProcessor(%0A%09%09%09%09project, methods, monitor);%0A%09%09return new ProcessorBasedRefactoring(processor);%0A%09%7D%0A%0A%09public static MigrateSkeletalImplementationToInterfaceRefactoringProcessor createMigrateSkeletalImplementationToInterfaceRefactoringProcessor(%0A%09%09%09IJavaProject project, IMethod%5B%5D methods, Optional%3CIProgressMonitor%3E monitor) 
 throws J
@@ -2090,38 +2090,8 @@
 urn 
-new ProcessorBasedRefactoring(
 proc
@@ -2087,33 +2087,32 @@
 return processor
-)
 ;%0A%09%7D%0A%0A%09public st
@@ -2108,32 +2108,46 @@
 %0A%09public static 
+ProcessorBased
 Refactoring crea
@@ -2206,33 +2206,36 @@
 onitor%3E monitor)
- 
+%0A%09%09%09
 throws JavaModel
@@ -2432,32 +2432,46 @@
 %0A%09public static 
+ProcessorBased
 Refactoring crea
@@ -2605,16 +2605,30 @@
  static 
+ProcessorBased
 Refactor

Make return type more specific.