[英]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.