use of org.autorefactor.environment.Environment in project AutoRefactor by JnRouvignac.
the class AutoRefactorFix method createCleanUp.
/**
* Create the clean up.
*
* @param compilationUnit compilation unit
* @param enabled enabled
* @param fOptions options
* @return Clean up fix
*/
public static ICleanUpFix createCleanUp(final CompilationUnit compilationUnit, final boolean enabled, final CleanUpOptions fOptions) {
boolean hasChanges = false;
final ICompilationUnit iCompilationUnit = (ICompilationUnit) compilationUnit.getJavaElement();
// $NON-NLS-1$
final CleanUpChange cleanUpChange = new CleanUpChange("AutoRefactor", iCompilationUnit);
TextEdit allEdits = null;
if (enabled) {
final IJavaProject javaProject = PrepareApplyRefactoringsJob.getIJavaProject(iCompilationUnit);
final JavaProjectOptions options = new JavaProjectOptionsImpl(javaProject.getOptions(true));
final Environment environment = AutoRefactorPlugin.getEnvironment();
final List<RefactoringRule> refactoringRules = getConfiguredRefactoringRules(fOptions);
final SubMonitor loopMonitor = SubMonitor.convert(null, 1);
final Queue<RefactoringUnit> refactoringUnits = new ConcurrentLinkedQueue<>();
refactoringUnits.add(new RefactoringUnit(iCompilationUnit, options));
final ApplyRefactoringsJob applyRefactoringsJob = new ApplyRefactoringsJob(refactoringUnits, refactoringRules, environment);
final AggregateASTVisitor visitor = new AggregateASTVisitor(refactoringRules);
try {
List<TextEdit> textEdits = applyRefactoringsJob.applyRefactoring(iCompilationUnit, visitor, options, loopMonitor, false);
for (TextEdit textEdit : textEdits) {
if (hasChanges) {
allEdits = TextEditUtil.merge(allEdits, textEdit);
} else {
hasChanges = true;
allEdits = textEdit;
}
}
} catch (Exception e) {
if (!hasChanges) {
return null;
}
}
}
if (!hasChanges) {
return null;
}
cleanUpChange.setEdit(allEdits);
AutoRefactorFix autoRefactorFix = new AutoRefactorFix();
autoRefactorFix.cleanUpChange = cleanUpChange;
return autoRefactorFix;
}
use of org.autorefactor.environment.Environment in project AutoRefactor by JnRouvignac.
the class AutoRefactorPlugin method start.
@Override
public void start(final BundleContext context) throws Exception {
super.start(context);
plugin = this;
environment = new Environment(new DisplayEventLoop(), new JobManagerImpl(), new LoggerImpl(), new EclipsePreferences(plugin.getPreferenceStore()));
}
use of org.autorefactor.environment.Environment in project AutoRefactor by JnRouvignac.
the class AutoRefactorHandler method execute.
/**
* Execute.
*
* @param event The event
*
* @return An object
*
* @throws ExecutionException ExecutionException
*/
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
try {
Environment environment = AutoRefactorPlugin.getEnvironment();
new PrepareApplyRefactoringsJob(getSelectedJavaElements(event), AllCleanUpRules.getConfiguredRefactoringRules(environment.getPreferences()), environment).schedule();
} catch (Exception e) {
final Shell shell = HandlerUtil.getActiveShell(event);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
// $NON-NLS-1$
showMessage(shell, "An error has occurred:\n\n" + sw);
}
// resolvedTypeBinding().
return null;
}
Aggregations