I’m working on some upkeep for a monolithic java codebase, where it was discovered that some of the @GET methods will actually start a write session, and should thus actually be @POST methods. I wrote the following regex to aide my search:
@GET[^}]+startWrite
This gave me all occurrences of the @GET annotation which reached a string ‘startWrite’ (which is part of the method names that start a write session) before reaching a ‘}’, which is used to close a method in java. This solution is not perfect, as it is possible that a } is used inside a method before a write session is started (for instance in an if-statement), but it proofed effective enough to work with.
However, it has since come to my attention that a lot of the methods follow this format:
@GET
@Path("/methodName")
public ObjectName methodName(...){
...
return methodNameInner(...);
}
private methodNameInner(...){
startWriteSession();
...
}
In other words, the write session command is moved to another method, which always bears the same name as the original method (and the pathname), followed by ‘Inner’. this inner method is always below the original method. I tried to write a regex that searched for occurences of @GET, followed by some strings until either the path name or the method name (which I isolated in a separate group), followed by more characters, followed by 1Inner, followed by the same [^}]+startWrite, meaning the inner method reached a ‘startWrite’ string before it reached the end of the method. But I could not get it to work.
Could someone please assist me?