Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Package declaration
Package declaration [message #894588] Mon, 09 July 2012 13:51 Go to next message
Eclipse UserFriend
Hi all,

I have a problem using XText, and didn't find a solution yet, so I decided to ask my question here.
I'm trying to implement support for a language where we do not have explicit package declaration, or, well, in a "non-commonly-Java-like-syntax"-way.

Usually you would meet (as in the Xtext examples) the following syntax:

package org.orgname.product;
import org.other.*;
something DeclarationName {
// elements...
}

In the language I'm working with, the current package declaration is different, we currently do :

import org.other.*;
something org.orgname.product.DeclarationName {
// elements...
}

The problem is that in the { } scope, Xtext expects elements to be org.orgname.product.DeclarationName.* elements, and not org.orgname.product.*, which our own tools expect.

The org.orgname.product.DeclarationName is matched as a standard QualifiedName in the grammar.

To summarize : how can I "implicitly declare" a namespace using the package prefix from my QualifiedName ? (And still have the freshly declared "something ....DeclarationName" available for references from other files)

How can I implement a way for Xtext to consider the right scope for all the inner elements, so it still does the same good old auto-completion and quickfixes for cross-references ?
Meaning, if I use an element from the same package, no import would be added, and if the element is in another package, its selection would add the import the standard way ? (it works with more classical "package" declaration : I tried... I just need to do it "our way").

I've tried to familiarize with DeclarativeScopeProvider and ImportedNamespaceAwareLocalScopeProvider, but didn't really find how to do it.

Thank you, sorry for the messy description, and the Xtext framework is really awesome by the way !

[Updated on: Mon, 09 July 2012 13:56] by Moderator

Re: Package declaration [message #894591 is a reply to message #894588] Mon, 09 July 2012 14:00 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

a complete reproducable example would have helped to give it a try
never the less
overrriding
org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.getQualifiedNameOfLocalElement(EObject)
shoud be worth a try

~Christian
--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@xxxxxxxx
Re: Package declaration [message #894712 is a reply to message #894591] Tue, 10 July 2012 04:59 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for your quick answer, you will find our grammar file attached to this message.
It's a bit complex, which is why I didn't post it at first.

In the grammar, I commented all that concerned the "PackageDeclaration" rule, as we do not want this behavior at the moment.
I personnally prefer using the "package" keyword in a Java-like way but don't have much choice at the moment, due to the other tools development and other members acceptance.

Our "implicit" package definition should be done using CompositeDefinition, PrimitiveDefinition, and TypeDefinition names (QualifiedName).
I want to fix the scope of our "elements" referred by these rules, actually considered as prefixed by the full QualifiedName of those rules (we only want the scope to consider the same package as the parent element).

Please note before using this grammar that it relies on another grammar in the ProvidedInterfaceDefinition and RequiredInterfaceDefinition rules. You can comment all references to those elements as they are not really important for our problem.

Thanks again, I will investigate your proposition and come back to you if I can (or can't !) make it work.

[Updated on: Tue, 10 July 2012 05:35] by Moderator

Re: Package declaration [message #894716 is a reply to message #894712] Tue, 10 July 2012 05:03 Go to previous messageGo to next message
Eclipse UserFriend
You can find a sample Eclipse project attached to this message.
  • Attachment: Example.zip
    (Size: 2.94KB, Downloaded 166 times)

[Updated on: Tue, 10 July 2012 05:22] by Moderator

Re: Package declaration [message #894729 is a reply to message #894716] Tue, 10 July 2012 05:41 Go to previous messageGo to next message
Eclipse UserFriend
Oops small correction to apply to the grammar, I just found that the

QualifiedNameWithWildcard:
QualifiedName '.*'? ;

rule was missing the '.' at the end.
This wasn't related to my problem since I've had it before removing the dot, but the dot removal was was the result of following experiments. Please consider it to be there anyway.

[Updated on: Tue, 10 July 2012 05:43] by Moderator

Re: Package declaration [message #894828 is a reply to message #894712] Tue, 10 July 2012 12:49 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

in this case you would do a fake import for the parent

public class MyDslImportedNamespaceAwareLocalScopeProvider extends
		ImportedNamespaceAwareLocalScopeProvider {
	
	@Inject IQualifiedNameConverter qualifiedNameConverter;
	

	
	@Override
	protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(
			EObject context, boolean ignoreCase) {
		// TODO Auto-generated method stub
		List<ImportNormalizer> result = new ArrayList<ImportNormalizer>();
		result.addAll(super.internalGetImportedNamespaceResolvers(context, 
ignoreCase));
		if (context instanceof CompositeDefinition) {
		 
result.add(createImportedNamespaceResolver(qualifiedNameConverter.toString(getQualifiedNameProvider().getFullyQualifiedName(context).skipLast(1)) 
+ ".*", ignoreCase));
		}
		return result;
		
	}

}


~Christian


--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Package declaration [message #894835 is a reply to message #894828] Tue, 10 July 2012 13:12 Go to previous message
Eclipse UserFriend
I had been messing with a custom ImportedNamespaceAwareLocalScopeProvider for some time, but had not thought of that.

A very neat solution to my problem, thank you !
Previous Topic:Using xpand with xtext
Next Topic:referencing java methods
Goto Forum:
  


Current Time: Thu Jul 10 08:13:43 EDT 2025

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

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

Back to the top