0

This question might sound duplicate of this question but they are not the same. I am dealing with some legacy code in which logging was done at entry and exit of most (not all) of the functions of a some (not all) classes. This logging at the two points was added programmatically using Antlr or some similar tool. Now what I have is that legacy code which I want to migrate to the new style. The new style should add an annotation (which would instrument the code to add logging at entry and exit) at the top of each of those functions which had these type of logging and removing the code from those functions.

Taking the approach of Antlr to do this task is problematic because it is unable to understand the new syntax and semantics of Java and fails at multiple places. So what could be the best approach to for this problem?

Community
  • 1
  • 1
Siddharth
  • 2,046
  • 5
  • 26
  • 41
  • Is this a one-time job? How many files are to be modified? – SubOptimal May 19 '15 at 07:08
  • Yes, this migration will be a one time job for a project. Files could be in order of a few hundreds. – Siddharth May 19 '15 at 07:16
  • You could have a look at [JavaParser](http://javaparser.github.io/javaparser/). But even it would be a boring task. It might be faster to search the method calls in your IDE and enter the annotation yourself instead fo searching a framework which could be instrumented for this job. Another "quick-and-dirty" programmatic solution could be read all files line by line, check if a method call the legacy logging, if so add the annotation and comment out the legacy call. Use your IDE for cosmetic tuning (indention, formatting, etc.). But for all my proposals: `It depends on your specific case.` – SubOptimal May 19 '15 at 08:16

1 Answers1

0

When maintainability is concerned, keeping the ANTLR based (or for that matter any custom code generation utility) is going to be a challenge especially when there are language changes.

I believe that you could look at the following:

  1. AspectJ
  2. Spring AOP

NOTE: When looking at 3rd party libraries, make sure that the library is being maintained and it fits your requirements without having to customize it much.

MJSG
  • 1,035
  • 8
  • 12