Xtext Proposal Provider: Remove "super" etc. from list [message #1779917] |
Mon, 15 January 2018 14:12  |
Eclipse User |
|
|
|
Hello,
I'm trying to customize my Proposal Provider for my dsl written in Xtext with Xbase.
What I got working is to remove some default keywords (like throw) with the following code:
override completeKeyword(Keyword keyword, ContentAssistContext contentAssistContext,
ICompletionProposalAcceptor acceptor) {
//Ignore these
if (keyword.getValue().equals("switch") || keyword.getValue().equals("var") ||
keyword.getValue().equals("for") || keyword.getValue().equals("val") || keyword.getValue().equals("val") ||
keyword.getValue().equals("try") || keyword.getValue().equals("throw") ||
keyword.getValue().equals("synchronized") || keyword.getValue().equals("this")) {
return;
}
super.completeKeyword(keyword, contentAssistContext, acceptor);
}
But I want to remove the default proposals "super" and "this" primarily. It would be great to also remove some variables by name (like "args" from the generated java main method) but that would be optional.
Is there a way to remove these?
Thanks in advance.
|
|
|
|
|
|
|
|
Re: Xtext Proposal Provider: Remove "super" etc. from list [message #1780031 is a reply to message #1780030] |
Tue, 16 January 2018 10:57   |
Eclipse User |
|
|
|
besides this you can try something like
public class DomainModelFeatureScopes extends FeatureScopes {
@Override
protected IScope createLocalVariableScope(EObject featureCall, IScope parent, IFeatureScopeSession session,
IResolvedTypes resolvedTypes) {
return new LocalVariableScope(parent, session, asAbstractFeatureCall(featureCall)) {
@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
if (IFeatureNames.THIS.equals(name) || IFeatureNames.SUPER.equals(name)) {
return null;
}
return super.getSingleElement(name);
}
@Override
protected List<IEObjectDescription> getLocalElementsByName(QualifiedName name) {
if (IFeatureNames.THIS.equals(name) || IFeatureNames.SUPER.equals(name)) {
return Collections.emptyList();
}
return super.getLocalElementsByName(name);
}
@Override
protected List<IEObjectDescription> getAllLocalElements() {
return IterableExtensions.toList(Iterables.filter(super.getAllLocalElements(), new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription d) {
return !IFeatureNames.THIS.equals(d.getQualifiedName()) && !IFeatureNames.SUPER.equals(d.getQualifiedName());
}
}));
}
};
}
}
or move the filtering to
org.eclipse.xtext.xbase.ui.contentassist.XbaseReferenceProposalCreator.queryScope(IScope, EObject, EReference, Predicate<IEObjectDescription>)
|
|
|
Re: Xtext Proposal Provider: Remove "super" etc. from list [message #1780038 is a reply to message #1780031] |
Tue, 16 January 2018 12:30  |
Eclipse User |
|
|
|
Thanks, that example works perfectly fine!
I don't want to use "this" and "super" in my language because its a language without object instantiation. Its a imperative language for beginners. I wanted to remove it from the content proposals because it might be confusing for beginners in coding to see them and get confused because they don't get used in the language.
|
|
|
Powered by
FUDForum. Page generated in 0.06930 seconds