I am looking for a way to analyze the Java code and programmatically modify them,
For example, the code may be like this:
@FindBy(id = "login")
WebElement btnLogin;
@FindBy(xpath = "//div/a")
List<WebElement> aNodes;
and I’d hope to check every field that is annotated by @FindBy, and change the annotation @FindBy into @Synchronized.
that is:
@Synchronized
WebElement btnLogin;
@Synchronized
List<WebElement> aNodes;
Unlike the similar questions I found (they use javassist or ASM to modify the bytecode), these annotation will be removed at runtime, so I can only do it in source code level but not in the bytecode level.
So far, I have find qdox, but seems it can only analyze the code but cannot modify it.
And I tried to write regex myself to solve it, but it seems a too much huge project.
Any recommendations on this?
The regular expression for this should be very simple
Match any line starting with
or, if you’re worried about an odd (but valid) syntax (@FindBy(blah) protected void ..)
That said, you can also use your favorite IDE to do a search and replace manually (Eclipse, IntelliJ, or even emacs should be able to do this across all files), since you seem to be doing this statically