ttben
ttben

Reputation: 113

Convert Spoon model into something else

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.

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

Answers (1)

Simon Urli
Simon Urli

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

Related Questions