Re: AST to replace `==` with `equals` method invocation

2018-06-16 Thread Paolo Di Tommaso
Thanks Mario,

Looking at Asteroid code put me in the right direction. In a nutshell it is
not possible to mix ClassCodeVisitorSupport logic with class
ClassCodeExpressionTransformer
one. I need to use two different classes.


p

On Wed, Jun 13, 2018 at 9:52 AM, Mario Garcia  wrote:

> Hi Paolo:
>
> A couple of years ago I created Asteroid (https://github.com/grooviter/
> asteroid) a library to deal with AST transformations. I needed to create
> a minor release so I've taken the oportunity to solve this problem and I
> think is pretty easy.
>
>- Create a Transformer. A transformer is just a class transforming a
>specific type of node, and it uses a criteria to filter nodes.
>- Create a Global transformation that includes the previous
>transformer to apply it to the whole codebase
>- Test that the AST generated has changed from a BinaryExpression to a
>MethodCallExpression
>- Profit :)
>
> You can find the source code here:
>
>- Transformer: https://github.com/grooviter/asteroid/blob/
>master/asteroid-test/src/main/groovy/asteroid/global/samples/
>ChangeEqualsTransformer.groovy
>
> 
>
>- Transformation: https://github.com/grooviter/asteroid/
>blob/master/asteroid-test/src/main/groovy/asteroid/global/samples/
>ChangeEqualsTransformation.groovy
>
> 
>- Test: https://github.com/grooviter/asteroid/blob/
>master/asteroid-test/src/test/groovy/asteroid/global/samples/
>ChangeEqualsTransformationSpec.groovy
>
> 
>
> You can find also some documentation at: http://grooviter.github.
> io/asteroid/
>
> Of course any feedback on the library is appreciated :)
>
> I hope this helps
> Mario
>
> 2018-06-10 21:27 GMT+02:00 MG :
>
>> Hi Paolo,
>>
>> I have not used it myself, but have you had a look at the new Groovy 2.5
>> "abstract syntax tree search and replace"-feature (
>> http://groovy-lang.org/releasenotes/groovy-2.5.html & search for "AST
>> matching") ?
>>
>> Cheers,
>> mg
>>
>>
>>
>> On 10.06.2018 16:55, Paolo Di Tommaso wrote:
>>
>> Dear all,
>>
>> I'm trying to implement an AST transformation to replace any `==` binary
>> expression with a equals method call invocation as suggested here
>> 
>> .
>>
>>
>> My understanding is that it's required to override each the visitor for
>> each node where a binary expression can appear ie. if statement, while
>> statement, assignment, for loop, method call, etc.
>>
>> That looks a bit overkill. I was wondering if there's a better way to
>> replace globally all `==` binary expressions with `equals` method
>> invocations.
>>
>>
>> Cheers,
>> Paolo
>>
>>
>>
>


Re: AST to replace `==` with `equals` method invocation

2018-06-13 Thread Mario Garcia
Hi Paolo:

A couple of years ago I created Asteroid (
https://github.com/grooviter/asteroid) a library to deal with AST
transformations. I needed to create a minor release so I've taken the
oportunity to solve this problem and I think is pretty easy.

   - Create a Transformer. A transformer is just a class transforming a
   specific type of node, and it uses a criteria to filter nodes.
   - Create a Global transformation that includes the previous transformer
   to apply it to the whole codebase
   - Test that the AST generated has changed from a BinaryExpression to a
   MethodCallExpression
   - Profit :)

You can find the source code here:

   - Transformer:
   
https://github.com/grooviter/asteroid/blob/master/asteroid-test/src/main/groovy/asteroid/global/samples/ChangeEqualsTransformer.groovy

   - Transformation:
   
https://github.com/grooviter/asteroid/blob/master/asteroid-test/src/main/groovy/asteroid/global/samples/ChangeEqualsTransformation.groovy
   - Test:
   
https://github.com/grooviter/asteroid/blob/master/asteroid-test/src/test/groovy/asteroid/global/samples/ChangeEqualsTransformationSpec.groovy

You can find also some documentation at:
http://grooviter.github.io/asteroid/

Of course any feedback on the library is appreciated :)

I hope this helps
Mario

2018-06-10 21:27 GMT+02:00 MG :

> Hi Paolo,
>
> I have not used it myself, but have you had a look at the new Groovy 2.5
> "abstract syntax tree search and replace"-feature (http://groovy-lang.org/
> releasenotes/groovy-2.5.html & search for "AST matching") ?
>
> Cheers,
> mg
>
>
>
> On 10.06.2018 16:55, Paolo Di Tommaso wrote:
>
> Dear all,
>
> I'm trying to implement an AST transformation to replace any `==` binary
> expression with a equals method call invocation as suggested here
> 
> .
>
>
> My understanding is that it's required to override each the visitor for
> each node where a binary expression can appear ie. if statement, while
> statement, assignment, for loop, method call, etc.
>
> That looks a bit overkill. I was wondering if there's a better way to
> replace globally all `==` binary expressions with `equals` method
> invocations.
>
>
> Cheers,
> Paolo
>
>
>


Re: AST to replace `==` with `equals` method invocation

2018-06-10 Thread MG

Hi Paolo,

I have not used it myself, but have you had a look at the new Groovy 2.5 
"abstract syntax tree search and replace"-feature 
(http://groovy-lang.org/releasenotes/groovy-2.5.html & search for "AST 
matching") ?


Cheers,
mg


On 10.06.2018 16:55, Paolo Di Tommaso wrote:

Dear all,

I'm trying to implement an AST transformation to replace any `==` 
binary expression with a equals method call invocation as suggested 
here 
.



My understanding is that it's required to override each the visitor 
for each node where a binary expression can appear ie. if statement, 
while statement, assignment, for loop, method call, etc.


That looks a bit overkill. I was wondering if there's a better way to 
replace globally all `==` binary expressions with `equals` method 
invocations.



Cheers,
Paolo





AST to replace `==` with `equals` method invocation

2018-06-10 Thread Paolo Di Tommaso
Dear all,

I'm trying to implement an AST transformation to replace any `==` binary
expression with a equals method call invocation as suggested here

.


My understanding is that it's required to override each the visitor for
each node where a binary expression can appear ie. if statement, while
statement, assignment, for loop, method call, etc.

That looks a bit overkill. I was wondering if there's a better way to
replace globally all `==` binary expressions with `equals` method
invocations.


Cheers,
Paolo