org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration Java Examples

The following examples show how to use org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration. 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: 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 #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));
	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: 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 #4
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ContentAssistProcessorTestBuilder applyProposal(ICompletionProposal proposal, int position, IXtextDocument document)
		throws Exception {
	Shell shell = new Shell();
	try {
		XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
		ISourceViewer sourceViewer = getSourceViewer(shell, document, configuration);
		return appendAndApplyProposal(proposal, sourceViewer, model, position);
	} finally {
		shell.dispose();
	}
}
 
Example #5
Source File: AcfContentAssistProcessorTestBuilder.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc} Code copied from parent. Override required to run in UI because of getSourceViewer, which creates a new Shell.
 */
@Override
public ContentAssistProcessorTestBuilder assertMatchString(final String matchString) throws Exception {
  BadLocationException exception = UiThreadDispatcher.dispatchAndWait(new Function<BadLocationException>() {
    @Override
    public BadLocationException run() {
      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);
        }
      } catch (BadLocationException e) {
        return e;
      } finally {
        shell.dispose();
      }
      return null;
    }
  });
  if (exception != null) {
    throw exception;
  }
  return this;
}
 
Example #6
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);
}
 
Example #7
Source File: DotProposalProviderDelegator.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private ISourceViewer getSourceViewer(Shell shell,
		final IXtextDocument xtextDocument,
		XtextSourceViewerConfiguration configuration) {
	XtextSourceViewer.Factory factory = get(
			XtextSourceViewer.Factory.class);
	ISourceViewer sourceViewer = factory.createSourceViewer(shell, null,
			null, false, 0);
	sourceViewer.configure(configuration);
	sourceViewer.setDocument(xtextDocument);
	return sourceViewer;
}
 
Example #8
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 #9
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, Shell shell)
		throws BadLocationException {
	XtextSourceViewerConfiguration configuration = get(
			XtextSourceViewerConfiguration.class);
	ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument,
			configuration);
	return computeCompletionProposals(xtextDocument, cursorPosition,
			configuration, sourceViewer);
}
 
Example #10
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ISourceViewer getSourceViewer(Shell shell, final IXtextDocument xtextDocument,
		XtextSourceViewerConfiguration configuration) {
	XtextSourceViewer.Factory factory = get(XtextSourceViewer.Factory.class);
	ISourceViewer sourceViewer = factory.createSourceViewer(shell, null, null, false, 0);
	sourceViewer.configure(configuration);
	sourceViewer.setDocument(xtextDocument);
	return sourceViewer;
}
 
Example #11
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 #12
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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();
	}
}
 
Example #13
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ISourceViewer getSourceViewer(Shell shell, final IXtextDocument xtextDocument,
		XtextSourceViewerConfiguration configuration) {
	XtextSourceViewer.Factory factory = get(XtextSourceViewer.Factory.class);
	ISourceViewer sourceViewer = factory.createSourceViewer(shell, null, null, false, 0);
	sourceViewer.configure(configuration);
	sourceViewer.setDocument(xtextDocument);
	return sourceViewer;
}
 
Example #14
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 #15
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ContentAssistProcessorTestBuilder applyProposal(ICompletionProposal proposal, int position, IXtextDocument document)
		throws Exception {
	Shell shell = new Shell();
	try {
		XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
		ISourceViewer sourceViewer = getSourceViewer(shell, document, configuration);
		return appendAndApplyProposal(proposal, sourceViewer, model, position);
	} finally {
		shell.dispose();
	}
}
 
Example #16
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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();
	}
}
 
Example #17
Source File: HighlightingHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.3
 */
public void install(XtextSourceViewerConfiguration configuration, XtextSourceViewer sourceViewer) {
	fSourceViewer= sourceViewer;
	fConfiguration= configuration;
	if(sourceViewer != null && configuration != null){
		fPresentationReconciler= (XtextPresentationReconciler) fConfiguration.getPresentationReconciler(sourceViewer);
	} else {
		fPresentationReconciler = null;
		fConfiguration = null;
	}
	preferenceStore = getPreferenceStoreAccessor().getPreferenceStore();
	preferenceStore.addPropertyChangeListener(this);
	enable();
}
 
Example #18
Source File: DefaultMergeViewer.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public DefaultMergeViewer(Composite parent, int styles, CompareConfiguration compareConfiguration,
		StreamContentDocumentProvider documentProvider,
		Provider<XtextSourceViewerConfiguration> sourceViewerConfigurationProvider) {
	super(parent, styles | SWT.LEFT_TO_RIGHT, compareConfiguration);
	this.documentProvider = documentProvider;
	this.sourceViewerConfigurationProvider = sourceViewerConfigurationProvider;
}
 
Example #19
Source File: EmbeddedEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public EmbeddedEditor(XtextDocument document, XtextSourceViewer viewer, XtextSourceViewerConfiguration configuration, IEditedResourceProvider resourceProvider, Runnable afterSetDocumet) {
	this.document = document;
	this.viewer = viewer;
	this.configuration = configuration;
	this.resourceProvider = resourceProvider;
	this.afterSetDocument = afterSetDocumet;
}
 
Example #20
Source File: AbstractSARLUiModule.java    From sarl with Apache License 2.0 4 votes vote down vote up
public Class<? extends XtextSourceViewerConfiguration> bindXtextSourceViewerConfiguration() {
	return XtendSourceViewerConfiguration.class;
}
 
Example #21
Source File: StyledTextXtextAdapter.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected XtextSourceViewerConfiguration getXtextSourceViewerConfiguration() {
	return this.configuration;
}
 
Example #22
Source File: GamlUiModule.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
public Class<? extends XtextSourceViewerConfiguration> bindXtextSourceViewerConfiguration() {
	return GamaSourceViewerConfiguration.class;
}
 
Example #23
Source File: XtendUiModule.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends XtextSourceViewerConfiguration> bindSourceViewerConfiguration() {
	return XtendSourceViewerConfiguration.class;
}
 
Example #24
Source File: DotUiModule.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends XtextSourceViewerConfiguration> bindXtextSourceViewerConfiguration() {
	return DotSourceViewerConfiguration.class;
}
 
Example #25
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected ICompletionProposal[] computeCompletionProposals(final IXtextDocument xtextDocument, int cursorPosition,
		Shell shell) throws BadLocationException {
	XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
	ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument, configuration);
	return computeCompletionProposals(xtextDocument, cursorPosition, configuration, sourceViewer);
}
 
Example #26
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected ICompletionProposal[] computeCompletionProposals(final IXtextDocument xtextDocument, int cursorPosition,
		Shell shell) throws BadLocationException {
	XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
	ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument, configuration);
	return computeCompletionProposals(xtextDocument, cursorPosition, configuration, sourceViewer);
}
 
Example #27
Source File: EmbeddedEditor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public XtextSourceViewerConfiguration getConfiguration() {
	return this.configuration;
}