Tutorial :Get code file version diff showing methods (names) impacted


I want to get a diff between two versions of a code file (of the Java/C#) variety - and from that get a list of methods (names) impacted. Has this been implemented?

I presume this would require an AST Analysis of the lines that come back from the diff.

The point of this would be to refine checkstyle/findbugs to just work on the methods touched during a Sprint.

I had a look at eclipse's process for doing a diff:


It looks like it just works on line number - not an actual AST. I'm interested in the line#=>methodName mapping.


You can use the compare api of eclipse, even without using eclipse itself. Search org.eclipse.compare


I don't know if this will/can help you, but the diff/compare in Eclipse does this in it's top panel (below that are the two files/versions side by side). Graphical, yes, but perhaps there's an API in there somewhere for "public" use?


Dunno if its implemented somewhere else.

But you are right, you need an AST, just to decide what the method bodies are, but you also need name and type resolution + call graph to decide if two methods named SAM are in fact in the same class and are thus "versions" of each other.

Our DMS Software Reengineering Toolkit has Java parsers and constructs name/type resolution and a full call graph, so it can be used to determine "method matches". (Of course, you might cheat and just decide that if the method names were the same, they must be variants, but you'd get a lot of false positives on Get and Set, etc. and if you did this a lot, those false positives would be be very distracting). Having decided which ones "match", their text could be displaed. This would be useful if have a lot of API files to compare.

An alternative would be to apply SD's "Smart Diff" to pairs of Java files that you know are the original and changed version. It compares ASTs and finds the minimal edits to map one into another. If the old and new methods are at all similar, it will discover that and tell you how one was edited to get the other. See http://www.semdesigns.com/Products/SmartDifferencer/index.html

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »