Java Code Examples for org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext#Builder
The following examples show how to use
org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext#Builder .
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: ParserBasedContentAssistContextFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void doCreateContexts( INode lastCompleteNode, INode currentNode, String prefix, EObject previousModel, Collection<FollowElement> followElements) { Set<AbstractElement> followElementAsAbstractElements = Sets.newLinkedHashSet(); computeFollowElements(followElements, followElementAsAbstractElements); Multimap<EObject, AbstractElement> contextMap = computeCurrentModel(previousModel, lastCompleteNode, followElementAsAbstractElements); currentNode = getContainingDatatypeRuleNode(currentNode); for (Entry<EObject, Collection<AbstractElement>> entry : contextMap.asMap().entrySet()) { ContentAssistContext.Builder contextBuilder = doCreateContext(lastCompleteNode, entry.getKey(), previousModel, currentNode, prefix); for(AbstractElement element: entry.getValue()) { contextBuilder.accept(element); } contextBuilders.add(contextBuilder); } }
Example 2
Source File: ParserBasedContentAssistContextFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public ContentAssistContext.Builder doCreateContext( INode lastCompleteNode, EObject currentModel, EObject previousModel, INode currentNode, String prefix) { ContentAssistContext.Builder context = contentAssistContextProvider.get(); context.setRootNode(rootNode); context.setLastCompleteNode(lastCompleteNode); context.setCurrentNode(currentNode); context.setRootModel(parseResult.getRootASTElement()); context.setCurrentModel(currentModel); context.setPreviousModel(previousModel); context.setOffset(completionOffset); context.setViewer(viewer); context.setPrefix(prefix); int regionLength = prefix.length(); if (selection.getLength() > 0) regionLength = regionLength + selection.getLength(); Region region = new Region(completionOffset - prefix.length(), regionLength); context.setReplaceRegion(region); context.setSelectedText(selection.getText()); context.setMatcher(matcher); context.setResource(resource); return context; }
Example 3
Source File: DelegatingContentAssistContextFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected ContentAssistContext.Builder convert(org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext delegateContext) { ContentAssistContext.Builder context = contentAssistContextProvider.get(); context.setRootNode(delegateContext.getRootNode()); context.setLastCompleteNode(delegateContext.getLastCompleteNode()); context.setCurrentNode(delegateContext.getCurrentNode()); context.setRootModel(delegateContext.getRootModel()); context.setCurrentModel(delegateContext.getCurrentModel()); context.setPreviousModel(delegateContext.getPreviousModel()); context.setOffset(delegateContext.getOffset()); context.setViewer(viewer); context.setPrefix(delegateContext.getPrefix()); Region region = new Region(delegateContext.getReplaceRegion().getOffset(), delegateContext.getReplaceRegion().getLength()); context.setReplaceRegion(region); context.setSelectedText(delegateContext.getSelectedText()); context.setMatcher(matcher); context.setResource(resource); for (AbstractElement grammarElement : delegateContext.getFirstSetGrammarElements()) { context.accept(grammarElement); } return context; }
Example 4
Source File: XtextProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@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); } } }