use of org.eclipse.jface.text.TextSelection in project linuxtools by eclipse.
the class DoubleClickTest method testDoubleClickLine.
@Test
public void testDoubleClickLine() throws Exception {
ILaunchConfiguration config = createConfiguration(proj.getProject());
// $NON-NLS-1$
doLaunch(config, "testDoubleClickLine");
doDoubleClick();
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
assertTrue("editor should be ITextEditor", editor instanceof ITextEditor);
ITextEditor textEditor = (ITextEditor) editor;
ISelection selection = textEditor.getSelectionProvider().getSelection();
assertTrue("selection must be TextSelection", selection instanceof TextSelection);
TextSelection textSelection = (TextSelection) selection;
// zero-indexed
int line = textSelection.getStartLine() + 1;
assertEquals(frame.getLine(), line);
}
use of org.eclipse.jface.text.TextSelection in project xtext-eclipse by eclipse.
the class LinkWithEditorTest method testTextToTree.
@Test
public void testTextToTree() throws Exception {
outlinePage.getSite().getSelectionProvider().addSelectionChangedListener(selectionSyncer);
activate(outlineView);
try {
selectionSyncer.start();
editor.getSelectionProvider().setSelection(new TextSelection(1, 1));
selectionSyncer.awaitSignal(EXPECTED_TIMEOUT);
fail("Selection from inactive part should not be linked");
} catch (TimeoutException e) {
}
activate(editor);
try {
for (int offset = 0; offset < modelAsText.length(); ++offset) {
selectionSyncer.start();
editor.getSelectionProvider().setSelection(new TextSelection(offset, 1));
selectionSyncer.awaitSignal(ERROR_TIMEOUT);
assertSelected(treeViewer, expectedNodeAt(offset));
}
} finally {
outlinePage.getSite().getSelectionProvider().removeSelectionChangedListener(selectionSyncer);
}
}
use of org.eclipse.jface.text.TextSelection in project xtext-eclipse by eclipse.
the class LinkedEditingRefactoringIntegrationTest method testRefactorEcoreCrossLanguage.
@Test
public void testRefactorEcoreCrossLanguage() throws Exception {
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("test");
ePackage.setNsPrefix("test");
ePackage.setNsURI("http://test");
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName(TEST_CLASS);
ePackage.getEClassifiers().add(eClass);
Resource ecoreResource = new ResourceSetImpl().createResource(URI.createPlatformResourceURI(TEST_PROJECT + "/Test.ecore", true));
ecoreResource.getContents().add(ePackage);
ecoreResource.save(null);
ecoreResource.unload();
project.refreshLocal(IResource.DEPTH_INFINITE, null);
String model = "ref test." + TEST_CLASS;
IFile file = createFile(TEST_PROJECT + "/ref.referringtestlanguage", model);
waitForBuild();
final XtextEditor editor = openEditor(file);
final TextSelection selection = new TextSelection(model.indexOf(TEST_CLASS), TEST_CLASS.length());
editor.getSelectionProvider().setSelection(selection);
waitForDisplay();
IRenameElementContext context = editor.getDocument().readOnly(new IUnitOfWork<IRenameElementContext, XtextResource>() {
@Override
public IRenameElementContext exec(XtextResource state) throws Exception {
Reference ref = (Reference) state.getContents().get(0).eContents().get(0);
EObject referenced = ref.getReferenced();
assertNotNull(referenced);
return new IRenameElementContext.Impl(EcoreUtil.getURI(referenced), referenced.eClass(), editor, selection, state.getURI());
}
});
renameRefactoringController.startRefactoring(context);
waitForDisplay();
pressKeys(editor, "NewTestClass\n");
waitForReconciler(editor);
waitForDisplay();
waitForBuild();
ecoreResource.load(null);
assertEquals("NewTestClass", ((EPackage) ecoreResource.getContents().get(0)).getEClassifiers().get(0).getName());
}
use of org.eclipse.jface.text.TextSelection in project xtext-eclipse by eclipse.
the class MarkOccurrencesTest method testMarkOccurrences.
@Test
public void testMarkOccurrences() throws Exception {
String model = "Foo { Bar(Foo) {} Baz(Foo Bar) {} }";
IFile modelFile = IResourcesSetupUtil.createFile("test/src/Test.outlinetestlanguage", model);
XtextEditor editor = openEditor(modelFile);
ISelectionProvider selectionProvider = editor.getSelectionProvider();
selectionProvider.setSelection(new TextSelection(0, 1));
IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
ExpectationBuilder listener = new ExpectationBuilder().added(DECLARATION_ANNOTATION_TYPE, 0, 3).added(OCCURRENCE_ANNOTATION_TYPE, model.indexOf("Foo", 3), 3).added(OCCURRENCE_ANNOTATION_TYPE, model.lastIndexOf("Foo"), 3);
listener.start();
annotationModel.addAnnotationModelListener(listener);
setMarkOccurrences(true);
listener.verify(TIMEOUT);
listener.start();
listener.removed(DECLARATION_ANNOTATION_TYPE, 0, 3).removed(OCCURRENCE_ANNOTATION_TYPE, model.indexOf("Foo", 3), 3).removed(OCCURRENCE_ANNOTATION_TYPE, model.lastIndexOf("Foo"), 3).added(DECLARATION_ANNOTATION_TYPE, model.indexOf("Bar"), 3).added(OCCURRENCE_ANNOTATION_TYPE, model.lastIndexOf("Bar"), 3);
selectionProvider.setSelection(new TextSelection(model.lastIndexOf("Bar"), 1));
listener.verify(TIMEOUT);
listener.start();
listener.removed(DECLARATION_ANNOTATION_TYPE, model.indexOf("Bar"), 3).removed(OCCURRENCE_ANNOTATION_TYPE, model.lastIndexOf("Bar"), 3);
setMarkOccurrences(false);
listener.verify(TIMEOUT);
}
use of org.eclipse.jface.text.TextSelection in project xtext-eclipse by eclipse.
the class ExpressionUtilTest method assertInsertionPoint.
protected void assertInsertionPoint(final String modelWithInsertionMarkup, final String expectedSuccessor) {
final String cleanedModel = modelWithInsertionMarkup.replaceAll("\\$", "");
final XExpression expression = this.parse(cleanedModel);
final int selectionOffset = modelWithInsertionMarkup.indexOf("$");
Resource _eResource = expression.eResource();
TextSelection _textSelection = new TextSelection(selectionOffset, 0);
final XExpression selectedExpression = this.util.findSelectedExpression(((XtextResource) _eResource), _textSelection);
final XExpression successor = this.util.findSuccessorExpressionForVariableDeclaration(selectedExpression);
if ((expectedSuccessor == null)) {
Assert.assertNull(successor);
} else {
Assert.assertNotNull(successor);
final ITextRegion selectedRegion = this.locationInFileProvider.getFullTextRegion(successor);
int _offset = selectedRegion.getOffset();
int _offset_1 = selectedRegion.getOffset();
int _length = selectedRegion.getLength();
int _plus = (_offset_1 + _length);
Assert.assertEquals(expectedSuccessor, cleanedModel.substring(_offset, _plus));
}
}
Aggregations