Does your transform extend ClassCodeExpressionTransformer (like NewifyASTTransformation)? Depending on how you have set things up, you might need to.
Cheers, Paul. On Thu, Nov 10, 2016 at 9:46 AM, Gowtham Sridharan <gowtham.sridha...@gmail.com> wrote: > Hi > Here is my usecase. I am running on version 2.1.6 > > I am trying to convert all array declarations to a more custom datatype > which is not exposed to the end user. > > For ex: > > def strr = new String[4] will be modified to def strr=new > mycustomType(datatypeForString,4) > > def str = [1,2,3] as String[] will be modified to def str=new > myCustomType(dataTypeForString,list) > > So far at the AST level, I registered a custom visitor and > visitDeclarationExpression(). > I am currently compiling the user script using custom GroovyClassLoader and > executing it on the fly using > myclassLoader.parseClass(usertext).newInstance().run() > > > When I am executing the above the sequence(compiling,loading,executing) the > AST transformations are executed(verified through sys printls) but the final > code execution does not reflect it. > > Here is the snippet of the code that modifies the expression and sets it to > the parent. > > @Override > public void visitDeclarationExpression(DeclarationExpression > expression) { > // TODO Auto-generated method stub > > if (expression.getLeftExpression() instanceof VariableExpression > && expression.getRightExpression() instanceof > ArrayExpression) { > > // Inspect the arrayExpressio > > expression.setRightExpression(transformArrayExpression((ArrayExpression) > expression.getRightExpression())); > > > > } > > else if (expression.getLeftExpression() instanceof > VariableExpression > && expression.getRightExpression() instanceof > CastExpression) { > // Inspect the cast expression > > expression.setRightExpression(transformCastExpression((CastExpression) > expression.getRightExpression())); > } > > super.visitDeclarationExpression(expression); > } > > > > Any pointers? > >