use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project xtext-eclipse by eclipse.
the class JdtTypesProposalProvider method createTypeProposal.
protected void createTypeProposal(final String typeName, int modifiers, boolean isInnerType, ICompletionProposalFactory proposalFactory, ContentAssistContext context, ICompletionProposalAcceptor acceptor, final IJvmTypeProvider jvmTypeProvider, IValueConverter<String> valueConverter) {
if (acceptor.canAcceptMoreProposals()) {
int lastDot = typeName.lastIndexOf('.');
final StyledString displayString;
if (lastDot != -1) {
if (isInnerType) {
displayString = new StyledString(typeName.substring(lastDot + 1).replace('$', '.')).append(" - " + typeName.substring(0, lastDot), StyledString.QUALIFIER_STYLER);
} else {
displayString = new StyledString(typeName.substring(lastDot + 1)).append(" - " + typeName.substring(0, lastDot), StyledString.QUALIFIER_STYLER);
}
} else {
displayString = new StyledString(isInnerType ? typeName.replace('$', '.') : typeName);
}
Image img = computeImage(typeName, isInnerType, modifiers);
String proposalAsString = typeName;
if (valueConverter != null) {
try {
proposalAsString = valueConverter.toString(isInnerType ? proposalAsString.replace('$', '.') : proposalAsString);
} catch (ValueConverterException vce) {
return;
}
}
ICompletionProposal proposal = proposalFactory.createCompletionProposal(proposalAsString, displayString, img, context);
if (proposal instanceof ConfigurableCompletionProposal) {
ConfigurableCompletionProposal theProposal = (ConfigurableCompletionProposal) proposal;
// calculate the type lazy, as this require a lot of time for large completion lists
theProposal.setAdditionalProposalInfo(new Provider<EObject>() {
@Override
public EObject get() {
return jvmTypeProvider.findTypeByName(typeName);
}
});
theProposal.setHover(hover);
priorities.adjustCrossReferencePriority(theProposal, context.getPrefix());
theProposal.setPriority(theProposal.getPriority() + jdtTypeRelevance.getRelevance(typeName, context.getPrefix()));
}
acceptor.accept(proposal);
}
}
use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project xtext-eclipse by eclipse.
the class TypeAwareReferenceProposalCreator method getWrappedFactory.
@Override
protected Function<IEObjectDescription, ICompletionProposal> getWrappedFactory(EObject model, EReference reference, final Function<IEObjectDescription, ICompletionProposal> proposalFactory) {
if (TypesPackage.Literals.JVM_TYPE.isSuperTypeOf(getEReferenceType(model, reference))) {
return new Function<IEObjectDescription, ICompletionProposal>() {
@Override
public ICompletionProposal apply(IEObjectDescription from) {
ICompletionProposal result = proposalFactory.apply(from);
if (result instanceof ConfigurableCompletionProposal) {
String flags = from.getUserData("flags");
if (flags != null) {
boolean inner = "true".equals(from.getUserData("inner"));
int modifiers = Integer.parseInt(flags);
((ConfigurableCompletionProposal) result).setImage(computeImage(inner, modifiers));
}
}
return result;
}
};
}
return super.getWrappedFactory(model, reference, proposalFactory);
}
use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project xtext-eclipse by eclipse.
the class UiToIdeContentProposalProvider method createProposals.
@Override
public void createProposals(final org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
final ArrayList<Pair<ContentAssistEntry, Integer>> entries = new ArrayList<Pair<ContentAssistEntry, Integer>>();
final IIdeContentProposalAcceptor ideAcceptor = new IIdeContentProposalAcceptor() {
@Override
public void accept(final ContentAssistEntry entry, final int priority) {
if ((entry != null)) {
Pair<ContentAssistEntry, Integer> _mappedTo = Pair.<ContentAssistEntry, Integer>of(entry, Integer.valueOf(priority));
entries.add(_mappedTo);
}
}
@Override
public boolean canAcceptMoreProposals() {
int _size = entries.size();
int _maxProposals = UiToIdeContentProposalProvider.this.getMaxProposals();
return (_size < _maxProposals);
}
};
ContentAssistContext _ideContext = this.getIdeContext(context);
this.ideProvider.createProposals(Collections.<ContentAssistContext>unmodifiableList(CollectionLiterals.<ContentAssistContext>newArrayList(_ideContext)), ideAcceptor);
final AbstractContentProposalProvider.NullSafeCompletionProposalAcceptor uiAcceptor = new AbstractContentProposalProvider.NullSafeCompletionProposalAcceptor(acceptor);
final Procedure2<Pair<ContentAssistEntry, Integer>, Integer> _function = (Pair<ContentAssistEntry, Integer> p, Integer idx) -> {
final ContentAssistEntry entry = p.getKey();
final ConfigurableCompletionProposal proposal = this.doCreateProposal(entry.getProposal(), this.getDisplayString(entry), this.getImage(entry), (p.getValue()).intValue(), context);
uiAcceptor.accept(proposal);
};
IterableExtensions.<Pair<ContentAssistEntry, Integer>>forEach(entries, _function);
}
use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project xtext-eclipse by eclipse.
the class XbaseContentProposalPriorities method adjustCrossReferencePriority.
@Override
public void adjustCrossReferencePriority(final ICompletionProposal proposal, final String prefix) {
if ((proposal instanceof ConfigurableCompletionProposal)) {
Object _additionalData = ((ConfigurableCompletionProposal) proposal).getAdditionalData(XbaseProposalProvider.DESCRIPTION_KEY);
final Object desc = _additionalData;
boolean _matched = false;
if (desc instanceof SimpleIdentifiableElementDescription) {
if (((!Objects.equal(((ConfigurableCompletionProposal) proposal).getReplacementString(), "this")) && (!Objects.equal(((ConfigurableCompletionProposal) proposal).getReplacementString(), "super")))) {
_matched = true;
this.adjustPriority(proposal, prefix, 570);
return;
}
}
if (!_matched) {
if (desc instanceof StaticFeatureDescriptionWithTypeLiteralReceiver) {
_matched = true;
this.adjustPriority(proposal, prefix, 560);
}
}
if (!_matched) {
if (desc instanceof IIdentifiableElementDescription) {
_matched = true;
JvmIdentifiableElement _elementOrProxy = ((IIdentifiableElementDescription) desc).getElementOrProxy();
boolean _matched_1 = false;
if (_elementOrProxy instanceof JvmField) {
_matched_1 = true;
this.adjustPriority(proposal, prefix, 550);
return;
}
if (!_matched_1) {
if (_elementOrProxy instanceof JvmExecutable) {
_matched_1 = true;
this.adjustPriority(proposal, prefix, 520);
return;
}
}
}
}
}
super.adjustCrossReferencePriority(proposal, prefix);
}
use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project n4js by eclipse.
the class ImportsAwareReferenceProposalCreator method getProposal.
/**
* Creates initial proposal adjusted for the N4JS imports. Then passes that proposal to the provided delegate
* proposal factory. Obtained ICompletionProposal is configured with a FQNImporter as custom text. applier.
*
* @param candidate
* for which proposal is created
* @param delegateProposalFactory
* delegate proposal factory
* @return code completion proposal
*/
private ICompletionProposal getProposal(IEObjectDescription candidate, EObject model, IScope scope, EReference reference, ContentAssistContext context, Predicate<IEObjectDescription> filter, Function<IEObjectDescription, ICompletionProposal> delegateProposalFactory) {
final IEObjectDescription inputToUse = getAliasedDescription(candidate, reference, context);
final ICompletionProposal result = delegateProposalFactory.apply(inputToUse);
if (result instanceof ConfigurableCompletionProposal) {
final FQNImporter importer = fqnImporterFactory.create(model.eResource(), scope, valueConverter, filter, context.getViewer());
((ConfigurableCompletionProposal) result).setTextApplier(importer);
}
return result;
}
Aggregations