简体   繁体   中英

Remove all annotations in Java source code and get new source code

I am looking for ways to remove all the annotations from existing Java Source Code. I am looking for an ant task or any other approach. I have seen some solutions that do this at the class level, but I am looking to do this at the source code to source code level.

I have done this through Java Parser code available in Lombok.

Look at these methods which has the logic

lombok.javac.handlers.JavacHandlerUtil#deleteAnnotationIfNecessary lombok.javac.handlers.JavacHandlerUtil#deleteImportFromCompilationUnit

I ended up using JEdit which has brilliant regular expression support.

I wanted to replace specific annotations (I wanted to keep stuff like @Override ). You can easily do that for all buffers or a directory tree.

Just write some simple expressions for the annotations you want to remove. For example

^\s*@NamedQueries\(\n\{[^\}]+\}\)\n

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM