Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » EnumLiteralDeclaration: problem getting the values of the reference
EnumLiteralDeclaration: problem getting the values of the reference [message #1153240] Thu, 24 October 2013 13:21 Go to next message
d 627 is currently offline d 627Friend
Messages: 28
Registered: March 2013
Junior Member
Hi there

I am kind of new in xtext, but I have been working in my project with some problems. One of this concerns the values of the references on EnumLiteralDeclaration. In theory there are two features supported: enumliteral and literal.

In my procedure when arrive an object of the EnumLiteralDeclaration kind, I am printing the two features inside the object just to try to understand what is happening.

As output I am having this:

quantity of references: 2

The references are: [org.eclipse.emf.ecore.impl.EReferenceImpl@93a061 (name: enumLiteral) (ordered: true, unique: true, lowerBound: 0, upperBound: 1) (changeable: true, volatile: false, transient: false, defaultValueLiteral: null, unsettable: false, derived: false) (containment: false, resolveProxies: true),
org.eclipse.emf.ecore.impl.EReferenceImpl@d7e37c (name: literal) (ordered: true, unique: true, lowerBound: 0, upperBound: 1) (changeable: true, volatile: false, transient: false, defaultValueLiteral: null, unsettable: false, derived: false) (containment: true, resolveProxies: false)]

- The value of literal is null.
The object is null

As you can see I am having the value of just one reference (literal) and not the value of enumLiteral even when I can see it with some values in its attributes. Instead of that I having a null object.

(Once again I am kind of new in xtext so I am also ignorant in some aspects, I hope you can understand that and can give a respectful answer).

Thanks a lot.

Regards.

[Updated on: Thu, 24 October 2013 14:57]

Report message to a moderator

Re: EnumLiteralDeclaration: problem getting the values of the reference [message #1153292 is a reply to message #1153240] Thu, 24 October 2013 14:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
Hi,

can you show with a grammar and example model what you actually want to achieve


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: EnumLiteralDeclaration: problem getting the values of the reference [message #1153352 is a reply to message #1153292] Thu, 24 October 2013 14:56 Go to previous messageGo to next message
d 627 is currently offline d 627Friend
Messages: 28
Registered: March 2013
Junior Member
Ok, this is the grammar that I am trying to understand

[Updated on: Thu, 24 October 2013 16:39]

Report message to a moderator

Re: EnumLiteralDeclaration: problem getting the values of the reference [message #1153354 is a reply to message #1153352] Thu, 24 October 2013 15:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
And what is what you want to do?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: EnumLiteralDeclaration: problem getting the values of the reference [message #1153401 is a reply to message #1153354] Thu, 24 October 2013 15:37 Go to previous messageGo to next message
d 627 is currently offline d 627Friend
Messages: 28
Registered: March 2013
Junior Member
The original for in the program was this:


 for (EReference refContainment : obj.eClass().getEAllContainments()) {
           //System.out.println("- il valore di " + refContainment.getName()  + " vale " + result);
            if (result instanceof EObject) {
                    navigateEObject((EObject) result,matchCollection, false);
            } else if (result instanceof EObjectContainmentEList) {
                    EObjectContainmentEList children = (EObjectContainmentEList) result;
                    for (Object child : children) { 
                            navigateEObject((EObject) child,matchCollection, false);
                    }
            } else {
                    System.out.println("It is not an object, it is a "
                                    + result.getClass().getCanonicalName());
                                }
                           }
                }



But when it was procesing an object instance of EnumLiteralDeclaration it was generating this exception:

Exception in thread "main" java.lang.NullPointerException

Modifing the procedure (the one that I have uploaded) I could see something releated with the enumLiteral feature, I don't understand why even when this feature is printing previously with some attributes I can not see it inside the for loop, and instead of that I am having this null object. That is my question.
Re: EnumLiteralDeclaration: problem getting the values of the reference [message #1153423 is a reply to message #1153401] Thu, 24 October 2013 15:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
Hi,

what i am is asking.
what should the code do?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: EnumLiteralDeclaration: problem getting the values of the reference [message #1153431 is a reply to message #1153423] Thu, 24 October 2013 15:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
Btw here a part of the Xtext Grammar to get a better IDEA

EnumLiteralDeclaration:
enumLiteral=[ecore::EEnumLiteral] ('=' literal=Keyword)?
;

enumLiteral is a (cross) reference, literal a (containment)Reference

in which line do you get the npe?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: EnumLiteralDeclaration: problem getting the values of the reference [message #1153516 is a reply to message #1153431] Thu, 24 October 2013 17:12 Go to previous messageGo to next message
d 627 is currently offline d 627Friend
Messages: 28
Registered: March 2013
Junior Member
Ok, Christian. This is not ALL the program. I just uploaded the part that I thought was enough to explain my doubt about some results. In the original program we need to process the results according some parameters, it's just that I can not post it totally because I could have some problems...
About the grammar, this is not mine, I just have to do some analysis without modify the original version.

With the for loop posted above, we are having this exception:

Exception in thread "main" java.lang.NullPointerException
at xtextupdating.Loader.navigateEObject(Loader.java:45)
at xtextupdating.Loader.navigateEObject(Loader.java:41)
at xtextupdating.Loader.navigateEObject(Loader.java:37)
at xtextupdating.Loader.navigateEObject(Loader.java:41)
at xtextupdating.Loader.main(Loader.java:68)

Wich I think correspond to a null value given instead the value of the enumLiteral feature( that is what we are trying to understand ).

Thanks a lot for you replay sorry for the inconvenience that we could give.

Regards
Re: EnumLiteralDeclaration: problem getting the values of the reference [message #1153534 is a reply to message #1153516] Thu, 24 October 2013 17:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
Still the question:
What is the input and what is the expected output.

--
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


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: EnumLiteralDeclaration: problem getting the values of the reference [message #1153552 is a reply to message #1153534] Thu, 24 October 2013 17:43 Go to previous messageGo to next message
d 627 is currently offline d 627Friend
Messages: 28
Registered: March 2013
Junior Member
Christian in the .zip that I uploaded there was the xtext project (the grammar and a class used to load it in a standalone Java application ), we were expecting to see something like this:

- The value of literal is null.
- The value of enumLiteral is ...


But instead of that we are having

- The value of literal is null.
The object is null.

Why the enumLiteral is not present in the output?,that is our question.

I am sorry for my English, this is not my native language and I am not so clear when I need to explain something using it.

Regards
Re: EnumLiteralDeclaration: problem getting the values of the reference [message #1153581 is a reply to message #1153552] Thu, 24 October 2013 18:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
hmmmm somehow there is no tar anymore.

never the less back to xtexts grammar itself:

EnumLiteralDeclaration:
    enumLiteral=[ecore::EEnumLiteral] ('=' literal=Keyword)?
;


this practically means in a grammar you could write
enum MyEnum :
	aEnumLiteral | anotherEnumLiteral="AndItsLiteral"
;


and here is the part of Xtexts Metamodel

  <eClassifiers xsi:type="ecore:EClass" name="EnumLiteralDeclaration" eSuperTypes="#//AbstractElement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="enumLiteral" eType="ecore:EClass platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore#//EEnumLiteral"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="literal" eType="#//Keyword"
        containment="true"/>
  </eClassifiers>


from the code you posted (no zip) i cannot see where you actually call
eobject.eGet(feature)


btw maybe the class XtextSwitch is a better way to traverse the grammar


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: EnumLiteralDeclaration: problem getting the values of the reference [message #1153613 is a reply to message #1153581] Thu, 24 October 2013 18:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
HI,

the file was still there in the newsgroup.
the problem is that the loaded resource had errors.
the following works for me

 StandaloneSetup standaloneSetup = new StandaloneSetup();
		standaloneSetup.setPlatformUri("../");
		standaloneSetup.addRegisterEcoreFile("platform:/resource/lala/src/VCML.ecore");
        Injector injector = new XtextStandaloneSetup().createInjectorAndDoEMFRegistration();
        XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
        
        
        URI uri1 = URI.createURI("platform:/resource/lala/src/a.xtext");
        
        Resource resourceVers1 = resourceSet.getResource(uri1, true);  
        EcoreUtil.resolveAll(resourceSet);
        System.out.println(resourceVers1.getErrors());
        EObject root = resourceVers1.getContents().get(0);
        navigateEObject(root);   


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: EnumLiteralDeclaration: problem getting the values of the reference [message #1161240 is a reply to message #1153613] Tue, 29 October 2013 17:22 Go to previous messageGo to next message
d 627 is currently offline d 627Friend
Messages: 28
Registered: March 2013
Junior Member
Thanks a lot Christian for your time. Now there is not problem with the grammar, but however the doubt is still the same, why the value of the enumLiteral feature is not display just like the value of literal? Now that were are not having npe.
Re: EnumLiteralDeclaration: problem getting the values of the reference [message #1161324 is a reply to message #1161240] Tue, 29 October 2013 18:38 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
hi,

what is the actual problem?
what do you mean with "just like" - one is a string, the other an object


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Grammer for UML-Association
Next Topic:how to open a file in the actual project
Goto Forum:
  


Current Time: Fri Jul 10 14:03:22 GMT 2020

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

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

Back to the top