Add java annotation before method

14 views
Skip to first unread message

Mohan Radhakrishnan

unread,
Jun 21, 2016, 5:14:35 AM6/21/16
to antlr-di...@googlegroups.com
Hi,

    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
Reply all
Reply to author
Forward
0 new messages