Search in sources :

Example 1 with XtextContentAssistProcessor

use of org.eclipse.xtext.ui.editor.contentassist.XtextContentAssistProcessor in project xtext-eclipse by eclipse.

the class CrossReferenceProposalTest method testBug276742_08b.

@Test
public void testBug276742_08b() throws Exception {
    String modelAsString = "Foo {}";
    ContentAssistProcessorTestBuilder builder = newBuilder();
    XtextContentAssistProcessor processor = get(XtextContentAssistProcessor.class);
    XtextResource resource = getResourceFromString(modelAsString);
    ITextViewer viewer = builder.getSourceViewer(modelAsString, builder.getDocument(resource, modelAsString));
    ContentAssistContext[] contexts = processor.getContextFactory().create(viewer, modelAsString.length(), resource);
    assertEquals(2, contexts.length);
    Set<EClass> contextTypes = Sets.newHashSet(CrossReferenceProposalTestPackage.Literals.MODEL, CrossReferenceProposalTestPackage.Literals.CLASS);
    CrossReferenceProposalTestLanguageGrammarAccess grammarAccess = get(CrossReferenceProposalTestLanguageGrammarAccess.class);
    for (ContentAssistContext context : contexts) {
        EObject model = context.getCurrentModel();
        assertTrue(contextTypes.remove(model.eClass()));
        if (context.getFirstSetGrammarElements().contains(grammarAccess.getClassAccess().getRightCurlyBracketKeyword_3())) {
            assertEquals(CrossReferenceProposalTestPackage.Literals.CLASS, model.eClass());
        } else {
            assertEquals(CrossReferenceProposalTestPackage.Literals.MODEL, model.eClass());
        }
    }
}
Also used : XtextContentAssistProcessor(org.eclipse.xtext.ui.editor.contentassist.XtextContentAssistProcessor) CrossReferenceProposalTestLanguageGrammarAccess(org.eclipse.xtext.ui.tests.editor.contentassist.services.CrossReferenceProposalTestLanguageGrammarAccess) ContentAssistProcessorTestBuilder(org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder) EClass(org.eclipse.emf.ecore.EClass) ContentAssistContext(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext) EObject(org.eclipse.emf.ecore.EObject) XtextResource(org.eclipse.xtext.resource.XtextResource) ITextViewer(org.eclipse.jface.text.ITextViewer) Test(org.junit.Test)

Example 2 with XtextContentAssistProcessor

use of org.eclipse.xtext.ui.editor.contentassist.XtextContentAssistProcessor in project xtext-eclipse by eclipse.

the class CrossReferenceProposalTest method testBug276742_09b.

@Test
public void testBug276742_09b() throws Exception {
    String modelAsString = "Foo {}";
    ContentAssistProcessorTestBuilder builder = newBuilder();
    XtextContentAssistProcessor processor = get(XtextContentAssistProcessor.class);
    XtextResource resource = getResourceFromString(modelAsString);
    ITextViewer viewer = builder.getSourceViewer(modelAsString, builder.getDocument(resource, modelAsString));
    ContentAssistContext[] contexts = processor.getContextFactory().create(viewer, 0, resource);
    assertEquals(1, contexts.length);
    for (ContentAssistContext context : contexts) {
        assertEquals(CrossReferenceProposalTestPackage.Literals.MODEL, context.getCurrentModel().eClass());
    }
}
Also used : XtextContentAssistProcessor(org.eclipse.xtext.ui.editor.contentassist.XtextContentAssistProcessor) ContentAssistProcessorTestBuilder(org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder) ContentAssistContext(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext) XtextResource(org.eclipse.xtext.resource.XtextResource) ITextViewer(org.eclipse.jface.text.ITextViewer) Test(org.junit.Test)

Aggregations

ITextViewer (org.eclipse.jface.text.ITextViewer)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 ContentAssistContext (org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext)2 XtextContentAssistProcessor (org.eclipse.xtext.ui.editor.contentassist.XtextContentAssistProcessor)2 ContentAssistProcessorTestBuilder (org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder)2 Test (org.junit.Test)2 EClass (org.eclipse.emf.ecore.EClass)1 EObject (org.eclipse.emf.ecore.EObject)1 CrossReferenceProposalTestLanguageGrammarAccess (org.eclipse.xtext.ui.tests.editor.contentassist.services.CrossReferenceProposalTestLanguageGrammarAccess)1