I am able to add an annotation like this.using this code - public@RequestMappingStringexecute
It should be before the qualifier 'public' like this - @RequestMapping publicStringexecute
public void enterMethodDeclaration(JavaParser.MethodDeclarationContext ctx){
if( ctx.getText().contains( "execute" )) {
System.out.println("Method Declaration Context [" + ctx.getChild(1).getText() + "]");
rewriter.insertBefore( ctx.start, "@RequestMapping");
}
}
How is that done ?
Update 1 : getChild(0) gives me the return type of the method. But I want to add the annotation before the 'public' qualifier.
Update 2 : When I look at Java.G4 I see 'classOrInterfaceModifier' which is misleading. And the method modifier is not part of the
coontext. But one could parse at a higher level and get at this. It worked.
Thanks,
Mohan