Home » Modeling » TMF (Xtext) » [ContentAssistant] Propose type involving ImportManager
|
Re: [ContentAssistant] Propose type involving ImportManager [message #1173778 is a reply to message #1172044] |
Wed, 06 November 2013 19:04 |
|
Hi,
do you use xbase?
overring org.eclipse.xtext.xbase.ui.contentassist.XbaseProposalProvider.createVisibilityFilter(ContentAssistContext, int) or preceeding methods doesnt work?
@Override
protected Filter createVisibilityFilter(ContentAssistContext context, final int searchFor) {
final char[] pn = "java.lang".toCharArray();
final char[] cn = "String".toCharArray();
return new Filter() {
public boolean accept(int modifiers, char[] packageName, char[] simpleTypeName,
char[][] enclosingTypeNames, String path) {
return java.util.Arrays.equals(packageName, pn) && java.util.Arrays.equals(simpleTypeName, cn);
}
public int getSearchFor() {
return searchFor;
}
};
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
| |
Re: [ContentAssistant] Propose type involving ImportManager [message #1173973 is a reply to message #1173900] |
Wed, 06 November 2013 21:49 |
|
Hi,
i have no idea on the impact/ performance, but the comparison has to be done somewhere. maybe there is a more efficient way to compare a char array to a string.
this filter thing is actually passed to the ITypesProposalProvider. JdtTypeProposalProvider does actually something similar in createSubTypeProposals
so if i understand you correct you do not want to use the typeprovider at all?!?
why dont you do this simply upfront
@Inject
private JdtTypeProviderFactory jdtTypeProviderFatory;
@Inject
private IScopeProvider scopeProvider;
@Inject
private RewritableImportSection.Factory importSectionFactory;
@Inject
private ReplaceConverter replaceConverter;
@Override
public void completeJvmParameterizedTypeReference_Type(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
IScope typeScope = null;
if (context.getCurrentModel() != null) {
typeScope = scopeProvider.getScope(context.getCurrentModel(), TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
}
final IJvmTypeProvider jvmTypeProvider = jdtTypeProviderFatory.findOrCreateTypeProvider(context.getResource().getResourceSet());
ICompletionProposal theProposal = createCompletionProposal("java.util.List", context);
((ConfigurableCompletionProposal) theProposal).setAdditionalProposalInfo(new Provider<EObject>(){
public EObject get() {
return jvmTypeProvider.findTypeByName("java.util.List");
}});
((ConfigurableCompletionProposal) theProposal).setTextApplier(createTextApplier(context, typeScope, getQualifiedNameConverter(), getQualifiedNameValueConverter()));
acceptor.accept(theProposal);
}
protected ConfigurableCompletionProposal.IReplacementTextApplier createTextApplier(
ContentAssistContext context, IScope typeScope,
IQualifiedNameConverter qualifiedNameConverter, IValueConverter<String> valueConverter) {
return new ImportingTypesProposalProvider.FQNImporter(context.getResource(), context.getViewer(), typeScope, qualifiedNameConverter,
valueConverter, importSectionFactory, replaceConverter);
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: [ContentAssistant] Propose type involving ImportManager [message #1174665 is a reply to message #1173973] |
Thu, 07 November 2013 08:39 |
Boris Brodski Messages: 112 Registered: July 2009 |
Senior Member |
|
|
Hello Christian,
thank you very much! This is the missing peace of the puzzle I was looking for.
Here is my current solution:
public class XxxProposalProvider extends AbstractXxxProposalProvider {
@Inject private RewritableImportSection.Factory importSectionFactory;
@Inject private ReplaceConverter replaceConverter;
@Inject private IScopeProvider scopeProvider;
@Inject private IEObjectHover hover;
@Override
public void completeMethodDefinition_MitSperreClassList(
final EObject model, final Assignment assignment,
final ContentAssistContext context,
final ICompletionProposalAcceptor acceptor) {
List<JvmType> entities = ...; //Get list of allowed entities
for (final JvmType jvmType : entities) {
IScope typeScope = null;
if (context.getCurrentModel() != null) {
typeScope = scopeProvider.getScope(context.getCurrentModel(),
TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
}
ICompletionProposal theProposal = createCompletionProposal(jvmType.getQualifiedName(),
getDisplayString(jvmType, jvmType.getQualifiedName(), jvmType.getSimpleName()), getImage(jvmType), context);
if (theProposal != null && theProposal instanceof ConfigurableCompletionProposal) {
ConfigurableCompletionProposal configurableCompletionProposal = (ConfigurableCompletionProposal) theProposal;
// Use 'new Provider<EObject>() {}' if EObject should be found in the first place
configurableCompletionProposal.setAdditionalProposalInfo(jvmType);
configurableCompletionProposal.setHover(hover);
configurableCompletionProposal.setTextApplier(
createTextApplier(context, typeScope, getQualifiedNameConverter(), getQualifiedNameValueConverter()));
acceptor.accept(theProposal);
}
}
}
protected ConfigurableCompletionProposal.IReplacementTextApplier createTextApplier(
ContentAssistContext context, IScope typeScope,
IQualifiedNameConverter qualifiedNameConverter, IValueConverter<String> valueConverter) {
return new ImportingTypesProposalProvider.FQNImporter(context.getResource(), context.getViewer(),
typeScope, qualifiedNameConverter, valueConverter, importSectionFactory, replaceConverter);
}
}
Cheers,
Boris
[Updated on: Thu, 07 November 2013 08:40] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Wed Sep 25 01:25:42 GMT 2024
Powered by FUDForum. Page generated in 0.03483 seconds
|