use of org.eclipse.xtext.ui.refactoring.ui.RefactoringWizardOpenOperation_NonForking in project xtext-eclipse by eclipse.
the class ExtractVariableHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
syncUtil.totalSync(false);
final XtextEditor editor = EditorUtils.getActiveXtextEditor(event);
if (editor != null) {
final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
final IXtextDocument document = editor.getDocument();
XtextResource resource = document.priorityReadOnly(new IUnitOfWork<XtextResource, XtextResource>() {
@Override
public XtextResource exec(XtextResource state) throws Exception {
return resourceCopier.loadIntoNewResourceSet(state);
}
});
XExpression expression = expressionUtil.findSelectedExpression(resource, selection);
if (expression != null) {
ExtractVariableRefactoring introduceVariableRefactoring = refactoringProvider.get();
if (introduceVariableRefactoring.initialize(editor, expression)) {
ITextRegion region = locationInFileProvider.getFullTextRegion(expression);
editor.selectAndReveal(region.getOffset(), region.getLength());
ExtractVariableWizard wizard = new ExtractVariableWizard(introduceVariableRefactoring);
RefactoringWizardOpenOperation_NonForking openOperation = new RefactoringWizardOpenOperation_NonForking(wizard);
openOperation.run(editor.getSite().getShell(), "Extract Local Variable");
}
}
}
} catch (InterruptedException e) {
return null;
} catch (Exception exc) {
LOG.error("Error during refactoring", exc);
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error during refactoring", exc.getMessage() + "\nSee log for details");
}
return null;
}
use of org.eclipse.xtext.ui.refactoring.ui.RefactoringWizardOpenOperation_NonForking in project xtext-xtend by eclipse.
the class ExtractMethodHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
syncUtil.totalSync(false);
final XtextEditor editor = EditorUtils.getActiveXtextEditor(event);
if (editor != null) {
final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
final IXtextDocument document = editor.getDocument();
XtextResource copiedResource = document.priorityReadOnly(new IUnitOfWork<XtextResource, XtextResource>() {
@Override
public XtextResource exec(XtextResource state) throws Exception {
return resourceCopier.loadIntoNewResourceSet(state);
}
});
List<XExpression> expressions = expressionUtil.findSelectedSiblingExpressions(copiedResource, selection);
if (!expressions.isEmpty()) {
ExtractMethodRefactoring extractMethodRefactoring = refactoringProvider.get();
if (extractMethodRefactoring.initialize(editor, expressions, true)) {
updateSelection(editor, expressions);
ExtractMethodWizard wizard = wizardFactory.create(extractMethodRefactoring);
RefactoringWizardOpenOperation_NonForking openOperation = new RefactoringWizardOpenOperation_NonForking(wizard);
openOperation.run(editor.getSite().getShell(), "Extract Method");
}
}
}
} catch (InterruptedException e) {
return null;
} catch (Exception exc) {
LOG.error("Error during refactoring", exc);
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error during refactoring", exc.getMessage() + "\nSee log for details");
}
return null;
}
Aggregations