views:

173

answers:

3

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:

http://dev.eclipse.org/viewsvn/index.cgi/org.eclipse.compare.tests/src/org/eclipse/compare/tests/

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

+1  A: 

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?

Mirvnillith
Looking at the underlying API in org.eclipse.compare it looks like this just does line numbers - not actual method names
hawkeye
You can see this here:http://dev.eclipse.org/viewsvn/index.cgi/org.eclipse.compare.tests/src/org/eclipse/compare/tests/
hawkeye
+1  A: 

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

Fortega
Looking at the underlying API in org.eclipse.compare it looks like this just does line numbers - not actual method names
hawkeye
A: 

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

Ira Baxter