Reputation: 113
I am trying to convert a Spoon representation
of a Java code into something else ; let say a JSON
or XML
representation or into other Java model
.
I am not sure how and where to start.
processor
for each leaf of Spoon's
metamodel (which is a lot of processors to write)? instanceof
checks)? Scanner
that is based on a tree-based representation?Last question: when converting an element (let say a CtIf
) how identifying its parent (a CtBlock
) in a unique way?
Let say that it will output the following:
[
{
type: block,
id: ???,
...,
},
...,
{
type: if,
parent: ???, (the block above)
...,
}
]
I am a bit lost and need some help :) Thanks!
Upvotes: 0
Views: 158
Reputation: 459
The easiest way to do that is to implement a custom pretty-printer (look on https://github.com/INRIA/spoon/blob/master/src/main/java/spoon/reflect/visitor/DefaultJavaPrettyPrinter.java) and to pass it to a Launcher by overriding it.
Upvotes: 1