Skip to main content



      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 14:12 Go to next message
Eclipse UserFriend
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 14:26 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Xtext Proposal Provider: Remove "super" etc. from list [message #1779924 is a reply to message #1779922] Mon, 15 January 2018 14:36 Go to previous messageGo to next message
Eclipse UserFriend
have a look e.g. at org.eclipse.xtext.xbase.typesystem.internal.LogicalContainerAwareReentrantTypeResolver.addThisAndSuper(IFeatureScopeSession, ITypeReferenceOwner, JvmDeclaredType, JvmTypeReference, boolean)
Re: Xtext Proposal Provider: Remove "super" etc. from list [message #1780021 is a reply to message #1779924] Tue, 16 January 2018 10:11 Go to previous messageGo to next message
Eclipse UserFriend
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 10:17 Go to previous messageGo to next message
Eclipse UserFriend
did you have a look at other places?
Re: Xtext Proposal Provider: Remove "super" etc. from list [message #1780030 is a reply to message #1780024] Tue, 16 January 2018 10:38 Go to previous messageGo to next message
Eclipse UserFriend
btw why do you want to get rid of "this"?
Re: Xtext Proposal Provider: Remove "super" etc. from list [message #1780031 is a reply to message #1780030] Tue, 16 January 2018 10:57 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 16:44:15 EDT 2025

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

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

Back to the top