1

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.

2
  • 1
    You could probably use some kind of script - try grep -v or some clever sed, but it would help to know what you are trying to achieve, because annotations are used for a lot of different things today, and to remove them all indiscriminately is potentially a bad idea... Commented Aug 22, 2013 at 12:19
  • I am looking to use annotations for server side, but same code, we need to use on device side, some devices such as JavaME does not support annotations. Hence, at build time. I could do search and replace.. but I am looking for engineering solution so that, mistakes can be less in future. Commented Aug 23, 2013 at 14:58

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.