use of org.eclipse.jface.text.TextSelection in project xtext-xtend by eclipse.
the class ExtractVariableIntegrationTest method assertAfterExtract.
protected void assertAfterExtract(final CharSequence input, final CharSequence expected, final boolean isFinal) {
try {
final String inputString = input.toString();
final String model = inputString.replace("$", "");
final IFile file = this.workbenchTestHelper.createFile("Foo", model);
final XtextEditor editor = this.workbenchTestHelper.openEditor(file);
try {
final IUnitOfWork<Change, XtextResource> _function = (XtextResource it) -> {
Change _xblockexpression = null;
{
final int offset = inputString.indexOf("$");
int _lastIndexOf = inputString.lastIndexOf("$");
int _minus = (_lastIndexOf - 1);
final int length = (_minus - offset);
final TextSelection textSelection = new TextSelection(offset, length);
final XExpression selection = this.util.findSelectedExpression(it, textSelection);
final ExtractVariableRefactoring refactoring = this.refactoringProvider.get();
refactoring.setFinal(isFinal);
refactoring.initialize(editor, selection);
NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
final RefactoringStatus status = refactoring.checkAllConditions(_nullProgressMonitor);
Assert.assertTrue(status.toString(), status.isOK());
NullProgressMonitor _nullProgressMonitor_1 = new NullProgressMonitor();
Change _createChange = refactoring.createChange(_nullProgressMonitor_1);
NullProgressMonitor _nullProgressMonitor_2 = new NullProgressMonitor();
_xblockexpression = _createChange.perform(_nullProgressMonitor_2);
}
return _xblockexpression;
};
editor.getDocument().<Change>readOnly(_function);
Assert.assertEquals(expected.toString(), editor.getDocument().get());
} finally {
editor.close(false);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.jface.text.TextSelection in project xtext-xtend by eclipse.
the class ExtractMethodIntegrationTest method assertExtractForbidden.
protected void assertExtractForbidden(final CharSequence input, final Procedure1<? super ExtractMethodRefactoring> initializer, final String messageFragment) {
try {
final String inputString = input.toString();
final IFile file = this.workbenchTestHelper.createFile("Foo", inputString.replace("$", ""));
final XtextEditor editor = this.workbenchTestHelper.openEditor(file);
try {
final IUnitOfWork<String, XtextResource> _function = (XtextResource it) -> {
String _xblockexpression = null;
{
int _indexOf = inputString.indexOf("$");
int _lastIndexOf = inputString.lastIndexOf("$");
int _indexOf_1 = inputString.indexOf("$");
int _minus = (_lastIndexOf - _indexOf_1);
int _minus_1 = (_minus - 1);
TextSelection _textSelection = new TextSelection(_indexOf, _minus_1);
final List<XExpression> selection = this.util.findSelectedSiblingExpressions(it, _textSelection);
final ExtractMethodRefactoring refactoring = this.refactoringProvider.get();
refactoring.initialize(editor, selection, true);
refactoring.setMethodName("bar");
NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
final RefactoringStatus status = refactoring.checkInitialConditions(_nullProgressMonitor);
initializer.apply(refactoring);
NullProgressMonitor _nullProgressMonitor_1 = new NullProgressMonitor();
status.merge(refactoring.checkFinalConditions(_nullProgressMonitor_1));
Assert.assertTrue(status.toString(), status.hasError());
final String message = status.getMessageMatchingSeverity(RefactoringStatus.ERROR);
Assert.assertTrue(message, message.toLowerCase().contains(messageFragment.toLowerCase()));
_xblockexpression = "";
}
return _xblockexpression;
};
editor.getDocument().<String>readOnly(_function);
} finally {
editor.close(false);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.jface.text.TextSelection in project xtext-xtend by eclipse.
the class XtendQuickfixProvider method fixWrongFileRenameClass.
@Fix(IssueCodes.WRONG_FILE)
public void fixWrongFileRenameClass(final Issue issue, final IssueResolutionAcceptor acceptor) {
URI uri = issue.getUriToProblem();
String className = uri.trimFileExtension().lastSegment();
String label = String.format("Rename class to '%s'", className);
acceptor.accept(issue, label, label, null, (element, context) -> {
context.getXtextDocument().modify(resource -> {
IRenameElementContext renameContext = renameContextFactory.createRenameElementContext(element, null, new TextSelection(context.getXtextDocument(), issue.getOffset(), issue.getLength()), resource);
final ProcessorBasedRefactoring refactoring = renameRefactoringProvider.getRenameRefactoring(renameContext);
((RenameElementProcessor) refactoring.getProcessor()).setNewName(className);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(true, true, monitor -> {
try {
if (!refactoring.checkFinalConditions(monitor).isOK())
return;
Change change = refactoring.createChange(monitor);
change.initializeValidationData(monitor);
PerformChangeOperation performChangeOperation = new PerformChangeOperation(change);
performChangeOperation.setUndoManager(RefactoringCore.getUndoManager(), refactoring.getName());
performChangeOperation.setSchedulingRule(ResourcesPlugin.getWorkspace().getRoot());
performChangeOperation.run(monitor);
} catch (CoreException e) {
logger.error(e);
}
});
return null;
});
});
}
use of org.eclipse.jface.text.TextSelection in project eclipse.platform.text by eclipse.
the class GotoLastEditPositionAction method run.
@Override
public void run() {
EditPosition editPosition = TextEditorPlugin.getDefault().getLastEditPosition();
if (editPosition == null)
return;
final Position pos = editPosition.getPosition();
if (pos == null || pos.isDeleted)
return;
IWorkbenchWindow window = getWindow();
if (window == null)
return;
IWorkbenchPage page = window.getActivePage();
IEditorPart editor;
try {
editor = page.openEditor(editPosition.getEditorInput(), editPosition.getEditorId());
} catch (PartInitException ex) {
// $NON-NLS-1$
IStatus status = new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, IStatus.OK, "Go to Last Edit Location failed", ex);
TextEditorPlugin.getDefault().getLog().log(status);
return;
}
// Optimization - could also use else branch
if (editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) editor;
textEditor.selectAndReveal(pos.offset, pos.length);
return;
}
/*
* Workaround: send out a text selection
* XXX: Needs to be improved, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=32214
*/
if (editor != null) {
IEditorSite site = editor.getEditorSite();
if (site == null)
return;
ISelectionProvider provider = editor.getEditorSite().getSelectionProvider();
if (provider == null)
return;
provider.setSelection(new TextSelection(pos.offset, pos.length));
}
}
use of org.eclipse.jface.text.TextSelection in project linuxtools by eclipse.
the class DoubleClickTest method testDoubleClickFunction.
@Test
public void testDoubleClickFunction() throws Exception {
ILaunchConfiguration config = createConfiguration(proj.getProject());
// $NON-NLS-1$
doLaunch(config, "testDoubleClickFunction");
CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
CachegrindOutput output = view.getOutputs()[0];
// $NON-NLS-1$
CachegrindFile file = getFileByName(output, "cpptest.cpp");
// $NON-NLS-1$
CachegrindFunction func = getFunctionByName(file, "main");
TreePath path = new TreePath(new Object[] { output, file, func });
doDoubleClick(path);
// check file in editor
IEditorPart editor = checkFile(file);
// check line number
ITextEditor textEditor = (ITextEditor) editor;
ISelection selection = textEditor.getSelectionProvider().getSelection();
TextSelection textSelection = (TextSelection) selection;
// zero-indexed
int line = textSelection.getStartLine() + 1;
int expectedLine = ((IFunction) func.getModel()).getSourceRange().getStartLine();
assertEquals(expectedLine, line);
}
Aggregations