Search in sources :

Example 61 with TextSelection

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);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) TextSelection(org.eclipse.jface.text.TextSelection) ISelection(org.eclipse.jface.viewers.ISelection) IEditorPart(org.eclipse.ui.IEditorPart) Test(org.junit.Test)

Example 62 with TextSelection

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);
    }
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) ITextSelection(org.eclipse.jface.text.ITextSelection) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 63 with TextSelection

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());
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IFile(org.eclipse.core.resources.IFile) TextSelection(org.eclipse.jface.text.TextSelection) Reference(org.eclipse.xtext.ui.tests.refactoring.referring.Reference) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) XtextResource(org.eclipse.xtext.resource.XtextResource) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) EPackage(org.eclipse.emf.ecore.EPackage) EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) IRenameElementContext(org.eclipse.xtext.ui.refactoring.ui.IRenameElementContext) AbstractLinkedEditingIntegrationTest(org.eclipse.xtext.ui.testing.AbstractLinkedEditingIntegrationTest) Test(org.junit.Test)

Example 64 with TextSelection

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);
}
Also used : IFile(org.eclipse.core.resources.IFile) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) TextSelection(org.eclipse.jface.text.TextSelection) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest) Test(org.junit.Test)

Example 65 with TextSelection

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));
    }
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) ITextRegion(org.eclipse.xtext.util.ITextRegion) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XExpression(org.eclipse.xtext.xbase.XExpression) XtextResource(org.eclipse.xtext.resource.XtextResource)

Aggregations

TextSelection (org.eclipse.jface.text.TextSelection)105 IFile (org.eclipse.core.resources.IFile)35 ITextSelection (org.eclipse.jface.text.ITextSelection)24 ISelection (org.eclipse.jface.viewers.ISelection)24 Test (org.junit.Test)23 IDocument (org.eclipse.jface.text.IDocument)21 IEditorPart (org.eclipse.ui.IEditorPart)19 InputStream (java.io.InputStream)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 Path (org.eclipse.core.runtime.Path)13 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)11 BadLocationException (org.eclipse.jface.text.BadLocationException)10 IRegion (org.eclipse.jface.text.IRegion)10 XtextResource (org.eclipse.xtext.resource.XtextResource)9 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)8 Module (org.eclipse.titan.designer.AST.Module)8 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)8 XExpression (org.eclipse.xtext.xbase.XExpression)8 TTCN3Editor (org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor)7 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)7