Home » Modeling » TMF (Xtext) » Could anybody provide some information about NodeModelUtils?(xtext NodeModelUtils)
| |
Re: Could anybody provide some information about NodeModelUtils? [message #1041019 is a reply to message #1040985] |
Sun, 14 April 2013 13:36 |
Hao Zhang 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:22On 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 |
Henrik Lindberg 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 #1042326 is a reply to message #1040985] |
Tue, 16 April 2013 09:26 |
Hao Zhang 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:22On 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 |
Henrik Lindberg 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 |
Hao Zhang 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:50Don'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
|
|
|
Goto Forum:
Current Time: Wed Sep 25 12:25:32 GMT 2024
Powered by FUDForum. Page generated in 0.06024 seconds
|