33import java .io .IOException ;
44import java .io .InputStream ;
55import java .io .UncheckedIOException ;
6+ import java .net .URI ;
67import java .nio .file .Files ;
78import java .nio .file .Path ;
9+ import java .nio .file .Paths ;
810import java .util .ArrayList ;
911import java .util .Collection ;
12+ import java .util .Collections ;
1013import java .util .List ;
1114import java .util .concurrent .CompletableFuture ;
1215import java .util .stream .Stream ;
1316import java .util .zip .ZipEntry ;
14- import java .util .zip .ZipFile ;
1517
1618import cuchaz .enigma .api .view .ProjectView ;
1719import org .objectweb .asm .ClassReader ;
@@ -34,7 +36,7 @@ public static CompletableFuture<AnnotationsIndex> index(ProjectView project) {
3436 }
3537 });
3638
37- indexJdkClasses (annotations , allClasses );
39+ indexJdkClasses (Collections . synchronizedList ( annotations ), Collections . synchronizedList ( allClasses ) );
3840
3941 return new AnnotationsIndex (annotations , allClasses );
4042 }).whenComplete ((annotationsIndex , throwable ) -> {
@@ -45,37 +47,21 @@ public static CompletableFuture<AnnotationsIndex> index(ProjectView project) {
4547 }
4648
4749 private static void indexJdkClasses (List <String > annotations , List <String > allClasses ) {
48- String javaHome = System .getProperty ("java.home" );
49- Path modulesPath = Path .of (javaHome , "jmods" );
50+ try (Stream <Path > classes = Files .walk (Paths .get (URI .create ("jrt:/" ))).parallel ()) {
51+ classes .forEach (path -> {
52+ if (!Files .isRegularFile (path )) return ;
53+ if (!path .getFileName ().toString ().endsWith (".class" )) return ;
5054
51- try (Stream <Path > modules = Files .walk (modulesPath )) {
52- modules .forEach (module -> {
53- if (!module .toString ().endsWith (".jmod" )) {
54- return ;
55- }
56-
57- try (ZipFile zipFile = new ZipFile (module .toFile ())) {
58- List <? extends ZipEntry > classEntries = zipFile .stream ()
59- .filter (entry -> entry .getName ().startsWith ("classes/" ) && entry .getName ().endsWith (".class" ))
60- .toList ();
55+ try (InputStream in = Files .newInputStream (path )) {
56+ ClassReader reader = new ClassReader (in );
6157
62- for (ZipEntry classEntry : classEntries ) {
63- allClasses .add (getClassName (classEntry ));
64- }
58+ allClasses .add (reader .getClassName ());
6559
66- classEntries .parallelStream ().forEach (entry -> {
67- try (InputStream in = zipFile .getInputStream (entry )) {
68- ClassReader reader = new ClassReader (in );
69-
70- if ((reader .getAccess () & Opcodes .ACC_ANNOTATION ) != 0 ) {
71- synchronized (annotations ) {
72- annotations .add (getClassName (entry ));
73- }
74- }
75- } catch (IOException e ) {
76- throw new UncheckedIOException (e );
60+ if ((reader .getAccess () & Opcodes .ACC_ANNOTATION ) != 0 ) {
61+ synchronized (annotations ) {
62+ annotations .add (reader .getClassName ());
7763 }
78- });
64+ }
7965 } catch (IOException e ) {
8066 throw new UncheckedIOException (e );
8167 }
0 commit comments