@@ -292,30 +292,14 @@ private String simpleName(String name) {
292292 }
293293
294294 private static List <TypeElement > permittedSubclasses (TypeElement node , Set <String > exports ) {
295- List <TypeElement > dfsStack = new ArrayList <TypeElement >().reversed (); // Faster operations to head
296- List <TypeElement > result = new ArrayList <>();
297- // The starting node may be in the public API - still expand it
298- prependSubclasses (node , dfsStack );
299-
300- while (!dfsStack .isEmpty ()) {
301- TypeElement now = dfsStack .removeFirst ();
302- if (isInPublicApi (now , exports )) {
303- result .addLast (now );
304- } else {
305- // Skip the non-exported classes in the hierarchy
306- prependSubclasses (now , dfsStack );
307- }
308- }
309-
310- return List .copyOf (result );
311- }
312-
313- private static void prependSubclasses (TypeElement node , List <TypeElement > dfs ) {
314- for (var e : node .getPermittedSubclasses ().reversed ()) {
315- if (e instanceof DeclaredType dt && dt .asElement () instanceof TypeElement te ) {
316- dfs .addFirst (te );
317- }
318- }
295+ return node .getPermittedSubclasses ().stream ()
296+ .filter (DeclaredType .class ::isInstance )
297+ .map (DeclaredType .class ::cast )
298+ .map (DeclaredType ::asElement )
299+ .filter (TypeElement .class ::isInstance )
300+ .map (TypeElement .class ::cast )
301+ .filter (te -> isInPublicApi (te , exports ))
302+ .toList ();
319303 }
320304
321305 private static boolean isInPublicApi (TypeElement typeElement , Set <String > exports ) {
0 commit comments