获取代码文件版本差异显示受影响的方法(名称)

时间:2023-01-25 08:51:11

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?

我希望在两个版本的代码文件(Java / C#)之间获得差异 - 并从中获得受影响的方法(名称)列表。这已经实施了吗?

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

我认为这需要对从diff中返回的行进行AST分析。

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

这一点的重点是改进checkstyle / findbugs以仅仅处理Sprint期间触及的方法。

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

我看了一下eclipse执行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.

看起来它只适用于行号 - 而不是实际的AST。我对#=> methodName映射行很感兴趣。

3 个解决方案

#1


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

您可以使用eclipse的比较api,即使不使用eclipse本身也是如此。搜索org.eclipse.compare

#2


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?

我不知道这是否会对你有所帮助,但Eclipse中的diff / compare在它的顶部面板中执行此操作(下面是两个文件/版本并排)。图形化,是的,但也许在那里有一个用于“公共”使用的API?

#3


Dunno if its implemented somewhere else.

Dunno如果它在其他地方实现的话。

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.

但你是对的,你需要一个AST,只需要决定方法体是什么,但你还需要名称和类型解析+调用图来决定两个名为SAM的方法是否实际上在同一个类中,因此是“版本”彼此的。

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.

我们的DMS软件再造工具包具有Java解析器和构造名称/类型解析和完整的调用图,因此可用于确定“方法匹配”。 (当然,你可能会作弊,只是决定如果方法名称是相同的,它们必须是变体,但你会在Get和Set等上得到很多误报,如果你做了很多,那些误报会非常分散注意力)。在确定哪些“匹配”后,他们的文本可能会被取代。如果要比较很多API文件,这将非常有用。

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

另一种方法是将SD的“Smart Diff”应用于您知道的原始和更改版本的Java文件对。它比较AST并找到将其中一个映射到另一个的最小编辑。如果旧方法和新方法完全相似,它会发现并告诉你如何编辑一个方法以获得另一个方法。请参阅http://www.semdesigns.com/Products/SmartDifferencer/index.html

#1


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

您可以使用eclipse的比较api,即使不使用eclipse本身也是如此。搜索org.eclipse.compare

#2


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?

我不知道这是否会对你有所帮助,但Eclipse中的diff / compare在它的顶部面板中执行此操作(下面是两个文件/版本并排)。图形化,是的,但也许在那里有一个用于“公共”使用的API?

#3


Dunno if its implemented somewhere else.

Dunno如果它在其他地方实现的话。

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.

但你是对的,你需要一个AST,只需要决定方法体是什么,但你还需要名称和类型解析+调用图来决定两个名为SAM的方法是否实际上在同一个类中,因此是“版本”彼此的。

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.

我们的DMS软件再造工具包具有Java解析器和构造名称/类型解析和完整的调用图,因此可用于确定“方法匹配”。 (当然,你可能会作弊,只是决定如果方法名称是相同的,它们必须是变体,但你会在Get和Set等上得到很多误报,如果你做了很多,那些误报会非常分散注意力)。在确定哪些“匹配”后,他们的文本可能会被取代。如果要比较很多API文件,这将非常有用。

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

另一种方法是将SD的“Smart Diff”应用于您知道的原始和更改版本的Java文件对。它比较AST并找到将其中一个映射到另一个的最小编辑。如果旧方法和新方法完全相似,它会发现并告诉你如何编辑一个方法以获得另一个方法。请参阅http://www.semdesigns.com/Products/SmartDifferencer/index.html