Search in sources :

Example 1 with ContentAssistContext

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

the class XbaseProposalProvider method proposeDeclaringTypeForStaticInvocation.

public void proposeDeclaringTypeForStaticInvocation(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    if (getXbaseCrossReferenceProposalCreator().isShowTypeProposals() || getXbaseCrossReferenceProposalCreator().isShowSmartProposals()) {
        ContentAssistContext modifiedContext = context.copy().setMatcher(staticQualifierPrefixMatcher).toContext();
        completeJavaTypes(modifiedContext, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, qualifiedNameValueConverter, createVisibilityFilter(context), acceptor);
    }
}
Also used : ContentAssistContext(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext)

Example 2 with ContentAssistContext

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

the class XtextProposalProvider method completeTypeRef_Classifier.

@Override
public void completeTypeRef_Classifier(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    Grammar grammar = GrammarUtil.getGrammar(model);
    ContentAssistContext.Builder myContextBuilder = context.copy();
    myContextBuilder.setMatcher(new ClassifierPrefixMatcher(context.getMatcher(), classifierQualifiedNameConverter));
    if (model instanceof TypeRef) {
        ICompositeNode node = NodeModelUtils.getNode(model);
        if (node != null) {
            int offset = node.getOffset();
            Region replaceRegion = new Region(offset, context.getReplaceRegion().getLength() + context.getReplaceRegion().getOffset() - offset);
            myContextBuilder.setReplaceRegion(replaceRegion);
            myContextBuilder.setLastCompleteNode(node);
            StringBuilder availablePrefix = new StringBuilder(4);
            for (ILeafNode leaf : node.getLeafNodes()) {
                if (leaf.getGrammarElement() != null && !leaf.isHidden()) {
                    if ((leaf.getTotalLength() + leaf.getTotalOffset()) < context.getOffset())
                        availablePrefix.append(leaf.getText());
                    else
                        availablePrefix.append(leaf.getText().substring(0, context.getOffset() - leaf.getTotalOffset()));
                }
                if (leaf.getTotalOffset() >= context.getOffset())
                    break;
            }
            myContextBuilder.setPrefix(availablePrefix.toString());
        }
    }
    ContentAssistContext myContext = myContextBuilder.toContext();
    for (AbstractMetamodelDeclaration declaration : grammar.getMetamodelDeclarations()) {
        if (declaration.getEPackage() != null) {
            createClassifierProposals(declaration, model, myContext, acceptor);
        }
    }
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) TypeRef(org.eclipse.xtext.TypeRef) ContentAssistContext(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Region(org.eclipse.jface.text.Region) Grammar(org.eclipse.xtext.Grammar) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration)

Example 3 with ContentAssistContext

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

the class CodetemplatesProposalProvider method createNestedProposals.

public void createNestedProposals(ContentAssistContext[] contexts, ITextViewer originalViewer, final ICompletionProposalAcceptor acceptor, TemplateData data) {
    for (ContentAssistContext context : contexts) {
        Builder builder = context.copy();
        builder.setViewer(originalViewer);
        ContentAssistContext myContext = builder.toContext();
        IFollowElementAcceptor selector = createNestedSelector(myContext, acceptor, data);
        for (AbstractElement element : myContext.getFirstSetGrammarElements()) {
            selector.accept(element);
        }
    }
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) ContentAssistContext(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext) Builder(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext.Builder) IFollowElementAcceptor(org.eclipse.xtext.ui.editor.contentassist.IFollowElementAcceptor)

Example 4 with ContentAssistContext

use of org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext 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 5 with ContentAssistContext

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

the class TerminalsProposalProvider method complete_ID.

public void complete_ID(EObject model, RuleCall ruleCall, final ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    if (doCreateIdProposals()) {
        PrefixMatcher newMatcher = new PrefixMatcher() {

            @Override
            public boolean isCandidateMatchingPrefix(String name, String prefix) {
                String strippedName = name;
                if (name.startsWith("^") && !prefix.startsWith("^")) {
                    strippedName = name.substring(1);
                }
                return context.getMatcher().isCandidateMatchingPrefix(strippedName, prefix);
            }
        };
        ContentAssistContext myContext = context.copy().setMatcher(newMatcher).toContext();
        String feature = getAssignedFeature(ruleCall);
        String proposalText = feature != null ? feature : Strings.toFirstUpper(ruleCall.getRule().getName().toLowerCase());
        String displayText = proposalText;
        if (feature != null)
            displayText = proposalText + " - " + ruleCall.getRule().getName();
        proposalText = getValueConverter().toString(proposalText, ruleCall.getRule().getName());
        ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, myContext);
        if (proposal instanceof ConfigurableCompletionProposal) {
            ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
            configurable.setSelectionStart(configurable.getReplacementOffset());
            configurable.setSelectionLength(proposalText.length());
            configurable.setAutoInsertable(false);
            configurable.setSimpleLinkedMode(myContext.getViewer(), '\t', ' ');
        }
        acceptor.accept(proposal);
    }
}
Also used : PrefixMatcher(org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher) ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ContentAssistContext(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Aggregations

ContentAssistContext (org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext)15 XtextResource (org.eclipse.xtext.resource.XtextResource)6 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)5 EObject (org.eclipse.emf.ecore.EObject)3 ITextViewer (org.eclipse.jface.text.ITextViewer)3 ConfigurableCompletionProposal (org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal)3 ICompletionProposalAcceptor (org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor)3 PrefixMatcher (org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher)3 StringInputStream (org.eclipse.xtext.util.StringInputStream)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 EClass (org.eclipse.emf.ecore.EClass)2 Region (org.eclipse.jface.text.Region)2 IContentAssistant (org.eclipse.jface.text.contentassist.IContentAssistant)2 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)2 StyledString (org.eclipse.jface.viewers.StyledString)2 Shell (org.eclipse.swt.widgets.Shell)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 XtextSourceViewerConfiguration (org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration)2 Builder (org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext.Builder)2 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)2