Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext Reader for unnamed Grammar Element(How to read a textual model using a grammar that does not have a name for the top level element?)
Xtext Reader for unnamed Grammar Element [message #638454] Thu, 11 November 2010 11:15 Go to next message
Helge Mising name is currently offline Helge Mising nameFriend
Messages: 17
Registered: October 2010
Junior Member
Hi all,

I read the two threads covering this subject:
(i) http://www.eclipse.org/forums/index.php?t=msg&th=171975& amp;start=0&
(ii) http://www.eclipse.org/forums/index.php?t=msg&goto=54889 1&

but they do not really help me further.

I have a grammar similar to Jeremie's that does not have a name in the top-level element.
CompilationUnit returns CompilationUnit : 
	( 
		( annotations+=Annotations )?
		packageDeclaration+=PackageDeclaration
	)?
	( importDeclarations+=ImportDeclaration )*
	( typeDeclarations+=TypeDeclaration )*
;


Since I want to read Java like code fragments I cannot add a 'name' element there.
Thus, I followed the posts and let the RuntimeModule class override the name provider binding as:
@Override
public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
	return CompilationUnitQualifiedNameProvider.class;
}


The implementation of CompilationUnitQualifiedNameProvider returns a name String. Is this all I have to do or did I miss anything? I assume that I have to do something else since my workflow still tells:
Quote:
Could not find any exported element of type 'CompilationUnit' -> Slot 'j' is empty.

and when debugging the name provider it seems, that it is never called.

So, what did I miss? Is there a step-by-step list of what to do in my case?

The DSL generator workflow calls the
fragment = exporting.QualifiedNamesFragment {}


and not the SimpleNamesFragment as in Jeremie's case. Is this the problem? I did not change anything in this DSL generator workflow except allowing for backtracking in the Antlr fragments.
(I use Xtext version 1.0.1)

Best,
Helge
Re: Xtext Reader for unnamed Grammar Element [message #638469 is a reply to message #638454] Thu, 11 November 2010 12:28 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

as an initial question: Have you tried using the UriBasedReader in the workflow rather than Reader? The former allows for specifying a particular file directly, so that the root element is stored in the model slot.

Alex
Re: Xtext Reader for unnamed Grammar Element [message #638473 is a reply to message #638469] Thu, 11 November 2010 12:35 Go to previous messageGo to next message
Helge Mising name is currently offline Helge Mising nameFriend
Messages: 17
Registered: October 2010
Junior Member
Hi,

I just tried to use the org.eclipse.xtext.mwe.UriBasedReader. It gives the same 'empty slot' message and seems to not call my name provider.

Best,
Helge
Re: Xtext Reader for unnamed Grammar Element [message #638868 is a reply to message #638473] Fri, 12 November 2010 20:18 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I just tried it with the following name provider implementation and it works for me

public class MyNameProvider extends DefaultDeclarativeQualifiedNameProvider {
public String qualifiedName(TypeWithoutNameFeature obj) {
return "someName";
}
}

Alex
Re: Xtext Reader for unnamed Grammar Element [message #642194 is a reply to message #638868] Tue, 30 November 2010 10:50 Go to previous messageGo to next message
Helge Mising name is currently offline Helge Mising nameFriend
Messages: 17
Registered: October 2010
Junior Member
Hi,

I did a lot of debugging. I am sure that my name provider is never called. It seems that something is going wrong with registering it. That is, when I debug the RuntimeModule of my language, then the language provider class contains only 'null' and '0' elements. Especially, I would expect the 'qualifiedName' method to appear in the 'publicMethods'.
When debugging the URIBasedReader and particularly the corresponding SlotEntry class, I see that the
Quote:

Could not find any exported element of type 'CompilationUnit' -> Slot 'j' is empty.


message is generated by the 'put(...)' method. There, the model class is correctly assigned to 'eClasses' (see code snippet) but the method 'findEObjectsOfType' returns an empty list since 'resourceDescriptions.getAllResourceDescriptions();' returns an empty collection.
public void put(WorkflowContext ctx, IResourceDescriptions resourceDescriptions, ResourceSet resourceSet) {
		Set<EClass> eClasses = findEClasses(resourceSet, nsURI, type);
		List<EObject> elements = findEObjectsOfType(eClasses, resourceDescriptions, resourceSet);


How do I get my name provider properly registered? Do I have to set anything else, like dependencies to certain plugins, particular switches when running the workflow,... ? May the problem be caused by my setup, since I think that something in the injection process goes wrong? I am using XText (1.0.1) on Java version 1.5.0_24 (32Bit) on Mac OS 10.5.8.

Best,
Helge
Re: Xtext Reader for unnamed Grammar Element [message #642223 is a reply to message #642194] Tue, 30 November 2010 13:00 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
EDIT Never mind, didn't see that you already bound the class in the RuntimeModule.

[Updated on: Tue, 30 November 2010 13:02]

Report message to a moderator

Re: Xtext Reader for unnamed Grammar Element [message #642228 is a reply to message #642194] Tue, 30 November 2010 13:35 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

does your name provider extend DefaultDeclarativeQualifiedNameProvider?
Have you set a class breakpoint in order to see if your implementation was bound?
Have you tried using a general type in the qualifiedName-Method (EObject) for making sure that your implementation is used?

As to the binding, your code looks OK. Basically, you should be fine with copying the binding from the AbstractYOURDSLRuntimeModule returning your own implementation.

Alex
Previous Topic:How to run MWE2 code generator programmatically in the eclipse IDE plugin
Next Topic:Performance of saving a XtextResource
Goto Forum:
  


Current Time: Fri Apr 26 23:55:37 GMT 2024

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

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

Back to the top