Java Code Examples for org.eclipse.jface.text.contentassist.IContentAssistant#getContentAssistProcessor()

The following examples show how to use org.eclipse.jface.text.contentassist.IContentAssistant#getContentAssistProcessor() . 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: AbstractWorkbenchTestCase.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Requests proposals in the last location of the given editor.
 */
protected ICompletionProposalHandle[] requestProposals(String mod1Contents, PyEdit editor) {
    editor.setSelection(mod1Contents.length(), 0);
    IContentAssistant contentAssistant = editor.getEditConfiguration().getContentAssistant(
            editor.getPySourceViewer());
    SimpleAssistProcessor processor = (SimpleAssistProcessor) contentAssistant
            .getContentAssistProcessor(IDocument.DEFAULT_CONTENT_TYPE);
    processor.doCycle(); //we want to show the default completions in this case (not the simple ones)
    ICompletionProposal[] props = processor.computeCompletionProposals(editor.getPySourceViewer(),
            mod1Contents.length());
    ArrayList<ICompletionProposalHandle> lst = new ArrayList<>(props.length);
    for (ICompletionProposal iCompletionProposal : props) {
        lst.add((ICompletionProposalHandle) iCompletionProposal);
    }

    return lst.toArray(new ICompletionProposalHandle[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: 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 7
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];
}
 
Example 8
Source File: DirtyEditorFilteringContentAssistTests.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public ICompletionProposal[] computeCompletionProposals(final XtextEditor editorForCompletion, final XtextEditor dirtyEditor, final int cursorPosition) throws BadLocationException {
  this.syncUtil.waitForReconciler(dirtyEditor);
  final ISourceViewer sourceViewer = editorForCompletion.getInternalSourceViewer();
  final IContentAssistant contentAssistant = editorForCompletion.getXtextSourceViewerConfiguration().getContentAssistant(sourceViewer);
  final String contentType = editorForCompletion.getDocument().getContentType(cursorPosition);
  final IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(contentType);
  if ((processor != null)) {
    return processor.computeCompletionProposals(sourceViewer, cursorPosition);
  }
  return null;
}
 
Example 9
Source File: AbstractContentAssistUiTest.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Helper function to find the correct CompletionProposalComputer for the given offset.
 *
 * @param offset
 *          offset in test file
 * @return language and offset specific content assist proposal computer
 */
private CompletionProposalComputer createCompletionProposalComputer(final int offset) {
  XtextSourceViewerConfiguration configuration = getEditor().getXtextSourceViewerConfiguration();
  IContentAssistant contentAssistant = configuration.getContentAssistant(getViewer());
  IContentAssistProcessor contentAssistProcessor;
  try {
    contentAssistProcessor = contentAssistant.getContentAssistProcessor(getDocument().getContentType(offset));
  } catch (BadLocationException e) {
    contentAssistProcessor = getTestUtil().get(IContentAssistProcessor.class);
  }
  if (contentAssistProcessor == null) {
    contentAssistProcessor = getTestUtil().get(IContentAssistProcessor.class);
  }
  return new CompletionProposalComputer((State) contentAssistProcessor, (ITextViewer) getViewer(), offset);
}