如何将所有已弃用的 类 列出到文件中?

How to list all deprecated classes to a file?

我知道 Intellij can scan for this - and there seems to be an ancient project called Scannotation。这些似乎都没有做我想要的。

我想列出我的代码库中标记为 @Deprecated 的 类 的完整包名。

我的问题是:如何将所有已弃用的 类 列出到文件中?

在 unix/linux 系统上,您可以使用 find . -name *.java -regex "@Deprecated"

这将给出一个包含绝对路径的文件列表,可以使用 sed 或任何其他文本编辑器将其更改为包符号。

在 Windows 上,您可以考虑安装 git,它会带来一个 bash,您可以在其中 运行 此命令。

您可以使用 Structural Search

CTRL + SHIFT + A --> Search Structurally

使用它来查找所有已弃用的 类:

@Deprecated
class $class$ {
}

这是您可以使用的:

    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();
        }

    }