[英]How to list all deprecated classes to a file?
我知道 Intellij 可以對此進行掃描- 似乎有一個名為Scannotation的古老項目。 這些似乎都沒有做我想要的。
我想列出我的代碼庫中標記為@Deprecated
的類的完整包名稱。
我的問題是:如何將所有已棄用的類列出到文件中?
在 unix/linux 系統上,您可以使用find . -name *.java -regex "@Deprecated"
find . -name *.java -regex "@Deprecated"
這將給出具有絕對路徑的文件列表,可以使用sed
或任何其他文本編輯器將其更改為包表示法。
在 Windows 上,您可能會考慮安裝git ,它會帶來一個 bash,您可以在其中運行此命令。
這是您可以使用的:
package util;
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner;
import io.github.lukehutch.fastclasspathscanner.matchprocessor.ClassAnnotationMatchProcessor;
public class AnnotationScanTest {
public static void main(String args[]) throws ClassNotFoundException {
new FastClasspathScanner("com")
// Optional, in case you want to debug any issues with scanning.
// Add this right after the constructor to maximize the amount of log info.
.verbose()
// Add a MatchProcessor ("Mechanism 1")
.matchClassesWithAnnotation(Deprecated.class, new ClassAnnotationMatchProcessor() {
@Override
public void processMatch(Class<?> matchingClass) {
System.out.println("Matching annotation: " + matchingClass);
}
})
// Actually perform the scan (nothing will happen without this call)
.scan();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.