26
26
package java .lang ;
27
27
28
28
import java .lang .annotation .Annotation ;
29
- import java .lang .classfile .Attributes ;
30
- import java .lang .classfile .ClassFile ;
31
- import java .lang .classfile .ClassModel ;
32
- import java .lang .classfile .MethodModel ;
29
+ import java .lang .classfile .*;
33
30
import java .lang .classfile .attribute .*;
34
31
import java .lang .constant .ClassDesc ;
35
32
import java .lang .constant .ConstantDescs ;
@@ -2311,7 +2308,10 @@ private Method[] filterOutDeconstructorsFromMethods(Method[] in) {
2311
2308
throw new RuntimeException (e );
2312
2309
}
2313
2310
for (MethodModel mm : cm .methods ()) {
2314
- PatternAttribute pa = mm .findAttribute (Attributes .PATTERN ).orElse (null );
2311
+ PatternAttribute pa = null ;
2312
+ for (Attribute <?> attribute : mm .attributes ()) {
2313
+ if (attribute instanceof PatternAttribute pap ) pa = pap ;
2314
+ }
2315
2315
isNotPattern .put (mm .methodName ().stringValue (), pa == null );
2316
2316
}
2317
2317
Method [] ret = Arrays .stream (in ).filter (m -> isNotPattern .getOrDefault (m .getName (), true )).toArray (Method []::new );
@@ -2413,12 +2413,18 @@ private Deconstructor<?>[] getDeclaredDeconstructors0(Class<?>[] params, int whi
2413
2413
byte [] bytes = is .readAllBytes ();
2414
2414
ClassModel cm = ClassFile .of ().parse (bytes );
2415
2415
for (MethodModel mm : cm .methods ()) {
2416
- PatternAttribute pa = mm .findAttribute (Attributes .PATTERN ).orElse (null );
2416
+ PatternAttribute pa = null ;
2417
+ for (Attribute <?> attribute : mm .attributes ()) {
2418
+ if (attribute instanceof PatternAttribute pa_ ) pa = pa_ ;
2419
+ }
2417
2420
if (pa != null ) {
2418
2421
String descriptorFilter = null ;
2419
2422
2420
2423
// generic signature detection
2421
- SignatureAttribute sa = pa .findAttribute (Attributes .SIGNATURE ).orElse (null );
2424
+ SignatureAttribute sa = null ;
2425
+ for (Attribute <?> attribute : pa .attributes ()) {
2426
+ if (attribute instanceof SignatureAttribute sa_ ) sa = sa_ ;
2427
+ }
2422
2428
List <String > signatures = List .of ();
2423
2429
if (sa != null ) {
2424
2430
signatures = sa .asMethodSignature ().arguments ().stream ().map (a -> a .signatureString ()).toList ();
@@ -2435,7 +2441,10 @@ private Deconstructor<?>[] getDeclaredDeconstructors0(Class<?>[] params, int whi
2435
2441
if ((params .length == 0 || (params .length != 0 && pa .patternTypeSymbol ().descriptorString ().equals (descriptorFilter ))) &&
2436
2442
(which == Member .DECLARED || mm .flags ().has (AccessFlag .PUBLIC ))) {
2437
2443
// binding annotations
2438
- RuntimeVisibleAnnotationsAttribute rva = mm .findAttribute (Attributes .RUNTIME_VISIBLE_ANNOTATIONS ).orElse (null );
2444
+ RuntimeVisibleAnnotationsAttribute rva = null ;
2445
+ for (Attribute <?> attribute : mm .attributes ()) {
2446
+ if (attribute instanceof RuntimeVisibleAnnotationsAttribute rva_ ) rva = rva_ ;
2447
+ }
2439
2448
ByteBuffer assembled_rva = null ;
2440
2449
if (rva != null ) {
2441
2450
byte rvaBytes [] = ((BoundAttribute ) rva ).contents (); // returns the full attribute
@@ -2456,11 +2465,17 @@ private Deconstructor<?>[] getDeclaredDeconstructors0(Class<?>[] params, int whi
2456
2465
2457
2466
// parameter names
2458
2467
var parameterList = pa .patternTypeSymbol ().parameterList ();
2459
- MethodParametersAttribute mp = pa .findAttribute (Attributes .METHOD_PARAMETERS ).orElse (null );
2468
+ MethodParametersAttribute mp = null ;
2469
+ for (Attribute <?> attribute : pa .attributes ()) {
2470
+ if (attribute instanceof MethodParametersAttribute mp_ ) mp = mp_ ;
2471
+ }
2460
2472
List <String > parameterNameList = mp .parameters ().stream ().map (p -> p .name ().get ().stringValue ()).toList ();
2461
2473
2462
2474
// binding annotations
2463
- RuntimeVisibleParameterAnnotationsAttribute rvpa = pa .findAttribute (Attributes .RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS ).orElse (null );
2475
+ RuntimeVisibleParameterAnnotationsAttribute rvpa = null ;
2476
+ for (Attribute <?> attribute : pa .attributes ()) {
2477
+ if (attribute instanceof RuntimeVisibleParameterAnnotationsAttribute rvpa_ ) rvpa = rvpa_ ;
2478
+ }
2464
2479
ByteBuffer assembled_rvpa = null ;
2465
2480
if (rvpa != null ) {
2466
2481
byte rvpaBytes [] = ((BoundAttribute ) rvpa ).contents ();
@@ -2470,7 +2485,10 @@ private Deconstructor<?>[] getDeclaredDeconstructors0(Class<?>[] params, int whi
2470
2485
}
2471
2486
2472
2487
// binding type annotations
2473
- RuntimeVisibleTypeAnnotationsAttribute rvta = pa .findAttribute (Attributes .RUNTIME_VISIBLE_TYPE_ANNOTATIONS ).orElse (null );
2488
+ RuntimeVisibleTypeAnnotationsAttribute rvta = null ;
2489
+ for (Attribute <?> attribute : pa .attributes ()) {
2490
+ if (attribute instanceof RuntimeVisibleTypeAnnotationsAttribute rvta_ ) rvta = rvta_ ;
2491
+ }
2474
2492
ByteBuffer assembled_rvta = null ;
2475
2493
if (rvpa != null ) {
2476
2494
byte rvtaBytes [] = ((BoundAttribute ) rvpa ).contents ();
0 commit comments