use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project n4js by eclipse.
the class ImportsAwareReferenceProposalCreator method lookupCrossReference.
/**
* Retrieves possible reference targets from scope, including erroneous solutions (e.g., not visible targets). This
* list is further filtered here. This is a general pattern: Do not change or modify scoping for special content
* assist requirements, instead filter here.
*
* @param proposalFactory
* usually this will be an instance of
* {@link AbstractJavaBasedContentProposalProvider.DefaultProposalCreator DefaultProposalCreator}.
* @param filter
* by default an instance of {@link N4JSCandidateFilter} will be provided here.
*/
@SuppressWarnings("javadoc")
public void lookupCrossReference(EObject model, EReference reference, ContentAssistContext context, ICompletionProposalAcceptor acceptor, Predicate<IEObjectDescription> filter, Function<IEObjectDescription, ICompletionProposal> proposalFactory) {
if (model != null) {
final IScope scope = ((IContentAssistScopeProvider) scopeProvider).getScopeForContentAssist(model, reference);
// iterate over candidates, filter them, and create ICompletionProposals for them
final Iterable<IEObjectDescription> candidates = scope.getAllElements();
// don't use candidates.forEach since we want an early exit
for (IEObjectDescription candidate : candidates) {
if (!acceptor.canAcceptMoreProposals())
return;
if (filter.apply(candidate)) {
QualifiedName qfn = candidate.getQualifiedName();
String tmodule = null;
if (qfn.getSegmentCount() >= 2) {
tmodule = qfn.getSegment(qfn.getSegmentCount() - 2);
}
// In case of main module, adjust the qualified name, e.g. index.Element -> react.Element
IN4JSProject project = n4jsCore.findProject(candidate.getEObjectURI()).orNull();
QualifiedName candidateName;
if (project != null && tmodule != null && tmodule.equals(project.getMainModule())) {
candidateName = QualifiedName.create(project.getProjectId(), candidate.getQualifiedName().getLastSegment().toString());
} else {
candidateName = candidate.getQualifiedName();
}
final ICompletionProposal proposal = getProposal(candidate, model, scope, reference, context, filter, proposalFactory);
if (proposal instanceof ConfigurableCompletionProposal && candidate.getName().getSegmentCount() > 1) {
ConfigurableCompletionProposal castedProposal = (ConfigurableCompletionProposal) proposal;
castedProposal.setAdditionalData(FQNImporter.KEY_QUALIFIED_NAME, candidateName);
// Original qualified name is the qualified name before adjustment
castedProposal.setAdditionalData(FQNImporter.KEY_ORIGINAL_QUALIFIED_NAME, candidate.getQualifiedName());
}
acceptor.accept(proposal);
}
}
}
}
use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project dsl-devkit by dsldevkit.
the class CheckCfgProposalProvider method completeConfiguredParameter_NewValue.
@Override
public // CHECKSTYLE:OFF
void completeConfiguredParameter_NewValue(final EObject model, final Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
// CHECKSTYLE:ON
// TODO filter depending on type of linked parameter
FormalParameter parameter = ((ConfiguredParameter) model).getParameter();
ICheckCfgPropertySpecification propertySpecification = null;
String[] validValues = null;
if (parameter != null) {
propertySpecification = CheckCfgUtil.getPropertySpecification(parameter.getName());
if (propertySpecification != null) {
validValues = propertySpecification.getExpectedValues();
}
}
if (validValues != null && validValues.length > 0) {
String info = propertySpecification.getInfo();
for (String validValue : validValues) {
ICompletionProposal proposal = createCompletionProposal(String.format("\"%s\"", validValue), new StyledString(validValue), getImage(model), 0, context.getPrefix(), context);
if (proposal instanceof ConfigurableCompletionProposal) {
((ConfigurableCompletionProposal) proposal).setAdditionalProposalInfo(info);
}
acceptor.accept(proposal);
}
return;
}
super.completeConfiguredParameter_NewValue(model, assignment, context, acceptor);
}
use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project dsl-devkit by dsldevkit.
the class AcfContentAssistProcessorTestBuilder method applyText.
/**
* Applies a content assist proposal using the expected display string.
*
* @param expectedDisplayString
* the content assist proposal to apply
* @param appendSpace
* whether to append a space
* @return a new {@link AcfContentAssistProcessorTestBuilder} with the text applied.
* @throws Exception
* if there was a problem loading the xtext resource
*/
public AcfContentAssistProcessorTestBuilder applyText(final String expectedDisplayString, final boolean appendSpace) throws Exception {
ICompletionProposal proposal = null;
for (final ICompletionProposal p : computeCompletionProposals(getModel(), getCursorPosition())) {
if (expectedDisplayString.equals(p.getDisplayString())) {
proposal = p;
break;
}
}
assertNotNull(MessageFormat.format("\"{0}\" not a valid completion proposal", expectedDisplayString), proposal);
String text = "";
if (proposal instanceof ConfigurableCompletionProposal) {
text = ((ConfigurableCompletionProposal) proposal).getReplacementString();
} else if (proposal instanceof XtextTemplateProposal) {
// These may occur in the context of custom content assist templates
text = ((XtextTemplateProposal) proposal).getAdditionalProposalInfo();
}
AcfContentAssistProcessorTestBuilder ret = append(text);
if (appendSpace) {
return ret.append(" ");
}
return ret;
}
use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project statecharts by Yakindu.
the class STextProposalProvider method alterPriority.
private void alterPriority(ICompletionProposal proposal, int delta) {
if (proposal == null || !(proposal instanceof ConfigurableCompletionProposal))
return;
ConfigurableCompletionProposal castedProposal = (ConfigurableCompletionProposal) proposal;
castedProposal.setPriority(castedProposal.getPriority() + delta);
}
use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project statecharts by Yakindu.
the class SGenProposalProvider method completeGeneratorModel_GeneratorId.
@Override
public void completeGeneratorModel_GeneratorId(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
Iterable<IGeneratorDescriptor> descriptions = GeneratorExtensions.getGeneratorDescriptors();
for (IGeneratorDescriptor desc : descriptions) {
ICompletionProposal proposal = createCompletionProposal(desc.getId(), new StyledString((desc.getName() != null) ? desc.getName() : "null"), PathToImageResolver.toImage(desc.getImagePath()), context);
if (proposal instanceof ConfigurableCompletionProposal) {
ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
configurable.setAdditionalProposalInfo(desc.getDescription());
}
acceptor.accept(proposal);
}
}
Aggregations