Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » limit scoping of first fragment of qualified name?
limit scoping of first fragment of qualified name? [message #807365] Sun, 26 February 2012 10:24 Go to next message
Phil R is currently offline Phil RFriend
Messages: 99
Registered: September 2011
Member
Hi,

For using import files and namespaces together the best option was to use only importNamespace. the first fragment of the qualified name will be the filelocation.
Now this all works great but not for the content assist because it should only propose content from the imported files and not from all files. This is normal behaviour because the filelocation are also "namespaces" and thus the content assist proposes file.dsl::content.

My question is what is the best option to limit the content assist to only propose content from files included. (otherwise the content assist list would get extremely big for projects with many files). I made a custom proposals so it works for one Xtext Rule, but then I have to create lot's of proposals for all other Rules referening to a FQN object. Could I solve it with scoping and how?
Please note I cant use importURI, because including files should be able to extend namespaces, so some behaviour of importnamespace is required for including files.

the full grammar is over 500 lines now, so here's a snippet:

Model:
	includes+=IncludeFile*
	elements+=AbstractElement*
;

FQN:
	ID ("::" ID)*	
;

// including files:
IncludeFile:
	'#include' importedNamespace=STRING 
;

// including some of the abstract elements :
Import: 
	'using' (ImportVocabulary|ImportNamespace)
;

ImportVocabulary:
	'vocabulary' importedNamespace=FQN
;

ImportNamespace:
	'namespace' importedNamespace=FQN 
;

InternPointer:
	pointername=[SymbolDeclaration|FQN] ('[' (arg=TypeReference (',' args+=TypeReference)*)? ']')?
;
...


So what I could get to work is making a custom content assist for internpointer_pointername. But there are a lot more of these references

I hope there is a compacter (and more stable) solution by custom scoping?

Regards,
Phil
Re: limit scoping of first fragment of qualified name? [message #807559 is a reply to message #807365] Sun, 26 February 2012 17:35 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Custom scoping is definitely a good possibility here and quite a bit less tedious to implement than custom content assist (generated custom assist will obey custom scoping, anyway).

The idea is probably to gather up all SymbolDeclaration's in the imported files and to have these returned by a method with signature scope_SymbolDeclaration(Model model(, ...)) as an IScope. (The Reference Guide is not entirely unclear on the matter and in any case, there are lots of examples floating around.)


Re: limit scoping of first fragment of qualified name? [message #808138 is a reply to message #807559] Mon, 27 February 2012 12:52 Go to previous message
Phil R is currently offline Phil RFriend
Messages: 99
Registered: September 2011
Member
Hi Meinte Boersma

it does not work with importnamespace now.
It is just "simple names" now, it doesn't matter which namespace is used. How to add qualified name functionality?
example of use:
vocname::vocelement // works
vocelement // works not with vocname imported

public IScope scope_SymbolDeclaration(final Model model, EReference reference) {		

		IScope unfilteredScope = scopeProvider.getScope(model, reference);		
		Predicate<IEObjectDescription> filter = new Predicate<IEObjectDescription>() {
			
			@Override
			public boolean apply(IEObjectDescription input) {
				System.out.println(model.eResource().getURI().lastSegment() + "==" + input.getQualifiedName().getFirstSegment());
				// keep the owning resource
				if (model.eResource().getURI().lastSegment() != null) {
					if (model.eResource().getURI().lastSegment().equals(input.getQualifiedName().getFirstSegment())) {
						return true;
					}
				}
				// keep the included resources
				for (IncludeFile file : model.getIncludes()) {
					if (input.getQualifiedName().getFirstSegment().equals(file.getImportedNamespace())) {
						return true;
					}
				}
				
				return false;
			}
		};
		
		return new FilteringScope(unfilteredScope, filter);		
	}


EDIT ::
got it fixed, dunno why not scope_SymbolDeclaration(model,..) could be used
It works as below:
public IScope scope_SymbolDeclaration(final EObject context, EReference reference) {		

		IScope unfilteredScope = super.delegateGetScope(context, reference);		
		
		Predicate<IEObjectDescription> filter = new Predicate<IEObjectDescription>() {
			
			@Override
			public boolean apply(IEObjectDescription input) {				
				// keep the owning resource
				if (context.eResource().getURI().lastSegment() != null) {
					if (context.eResource().getURI().lastSegment().equals(input.getQualifiedName().getFirstSegment())) {
						return true;
					}
				}
				// keep the included resources
				EObject model = context;
				while (!(model instanceof Model)) model = model.eContainer();
				if (model instanceof Model) {
				for (IncludeFile file : ((Model)model).getIncludes()) {
					if (input.getQualifiedName().getFirstSegment().equals(file.getImportedNamespace())) {						
						return true;
					}
				}
				}
				
				return false;
			}
		};
		
		return new FilteringScope(unfilteredScope, filter);		
	}

Any improvements?

Regards,
Phi

[Updated on: Mon, 27 February 2012 18:04]

Report message to a moderator

Previous Topic:Parsing block expressions vs. scope
Next Topic:help with Xdoc
Goto Forum:
  


Current Time: Sat Apr 27 04:39:32 GMT 2024

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

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

Back to the top