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);
}
}
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);
}
}
}
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);
}
}
}
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());
}
}
}
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);
}
}
Aggregations