Search in sources :

Example 36 with XtextDocument

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

the class BacktrackingLexerPresentationDamagerTest method createDocument.

@Override
protected Document createDocument(String before) throws Exception {
    DocumentTokenSource source = new BacktrackingLexerDocumentTokenSource();
    source.setLexer(new Provider<Lexer>() {

        @Override
        public Lexer get() {
            return createLexer();
        }
    });
    XtextDocument document = new XtextDocument(source, null, outdatedStateManager, operationCanceledManager);
    document.set(before);
    return document;
}
Also used : Lexer(org.eclipse.xtext.parser.antlr.Lexer) BacktrackingLexerDocumentTokenSource(org.eclipse.xtext.ui.editor.model.BacktrackingLexerDocumentTokenSource) DocumentTokenSource(org.eclipse.xtext.ui.editor.model.DocumentTokenSource) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) BacktrackingLexerDocumentTokenSource(org.eclipse.xtext.ui.editor.model.BacktrackingLexerDocumentTokenSource)

Example 37 with XtextDocument

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

the class EditorForAbsentFileTest method testOpenEditorViaIFile.

@Test
public void testOpenEditorViaIFile() throws Exception {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IEditorPart openEditor = IDE.openEditor(getActivePage(), root.getFile(root.getFullPath().append("someProject").append("absent.testlanguage")));
    assertNotNull(openEditor);
    Display display = Display.getCurrent();
    while (display.readAndDispatch()) {
    }
    assertTrue(openEditor instanceof XtextEditor);
    XtextEditor xtextEditor = (XtextEditor) openEditor;
    ISourceViewer sourceViewer = xtextEditor.getInternalSourceViewer();
    IDocument document = sourceViewer.getDocument();
    assertTrue(document instanceof XtextDocument);
    StyledText textWidget = sourceViewer.getTextWidget();
    Composite parent = textWidget.getParent();
    while (parent != null && !(parent.getLayout() instanceof StackLayout)) {
        parent = parent.getParent();
    }
    assertNotNull(parent);
    Control[] children = parent.getChildren();
    Composite errorPageControl = (Composite) children[1];
    while (errorPageControl.getChildren().length == 1) {
        errorPageControl = (Composite) errorPageControl.getChildren()[0];
    }
    Control[] errorPageChildren = errorPageControl.getChildren();
    for (Control c : errorPageChildren) {
        if (c instanceof StyledText) {
            String errorText = ((StyledText) c).getText();
            assertEquals("Resource '/someProject/absent.testlanguage' does not exist.", errorText);
            return;
        }
    }
    fail("Did not find StyledText with matching error text");
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) IEditorPart(org.eclipse.ui.IEditorPart) Control(org.eclipse.swt.widgets.Control) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) StackLayout(org.eclipse.swt.custom.StackLayout) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument) Display(org.eclipse.swt.widgets.Display) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Example 38 with XtextDocument

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

the class XtextGrammarQuickfixProviderTest method validateInEditor.

private void validateInEditor(IXtextDocument document) {
    Job validationJob = ((XtextDocument) document).getValidationJob();
    validationJob.schedule();
    boolean wasInterrupted = false;
    do {
        try {
            Job.getJobManager().join(ValidationJob.XTEXT_VALIDATION_FAMILY, new NullProgressMonitor());
            wasInterrupted = false;
        } catch (OperationCanceledException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            wasInterrupted = true;
        }
    } while (wasInterrupted);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) ValidationJob(org.eclipse.xtext.ui.editor.validation.ValidationJob) Job(org.eclipse.core.runtime.jobs.Job)

Example 39 with XtextDocument

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

the class AbstractDamagerRepairerTest method createDocument.

protected Document createDocument(String before) throws Exception {
    DocumentTokenSource source = new DocumentTokenSource();
    source.setLexer(new Provider<Lexer>() {

        @Override
        public Lexer get() {
            return createLexer();
        }
    });
    XtextDocument document = new XtextDocument(source, null, outdatedStateManager, operationCanceledManager);
    document.set(before);
    return document;
}
Also used : Lexer(org.eclipse.xtext.parser.antlr.Lexer) DocumentTokenSource(org.eclipse.xtext.ui.editor.model.DocumentTokenSource) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument)

Example 40 with XtextDocument

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

the class OutlineTreeProviderTest method testCreateRoot.

@Test
public void testCreateRoot() throws Exception {
    XtextDocument document = createXtextDocument("element {}");
    IOutlineNode rootNode = treeProvider.createRoot(document);
    assertTrue(rootNode instanceof DocumentRootNode);
    assertEquals(treeProvider, ((DocumentRootNode) rootNode).getTreeProvider());
    assertEquals(new TextRegion(0, 10), rootNode.getFullTextRegion());
    assertEquals(new TextRegion(0, 10), rootNode.getSignificantTextRegion());
    assertEquals(document, ((DocumentRootNode) rootNode).getDocument());
}
Also used : DocumentRootNode(org.eclipse.xtext.ui.editor.outline.impl.DocumentRootNode) TextRegion(org.eclipse.xtext.util.TextRegion) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) IOutlineNode(org.eclipse.xtext.ui.editor.outline.IOutlineNode) Test(org.junit.Test)

Aggregations

XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)50 Test (org.junit.Test)21 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)14 XtextResource (org.eclipse.xtext.resource.XtextResource)13 Lexer (org.eclipse.xtext.parser.antlr.Lexer)9 DocumentTokenSource (org.eclipse.xtext.ui.editor.model.DocumentTokenSource)8 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)5 AntlrTokenDefProvider (org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider)4 DocumentPartitioner (org.eclipse.xtext.ui.editor.model.DocumentPartitioner)4 IOutlineNode (org.eclipse.xtext.ui.editor.outline.IOutlineNode)4 ArrayList (java.util.ArrayList)3 Job (org.eclipse.core.runtime.jobs.Job)3 IDocument (org.eclipse.jface.text.IDocument)3 ITypedRegion (org.eclipse.jface.text.ITypedRegion)3 CancelIndicator (org.eclipse.xtext.util.CancelIndicator)3 StringInputStream (org.eclipse.xtext.util.StringInputStream)3 Injector (com.google.inject.Injector)2 IFile (org.eclipse.core.resources.IFile)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2