Re: AST to add a new class

2021-04-12 Thread Saravanan Palanichamy
Thanks paul,

This worked like a charm. I used the module node from one of the other
classes and added this parent level class along with all its static inner
classes

regards
Saravanan

On Mon, Apr 12, 2021 at 5:51 PM Paul King  wrote:

> It depends on how you have this set up. If you are compiling your other
> classes at the same time, I'd just get the module node from one of those
> classes and add your new class to it.
>
> Cheers, Paul.
>
>
> On Mon, Apr 12, 2021 at 9:34 PM Saravanan Palanichamy 
> wrote:
>
>> Hello paul
>>
>> Thank you for your email
>>
>> Yes the inner class mechanism works, but I want to declare a parent class
>> dynamically with static inner classes added dynamically
>>
>> With inner classes I jave access to the module node and the source unit.
>> Where do I get these for a parent level class?
>>
>> On Mon, 12 Apr, 2021, 16:52 Paul King,  wrote:
>>
>>> The Builders and Sortable AST do something similar and use:
>>>
>>> https://github.com/apache/groovy/blob/master/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java#L129
>>>
>>>
>>> On Mon, Apr 12, 2021 at 8:36 PM Saravanan Palanichamy <
>>> chava...@gmail.com> wrote:
>>>
 Hello

 What is the right way to add a new class through an AST during the
 Groovy compilation phase? What I am trying to do is this

 * Compile N different classes
 * During the compile process, create a new class for each of these N
 classes that denotes how it should be serialized (for example)
 * Add these classes as sub classes of one master class, called Types

 For example:-

 / These are my classes /
 Class Car {
 }

 class Cycle {
 }


 /* This class must be auto generated with all of its
 inner classes ***/
 class Types {
 static class CarSeralizer extends TypeReference {}

 static class CycleSerializer extends TypeReference {}
 }

 How do I achieve this through ASTs ?

 regards
 Saravanan

>>>


Re: AST to add a new class

2021-04-12 Thread Saravanan Palanichamy
Hello paul

Thank you for your email

Yes the inner class mechanism works, but I want to declare a parent class
dynamically with static inner classes added dynamically

With inner classes I jave access to the module node and the source unit.
Where do I get these for a parent level class?

On Mon, 12 Apr, 2021, 16:52 Paul King,  wrote:

> The Builders and Sortable AST do something similar and use:
>
> https://github.com/apache/groovy/blob/master/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java#L129
>
>
> On Mon, Apr 12, 2021 at 8:36 PM Saravanan Palanichamy 
> wrote:
>
>> Hello
>>
>> What is the right way to add a new class through an AST during the Groovy
>> compilation phase? What I am trying to do is this
>>
>> * Compile N different classes
>> * During the compile process, create a new class for each of these N
>> classes that denotes how it should be serialized (for example)
>> * Add these classes as sub classes of one master class, called Types
>>
>> For example:-
>>
>> / These are my classes /
>> Class Car {
>> }
>>
>> class Cycle {
>> }
>>
>>
>> /* This class must be auto generated with all of its
>> inner classes ***/
>> class Types {
>> static class CarSeralizer extends TypeReference {}
>>
>> static class CycleSerializer extends TypeReference {}
>> }
>>
>> How do I achieve this through ASTs ?
>>
>> regards
>> Saravanan
>>
>


Re: AST to add a new class

2021-04-12 Thread Paul King
The Builders and Sortable AST do something similar and use:
https://github.com/apache/groovy/blob/master/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java#L129


On Mon, Apr 12, 2021 at 8:36 PM Saravanan Palanichamy 
wrote:

> Hello
>
> What is the right way to add a new class through an AST during the Groovy
> compilation phase? What I am trying to do is this
>
> * Compile N different classes
> * During the compile process, create a new class for each of these N
> classes that denotes how it should be serialized (for example)
> * Add these classes as sub classes of one master class, called Types
>
> For example:-
>
> / These are my classes /
> Class Car {
> }
>
> class Cycle {
> }
>
>
> /* This class must be auto generated with all of its inner
> classes ***/
> class Types {
> static class CarSeralizer extends TypeReference {}
>
> static class CycleSerializer extends TypeReference {}
> }
>
> How do I achieve this through ASTs ?
>
> regards
> Saravanan
>