Search in sources :

Example 21 with IXtextDocument

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

the class ContentAssistProcessorTestBuilder method applyProposal.

public ContentAssistProcessorTestBuilder applyProposal(int position, String proposalString) throws Exception {
    IXtextDocument document = getDocument(getModel());
    Shell shell = new Shell();
    try {
        ICompletionProposal[] proposals = computeCompletionProposals(document, position, shell);
        ICompletionProposal proposal = findProposal(proposalString, proposals);
        return applyProposal(proposal, position, document);
    } finally {
        shell.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 22 with IXtextDocument

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

the class AbstractHyperlinkingTest method hyperlinkingOn.

protected IHyperlink[] hyperlinkingOn(IFile dslFile, int offset) {
    XtextEditor editor = openInEditor(dslFile);
    IXtextDocument document = xtextDocumentUtil.getXtextDocument(editor.getInternalSourceViewer());
    XtextResource resource = document.readOnly((state) -> state);
    return hyperlinkHelper.createHyperlinksByOffset(resource, offset, true);
}
Also used : XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) XtextResource(org.eclipse.xtext.resource.XtextResource) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 23 with IXtextDocument

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

the class ContentAssistProcessorTestBuilder method getDocument.

public IXtextDocument getDocument(final XtextResource xtextResource, final String model) {
    XtextDocument document = get(XtextDocument.class);
    document.set(model);
    document.setInput(xtextResource);
    DocumentPartitioner partitioner = get(DocumentPartitioner.class);
    partitioner.connect(document);
    document.setDocumentPartitioner(partitioner);
    return document;
}
Also used : XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) DocumentPartitioner(org.eclipse.xtext.ui.editor.model.DocumentPartitioner)

Example 24 with IXtextDocument

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

the class ContentAssistProcessorTestBuilder method appendAndApplyProposal.

public ContentAssistProcessorTestBuilder appendAndApplyProposal(String model, int position, String proposalString) throws Exception {
    IXtextDocument document = getDocument(getModel());
    Shell shell = new Shell();
    try {
        XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
        ISourceViewer sourceViewer = getSourceViewer(shell, document, configuration);
        ICompletionProposal[] proposals = computeCompletionProposals(document, position, shell);
        ICompletionProposal proposal = findProposal(proposalString, proposals);
        return appendAndApplyProposal(proposal, sourceViewer, model, position);
    } finally {
        shell.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextSourceViewerConfiguration(org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration)

Example 25 with IXtextDocument

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

the class ReplAutoEdit method customizeDocumentCommand.

@Override
public void customizeDocumentCommand(final IDocument document, final DocumentCommand command) {
    if (!isLineDelimiter(document, command)) {
        return;
    }
    try {
        IXtextDocument doc = xtextDocumentUtil.getXtextDocument(document);
        String result = doc.tryReadOnly(new IUnitOfWork<String, XtextResource>() {

            @Override
            public String exec(XtextResource resource) throws Exception {
                return computeResultText(document, command, resource);
            }
        });
        if (result == null)
            return;
        command.text = result;
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) BadLocationException(org.eclipse.jface.text.BadLocationException) 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