I'm aware that Intellij can scan for this - and there seems to be an ancient project called Scannotation . Neither of these seems to do what I want.
I want to list the full package names of classes in my codebase that are marked @Deprecated
.
My question is: How to list all deprecated classes to a file?
You can use Structural Search .
CTRL
+ SHIFT
+ A
--> Search Structurally
Use this to find all deprecated classes:
@Deprecated
class $class$ {
}
On a unix/linux system you could use find . -name *.java -regex "@Deprecated"
find . -name *.java -regex "@Deprecated"
This would give a list of files with absolute paths that could be changed to package notation with sed
or any other text editor.
On Windows you might consider installing git which brings a bash where you can run this command.
This is what you can use:
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();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.