当前位置: 动力学知识库 > 问答 > 编程问答 >

methodology - What is the quickest way to determine what code will be affected by a refactoring?

问题描述:

I'm using Eclipse and Java, but the answer doesn't need to be specific to those. I'm sure platform specific answers will get plenty of upvotes if they're far quicker than non-platform specific ones.

Right now I'm using

    grep "classname" find . -regex .*\.java > uses_classname.txt

to find code that might be affected by a change to the class. If there are only a few lines returned by this, I can look at it manually as it is. Otherwise, I can grep again to find the specific methods I'm modifying. Is there a better way to do this?

网友答案:

[Just being a bit of a librarian here:]

Finding references to a Java method/class:

How can I find all the methods that call a given method in Java?

How can I find references of a class in Eclipse?

References to Java annotations:

How to Check References of Annotated Methods

Finding references to 'derived' methods in Eclipse:

Eclipse Specific: Is it possible to find references of use of derived methods in a class?

How to do it with VIM:

Is it possible to find usage of java classes or methods in VIM?

And with Emacs:

How can I find the references of a class, method, variable in Emacs with Etags?

Finding (the number of) references to a method in C#:

How do you programmatically identify the number of references to a method with C#

Nice to read: how to find methods that are not used in C#/.NET:

Find unused code

Is there a tool for finding unreferenced functions (dead, obsolete code) in a C# app?

On refactoring of PHP code:

Tools for PHP code refactoring

Finding references in Smalltalk:

Find references to string/symbol/method

Finding references in (Apple) Xcode seems to be a popular question:

how to find method references in XCode

Xcode: view references for a variable?

Finding all references of a variable or a method in Xcode4

网友答案:

A good solution is to use JUnit and practice test-driven development. After refactoring, re-running your test cases will tell you whether any existing functionality has been damaged. Moreover, since you are actually testing the code rather than grep'ing over method names, you can get full backtrace, making debugging much easier. A good introduction to JUnit can be found here.

分享给朋友:
您可能感兴趣的文章:
随机阅读: