Java Code Examples for org.eclipse.xtext.ui.editor.model.IXtextDocument#getContentType()

The following examples show how to use org.eclipse.xtext.ui.editor.model.IXtextDocument#getContentType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public ContentAssistProcessorTestBuilder assertMatchString(String matchString)
		throws Exception {
	String currentModelToParse = getModel();
	final XtextResource xtextResource = loadHelper.getResourceFor(new StringInputStream(currentModelToParse));
	final IXtextDocument xtextDocument = getDocument(xtextResource, currentModelToParse);
	XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
	Shell shell = new Shell();
	try {
		ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument, configuration);
		IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
		String contentType = xtextDocument.getContentType(currentModelToParse.length());
		if (contentAssistant.getContentAssistProcessor(contentType) != null) {
			ContentAssistContext.Factory factory = get(ContentAssistContext.Factory.class);
			ContentAssistContext[] contexts = factory.create(sourceViewer, currentModelToParse.length(), xtextResource);
			for(ContentAssistContext context: contexts) {
				Assert.assertTrue("matchString = '" + matchString + "', actual: '" + context.getPrefix() + "'",
						"".equals(context.getPrefix()) || matchString.equals(context.getPrefix()));
			}
		} else {
			Assert.fail("No content assistant for content type " + contentType);
		}
		return this;
	} finally {
		shell.dispose();
	}
}
 
Example 2
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public ContentAssistProcessorTestBuilder assertMatchString(String matchString)
		throws Exception {
	String currentModelToParse = getModel();
	final XtextResource xtextResource = loadHelper.getResourceFor(new StringInputStream(currentModelToParse, getEncoding()));
	final IXtextDocument xtextDocument = getDocument(xtextResource, currentModelToParse);
	XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
	Shell shell = new Shell();
	try {
		ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument, configuration);
		IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
		String contentType = xtextDocument.getContentType(currentModelToParse.length());
		if (contentAssistant.getContentAssistProcessor(contentType) != null) {
			ContentAssistContext.Factory factory = get(ContentAssistContext.Factory.class);
			ContentAssistContext[] contexts = factory.create(sourceViewer, currentModelToParse.length(), xtextResource);
			for(ContentAssistContext context: contexts) {
				Assert.assertTrue("matchString = '" + matchString + "', actual: '" + context.getPrefix() + "'",
						"".equals(context.getPrefix()) || matchString.equals(context.getPrefix()));
			}
		} else {
			Assert.fail("No content assistant for content type " + contentType);
		}
		return this;
	} finally {
		shell.dispose();
	}
}
 
Example 3
Source File: AcfContentAssistProcessorTestBuilder.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Internally compute completion proposals.
 *
 * @param cursorPosition
 *          the position of the cursor in the {@link IXtextDocument}
 * @param xtextDocument
 *          the {@link IXtextDocument}
 * @return a pair of {@link ICompletionProposal}[] and {@link BadLocationException}. If the tail argument is not {@code null}, an exception occurred in the UI
 *         thread.
 */
private Pair<ICompletionProposal[], BadLocationException> internalComputeCompletionProposals(final int cursorPosition, final IXtextDocument xtextDocument) {
  XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
  Shell shell = new Shell();
  try {
    ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument, configuration);
    IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
    String contentType = xtextDocument.getContentType(cursorPosition);
    IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(contentType);
    if (processor != null) {
      return Tuples.create(processor.computeCompletionProposals(sourceViewer, cursorPosition), null);
    }
    return Tuples.create(new ICompletionProposal[0], null);
  } catch (BadLocationException e) {
    return Tuples.create(new ICompletionProposal[0], e);
  } finally {
    shell.dispose();
  }
}
 
Example 4
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ICompletionProposal[] computeCompletionProposals(final IXtextDocument xtextDocument, int cursorPosition,
		XtextSourceViewerConfiguration configuration, ISourceViewer sourceViewer) throws BadLocationException {
	IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
	String contentType = xtextDocument.getContentType(cursorPosition);
	IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(contentType);
	if (processor != null) {
		return processor.computeCompletionProposals(sourceViewer, cursorPosition);
	}
	return new ICompletionProposal[0];
}
 
Example 5
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ICompletionProposal[] computeCompletionProposals(final IXtextDocument xtextDocument, int cursorPosition,
		XtextSourceViewerConfiguration configuration, ISourceViewer sourceViewer) throws BadLocationException {
	IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
	String contentType = xtextDocument.getContentType(cursorPosition);
	IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(contentType);
	if (processor != null) {
		return processor.computeCompletionProposals(sourceViewer, cursorPosition);
	}
	return new ICompletionProposal[0];
}
 
Example 6
Source File: DotProposalProviderDelegator.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private ICompletionProposal[] computeCompletionProposals(
		final IXtextDocument xtextDocument, int cursorPosition,
		XtextSourceViewerConfiguration configuration,
		ISourceViewer sourceViewer) throws BadLocationException {
	IContentAssistant contentAssistant = configuration
			.getContentAssistant(sourceViewer);
	String contentType = xtextDocument.getContentType(cursorPosition);
	IContentAssistProcessor processor = contentAssistant
			.getContentAssistProcessor(contentType);
	if (processor != null) {
		return processor.computeCompletionProposals(sourceViewer,
				cursorPosition);
	}
	return new ICompletionProposal[0];
}