Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext Proposal Provider: Remove "super" etc. from list
Xtext Proposal Provider: Remove "super" etc. from list [message #1779917] Mon, 15 January 2018 19:12 Go to next message
René Bärnreuther is currently offline René BärnreutherFriend
Messages: 31
Registered: October 2017
Member
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 #1779922 is a reply to message #1779917] Mon, 15 January 2018 19:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
do you want to remove these from proposals only or from the scoping as well (hey originate from there) see usages of the constants in org.eclipse.xtext.xbase.scoping.batch.IFeatureNames

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Proposal Provider: Remove "super" etc. from list [message #1779924 is a reply to message #1779922] Mon, 15 January 2018 19:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
have a look e.g. at org.eclipse.xtext.xbase.typesystem.internal.LogicalContainerAwareReentrantTypeResolver.addThisAndSuper(IFeatureScopeSession, ITypeReferenceOwner, JvmDeclaredType, JvmTypeReference, boolean)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Proposal Provider: Remove "super" etc. from list [message #1780021 is a reply to message #1779924] Tue, 16 January 2018 15:11 Go to previous messageGo to next message
René Bärnreuther is currently offline René BärnreutherFriend
Messages: 31
Registered: October 2017
Member
Thanks for your input.
I had a look at the classes and tried to overwrite addThisAndSuper by removing the builder.add(THIS) and builder.add(SUPER), but it didn't work.
It would be sufficient if they just wouldn't appear in the proposal anymore. Where would I have to look at for this?
Re: Xtext Proposal Provider: Remove "super" etc. from list [message #1780024 is a reply to message #1780021] Tue, 16 January 2018 15:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
did you have a look at other places?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Proposal Provider: Remove "super" etc. from list [message #1780030 is a reply to message #1780024] Tue, 16 January 2018 15:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
btw why do you want to get rid of "this"?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Proposal Provider: Remove "super" etc. from list [message #1780031 is a reply to message #1780030] Tue, 16 January 2018 15:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
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>)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Proposal Provider: Remove "super" etc. from list [message #1780038 is a reply to message #1780031] Tue, 16 January 2018 17:30 Go to previous message
René Bärnreuther is currently offline René BärnreutherFriend
Messages: 31
Registered: October 2017
Member
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.
Previous Topic:Debug "Produced region is inconsistent"
Next Topic:xText Standalone maven dependencies
Goto Forum:
  


Current Time: Sat Apr 27 03:11:38 GMT 2024

Powered by FUDForum. Page generated in 0.03164 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top