Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Could anybody provide some information about NodeModelUtils?(xtext NodeModelUtils)
icon5.gif  Could anybody provide some information about NodeModelUtils? [message #1040883] Sun, 14 April 2013 08:31 Go to next message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 107
Registered: April 2013
Senior Member
I am searching examples of NodeModelUtils, but only found http://download.eclipse.org/modeling/tmf/xtext/javadoc/2.0.1/org/eclipse/xtext/nodemodel/util/NodeModelUtils.html. I would like to use NodeModeUtils to traverse the parse tree of code in a class. Could anybody provide me some more information? Thank you in advance!
Re: Could anybody provide some information about NodeModelUtils? [message #1040985 is a reply to message #1040883] Sun, 14 April 2013 12:22 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2013-14-04 10:31, Hao Zhang wrote:
> I am searching examples of NodeModelUtils, but only found
> http://download.eclipse.org/modeling/tmf/xtext/javadoc/2.0.1/org/eclipse/xtext/nodemodel/util/NodeModelUtils.html.
> I would like to use NodeModeUtils to traverse the parse tree of code in
> a class. Could anybody provide me some more information? Thank you in
> advance!
The NodeModel is for traversing the source text. Is that what you want
(as opposed to traversing the constructed model)?

If you need to traverse the NodeModel, there is quite a lot to learn to
fully understand how the node model describes how the text was parsed.
Afaik, there is no documentation of all these details.

Simple things are still simple though - find the text for a semantic
element etc.

I do quite a lot with nodes in the serializer and formatter in
cloudsmith / geppetto @ github - should be plenty of code to look at
there. Other than that - the debugger is your friend.

Regards
- henrik
Re: Could anybody provide some information about NodeModelUtils? [message #1041019 is a reply to message #1040985] Sun, 14 April 2013 13:36 Go to previous messageGo to next message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 107
Registered: April 2013
Senior Member
Thank you for your reply!
Currently, I am following the "domain-model" example in the xText 2.4. After I create and save the ".dmodel" file, I would like to see the automatically generated class diagram of all the classes which are defined in the ".dmodel" file, like the UML class diagram. For the behaviors (functions) of each class, I would like to show these behaviors in the activity diagrams as the UML, including everything even comments defined in the behavior. These activity diagrams are also automatically generated after I save the ".dmodel" file.
I saw the https://github.com/cloudsmith/geppetto, it seems really very complex. Honestly, I have no idea about what is source text and what is constructed model. Could you see what I am going to do is related with source text or constructed model? Thank you!
Henrik Lindberg wrote on Sun, 14 April 2013 08:22
On 2013-14-04 10:31, Hao Zhang wrote:
> I am searching examples of NodeModelUtils, but only found
> http://download.eclipse.org/modeling/tmf/xtext/javadoc/2.0.1/org/eclipse/xtext/nodemodel/util/NodeModelUtils.html.
> I would like to use NodeModeUtils to traverse the parse tree of code in
> a class. Could anybody provide me some more information? Thank you in
> advance!
The NodeModel is for traversing the source text. Is that what you want
(as opposed to traversing the constructed model)?

If you need to traverse the NodeModel, there is quite a lot to learn to
fully understand how the node model describes how the text was parsed.
Afaik, there is no documentation of all these details.

Simple things are still simple though - find the text for a semantic
element etc.

I do quite a lot with nodes in the serializer and formatter in
cloudsmith / geppetto @ github - should be plenty of code to look at
there. Other than that - the debugger is your friend.

Regards
- henrik

[Updated on: Sun, 14 April 2013 13:57]

Report message to a moderator

Re: Could anybody provide some information about NodeModelUtils? [message #1041043 is a reply to message #1041019] Sun, 14 April 2013 14:29 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2013-14-04 15:36, Hao Zhang wrote:
> Thank you for your reply!
> Currently, I am following the "domain-model" example in the xText 2.4.
> After I create and save the ".dmodel" file, I would like to see the
> class diagram of all the classes which are defined in the ".dmodel"
> file, like the UML class diagram. For the behaviors (functions) of each
> class, I would like to show these behaviors in the activity diagrams as
> the UML, including everything even comments defined in the behavior. I
> saw the https://github.com/cloudsmith/geppetto, it seems really very
> complex. Honestly, I have no idea about what is source text and what is
> constructed model. Could you see what I am going to do is related with
> source text or constructed mode? Thank you!

If you want a diagram, just create one based on the metamodel that Xtext
generated for your grammar.

For instances of the metamodel, you need to first install the support,
then use EMF to open the source files as any other modeling resources. I
have no clue how to create UML activity diagrams from them though...

You do not need to deal with the NodeModel. The things in Geppetto I
pointed you to are not relevant for what you want to do.

- henrik

> Henrik Lindberg wrote on Sun, 14 April 2013 08:22
>> On 2013-14-04 10:31, Hao Zhang wrote:
>> > I am searching examples of NodeModelUtils, but only found
>> >
>> http://download.eclipse.org/modeling/tmf/xtext/javadoc/2.0.1/org/eclipse/xtext/nodemodel/util/NodeModelUtils.html.
>>
>> > I would like to use NodeModeUtils to traverse the parse tree of code in
>> > a class. Could anybody provide me some more information? Thank you in
>> > advance!
>> The NodeModel is for traversing the source text. Is that what you want
>> (as opposed to traversing the constructed model)?
>>
>> If you need to traverse the NodeModel, there is quite a lot to learn
>> to fully understand how the node model describes how the text was
>> parsed. Afaik, there is no documentation of all these details.
>>
>> Simple things are still simple though - find the text for a semantic
>> element etc.
>>
>> I do quite a lot with nodes in the serializer and formatter in
>> cloudsmith / geppetto @ github - should be plenty of code to look at
>> there. Other than that - the debugger is your friend.
>>
>> Regards
>> - henrik
>
Re: Could anybody provide some information about NodeModelUtils? [message #1041053 is a reply to message #1041043] Sun, 14 April 2013 14:47 Go to previous messageGo to next message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 107
Registered: April 2013
Senior Member
Thank you very much!
Maybe the difficulty comes from the automatic generation of the activity diagrams. The reason is that I have to traverse the different kinds of XExpression written in the behaviors (functions) if I want to automatically generate an activity diagram.

[Updated on: Sun, 14 April 2013 14:52]

Report message to a moderator

Re: Could anybody provide some information about NodeModelUtils? [message #1041057 is a reply to message #1041053] Sun, 14 April 2013 14:53 Go to previous messageGo to next message
Steve Kallestad is currently offline Steve KallestadFriend
Messages: 62
Registered: March 2013
Member
There is a pretty cool diagram thing out of the box. Window->Show View->Other->Xtext->Xtext Syntax Graph

It's for looking at .xtext files, not for dsl source files, but the code might be an interesting reference.
Re: Could anybody provide some information about NodeModelUtils? [message #1041063 is a reply to message #1041057] Sun, 14 April 2013 15:04 Go to previous messageGo to next message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 107
Registered: April 2013
Senior Member
Thank you very much!
It looks really very interesting. "but the code might be an interesting reference" Where could I see the "code"?

Steve Kallestad wrote on Sun, 14 April 2013 10:53
There is a pretty cool diagram thing out of the box. Window->Show View->Other->Xtext->Xtext Syntax Graph

It's for looking at .xtext files, not for dsl source files, but the code might be an interesting reference.
Re: Could anybody provide some information about NodeModelUtils? [message #1041073 is a reply to message #1041063] Sun, 14 April 2013 15:21 Go to previous messageGo to next message
Steve Kallestad is currently offline Steve KallestadFriend
Messages: 62
Registered: March 2013
Member
I *think* this is it. http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/plain/plugins/org.eclipse.xtext.xtext.ui.graph/src/org/eclipse/xtext/xtext/ui/graph/RailroadView.java

I found it by referencing this: https://github.com/JanKoehnlein/Xtext-Syntax-View/blob/master/org.eclipse.xtext.graph/plugin.xml

Specifically this line:
class="org.eclipse.xtext.graph.bundle.RailroadViewExecutableExtensionRegistry:org.eclipse.xtext.graph.RailroadView"


Re: Could anybody provide some information about NodeModelUtils? [message #1041078 is a reply to message #1041073] Sun, 14 April 2013 15:26 Go to previous messageGo to next message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 107
Registered: April 2013
Senior Member
Thank you very much!
I would like to generate code based on the elements which are defined in Syntax Graphs, is it possible?

Steve Kallestad wrote on Sun, 14 April 2013 11:21
I *think* this is it. http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/plain/plugins/org.eclipse.xtext.xtext.ui.graph/src/org/eclipse/xtext/xtext/ui/graph/RailroadView.java

I found it by referencing this: https://github.com/JanKoehnlein/Xtext-Syntax-View/blob/master/org.eclipse.xtext.graph/plugin.xml

Specifically this line:
class="org.eclipse.xtext.graph.bundle.RailroadViewExecutableExtensionRegistry:org.eclipse.xtext.graph.RailroadView"



[Updated on: Sun, 14 April 2013 15:29]

Report message to a moderator

Re: Could anybody provide some information about NodeModelUtils? [message #1042326 is a reply to message #1040985] Tue, 16 April 2013 09:26 Go to previous messageGo to next message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 107
Registered: April 2013
Senior Member
I checked the webpage https://github.com/cloudsmith/geppetto.
I can see you really did much work abut the node model. If I have the following function. How could I get the text and type of the "if ", "else", and the other statements, such as "getUp", "haveBreakfast", "sleep"?
op activityInOneDay(): void {
if (getUp())
{
haveBreakfast();

}
else
{
sleep();
}
workAtHome();
haveLunch();
}
Henrik Lindberg wrote on Sun, 14 April 2013 08:22
On 2013-14-04 10:31, Hao Zhang wrote:
> I am searching examples of NodeModelUtils, but only found
> http://download.eclipse.org/modeling/tmf/xtext/javadoc/2.0.1/org/eclipse/xtext/nodemodel/util/NodeModelUtils.html.
> I would like to use NodeModeUtils to traverse the parse tree of code in
> a class. Could anybody provide me some more information? Thank you in
> advance!
The NodeModel is for traversing the source text. Is that what you want
(as opposed to traversing the constructed model)?

If you need to traverse the NodeModel, there is quite a lot to learn to
fully understand how the node model describes how the text was parsed.
Afaik, there is no documentation of all these details.

Simple things are still simple though - find the text for a semantic
element etc.

I do quite a lot with nodes in the serializer and formatter in
cloudsmith / geppetto @ github - should be plenty of code to look at
there. Other than that - the debugger is your friend.

Regards
- henrik

Re: Could anybody provide some information about NodeModelUtils? [message #1042444 is a reply to message #1042326] Tue, 16 April 2013 12:50 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Don't understand your question, unless you are asking the obvious.

The parser produces a model. You traverse this model using explicit
navigation (using getters), or iteration (eAllContents). When you have
the model element you can get all other information (its type, parent,
content, its features, etc.). You use NodeModelUtils to find the
corresponding textual INode that containes the actual parsed text and
information about how the parser decided that that piece of text should
result in the constructed model element.

Armed with this information, you should be able to do the rest by just
looking at the available methods in NodeModelUtils, in the methods on
the nodes, etc.

Regards
- henrik

On 2013-16-04 11:26, Hao Zhang wrote:
> I checked the webpage https://github.com/cloudsmith/geppetto.
> I can see you really did much work abut the node model. If I have the
> following function. How could I get the text and type of the "if ",
> "else", and the other statements, such as "getUp", "haveBreakfast",
> "sleep"? op activityInOneDay(): void {
> if (getUp())
> {
> haveBreakfast();
>
> }
> else
> {
> sleep();
> }
> workAtHome();
> haveLunch();
> }
> Henrik Lindberg wrote on Sun, 14 April 2013 08:22
>> On 2013-14-04 10:31, Hao Zhang wrote:
>> > I am searching examples of NodeModelUtils, but only found
>> >
>> http://download.eclipse.org/modeling/tmf/xtext/javadoc/2.0.1/org/eclipse/xtext/nodemodel/util/NodeModelUtils.html.
>>
>> > I would like to use NodeModeUtils to traverse the parse tree of code in
>> > a class. Could anybody provide me some more information? Thank you in
>> > advance!
>> The NodeModel is for traversing the source text. Is that what you want
>> (as opposed to traversing the constructed model)?
>>
>> If you need to traverse the NodeModel, there is quite a lot to learn
>> to fully understand how the node model describes how the text was
>> parsed. Afaik, there is no documentation of all these details.
>>
>> Simple things are still simple though - find the text for a semantic
>> element etc.
>>
>> I do quite a lot with nodes in the serializer and formatter in
>> cloudsmith / geppetto @ github - should be plenty of code to look at
>> there. Other than that - the debugger is your friend.
>>
>> Regards
>> - henrik
>
>
Re: Could anybody provide some information about NodeModelUtils? [message #1042454 is a reply to message #1042444] Tue, 16 April 2013 13:06 Go to previous message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 107
Registered: April 2013
Senior Member
Thank you for your reply!
I am following the "domain-model" in the xText 2.4. In the "Domainmodel.xtext", I have the following definition of the "Operation".

Operation:
'op' name=ValidID '(' (params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)? ')' (':' type=JvmTypeReference)?
body=XBlockExpression;

In the "DomainmodelGenerator.xtend", I would like to print the "body" of the "op activityInOneDay" method automatically, and get the following string in a ".txt" file.

@startuml
(*) --> if "getUp" then
-->[true] "haveBreakfast"
else
->[false] "sleep"
endif
--> "workAtHome"
--> "haveLunch"
--> (*)
@enduml


Currently, with Christian's help, I have the following "print" method, but with this method, I cannot get the above string in the ".txt" file.
I think I did not get the right method to traverse the "XBlockExpression".
Could you have some idea? Thank you in advance!

def dispatch print(XBlockExpression e)'''
{
«FOR ex : e.expressions»
«val curExpressionNode = NodeModelUtils::findActualNodeFor(ex)»
«val NodeStr = NodeModelUtils::compactDump(curExpressionNode, true)»
«val curGrammarStr = curExpressionNode.grammarElement»
«val curSematicStr = curExpressionNode.semanticElement»
«val curStr = curExpressionNode.startLine.toString»
«ENDFOR»

««« «val node = NodeModelUtils::findActualNodeFor(operation)»
««« «FOR oneNode : node.getAsTreeIterable()»
««« «oneNode.print»
««« «ENDFOR»
}
'''

Henrik Lindberg wrote on Tue, 16 April 2013 08:50
Don't understand your question, unless you are asking the obvious.

The parser produces a model. You traverse this model using explicit
navigation (using getters), or iteration (eAllContents). When you have
the model element you can get all other information (its type, parent,
content, its features, etc.). You use NodeModelUtils to find the
corresponding textual INode that containes the actual parsed text and
information about how the parser decided that that piece of text should
result in the constructed model element.

Armed with this information, you should be able to do the rest by just
looking at the available methods in NodeModelUtils, in the methods on
the nodes, etc.

Regards
- henrik

On 2013-16-04 11:26, Hao Zhang wrote:
> I checked the webpage https://github.com/cloudsmith/geppetto.
> I can see you really did much work abut the node model. If I have the
> following function. How could I get the text and type of the "if ",
> "else", and the other statements, such as "getUp", "haveBreakfast",
> "sleep"? op activityInOneDay(): void {
> if (getUp())
> {
> haveBreakfast();
>
> }
> else
> {
> sleep();
> }
> workAtHome();
> haveLunch();
> }
> Henrik Lindberg wrote on Sun, 14 April 2013 08:22
>> On 2013-14-04 10:31, Hao Zhang wrote:
>> > I am searching examples of NodeModelUtils, but only found
>> >
>> http://download.eclipse.org/modeling/tmf/xtext/javadoc/2.0.1/org/eclipse/xtext/nodemodel/util/NodeModelUtils.html.
>>
>> > I would like to use NodeModeUtils to traverse the parse tree of code in
>> > a class. Could anybody provide me some more information? Thank you in
>> > advance!
>> The NodeModel is for traversing the source text. Is that what you want
>> (as opposed to traversing the constructed model)?
>>
>> If you need to traverse the NodeModel, there is quite a lot to learn
>> to fully understand how the node model describes how the text was
>> parsed. Afaik, there is no documentation of all these details.
>>
>> Simple things are still simple though - find the text for a semantic
>> element etc.
>>
>> I do quite a lot with nodes in the serializer and formatter in
>> cloudsmith / geppetto @ github - should be plenty of code to look at
>> there. Other than that - the debugger is your friend.
>>
>> Regards
>> - henrik
>
>

[Updated on: Tue, 16 April 2013 13:07]

Report message to a moderator

Previous Topic:Extend xbase expressions
Next Topic:Difference between JVMInferrer and Generator
Goto Forum:
  


Current Time: Thu Mar 28 10:38:05 GMT 2024

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

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

Back to the top