Search in sources :

Example 56 with IXtextDocument

use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.

the class DefaultFoldingRegionProviderTest method testSignificantPartOfModel_03.

@Test
public void testSignificantPartOfModel_03() throws Exception {
    IFile iFile = createFile("foo/bar.foldingtestlanguage", "\n" + "element\n" + "  foo end\n");
    IXtextDocument document = openFileAndReturnDocument(iFile);
    DefaultFoldingRegionProvider reg = createFoldingRegionProvider();
    Collection<FoldedPosition> regions = reg.getFoldingRegions(document);
    assertEquals(1, regions.size());
    FoldedPosition position = Iterables.getOnlyElement(regions);
    assertEquals("\n".length(), position.getOffset());
    assertEquals("element\n  foo end\n".length(), position.getLength());
    assertEquals("element\n  ".length(), position.computeCaptionOffset(document));
    IRegion[] projectionRegions = position.computeProjectionRegions(document);
    assertEquals(1, projectionRegions.length);
    assertEquals("\n".length(), projectionRegions[0].getOffset());
    assertEquals("element\n".length(), projectionRegions[0].getLength());
}
Also used : IFile(org.eclipse.core.resources.IFile) DefaultFoldingRegionProvider(org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider) FoldedPosition(org.eclipse.xtext.ui.editor.folding.FoldedPosition) IRegion(org.eclipse.jface.text.IRegion) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Example 57 with IXtextDocument

use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.

the class DefaultFoldingRegionProviderTest method testSignificantPartOfModel_01.

@Test
public void testSignificantPartOfModel_01() throws Exception {
    IFile iFile = createFile("foo/bar.foldingtestlanguage", "\n" + "element foo\n" + "end\n");
    IXtextDocument document = openFileAndReturnDocument(iFile);
    DefaultFoldingRegionProvider reg = createFoldingRegionProvider();
    Collection<FoldedPosition> regions = reg.getFoldingRegions(document);
    assertEquals(1, regions.size());
    FoldedPosition position = Iterables.getOnlyElement(regions);
    assertEquals("\n".length(), position.getOffset());
    assertEquals("element foo\nend\n".length(), position.getLength());
    assertEquals("element ".length(), position.computeCaptionOffset(document));
    IRegion[] projectionRegions = position.computeProjectionRegions(document);
    assertEquals(1, projectionRegions.length);
    assertEquals("\nelement foo\n".length(), projectionRegions[0].getOffset());
    assertEquals("end\n".length(), projectionRegions[0].getLength());
}
Also used : IFile(org.eclipse.core.resources.IFile) DefaultFoldingRegionProvider(org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider) FoldedPosition(org.eclipse.xtext.ui.editor.folding.FoldedPosition) IRegion(org.eclipse.jface.text.IRegion) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Example 58 with IXtextDocument

use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.

the class OpenDocumentTracker method initialize.

@Inject(optional = true)
protected void initialize(final IWorkbench workbench) {
    Assert.isNotNull(Display.getCurrent());
    partListener = new PartListener();
    pageListener = new PageListener();
    for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) {
        window.addPageListener(pageListener);
        for (IWorkbenchPage page : window.getPages()) {
            page.addPartListener(partListener);
            for (IEditorReference editorRef : page.getEditorReferences()) {
                Pair<URI, IXtextDocument> entry = getEntry(editorRef);
                if (entry != null) {
                    resourceUri2document.put(entry.getFirst(), entry.getSecond());
                }
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPageListener(org.eclipse.ui.IPageListener) URI(org.eclipse.emf.common.util.URI) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Inject(com.google.inject.Inject)

Example 59 with IXtextDocument

use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.

the class OpenDocumentTracker method getEntry.

protected Pair<URI, IXtextDocument> getEntry(IWorkbenchPartReference partRef) {
    IWorkbenchPart part = partRef.getPart(false);
    if (part instanceof XtextEditor) {
        XtextEditor xtextEditor = (XtextEditor) part;
        URI resourceURI = getResourceURI(xtextEditor);
        IXtextDocument document = xtextEditor.getDocument();
        if (resourceURI != null && document != null)
            return Tuples.create(resourceURI, document);
    }
    return null;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) URI(org.eclipse.emf.common.util.URI) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 60 with IXtextDocument

use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.

the class XtextContentAssistProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    if (contentProposalProvider == null)
        return null;
    IXtextDocument document = xtextDocumentUtil.getXtextDocument(viewer);
    ICompletionProposal[] result = document.priorityReadOnly(createCompletionProposalComputer(viewer, offset));
    Arrays.sort(result, completionProposalComparator);
    result = completionProposalPostProcessor.postProcess(result);
    return result;
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Aggregations

IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)147 XtextResource (org.eclipse.xtext.resource.XtextResource)51 Test (org.junit.Test)46 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)38 IFile (org.eclipse.core.resources.IFile)37 BadLocationException (org.eclipse.jface.text.BadLocationException)26 AbstractEditorTest (org.eclipse.xtext.ui.testing.AbstractEditorTest)26 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)25 IModificationContext (org.eclipse.xtext.ui.editor.model.edit.IModificationContext)23 EObject (org.eclipse.emf.ecore.EObject)22 DefaultFoldingRegionProvider (org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider)18 FoldedPosition (org.eclipse.xtext.ui.editor.folding.FoldedPosition)18 Fix (org.eclipse.xtext.ui.editor.quickfix.Fix)16 List (java.util.List)12 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)12 ArrayList (java.util.ArrayList)11 Issue (org.eclipse.xtext.validation.Issue)11 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)10 URI (org.eclipse.emf.common.util.URI)9 IRegion (org.eclipse.jface.text.IRegion)9