33
33
import java .util .ArrayList ;
34
34
import java .util .Arrays ;
35
35
import java .util .Collection ;
36
- import java .util .Comparator ;
37
36
import java .util .List ;
38
37
39
38
import jdk .graal .compiler .util .json .JsonPrinter ;
40
39
import jdk .graal .compiler .util .json .JsonWriter ;
41
40
42
41
public record LambdaConfigurationTypeDescriptor (ConfigurationTypeDescriptor declaringClass , ConfigurationParser .ConfigurationMethodDescriptor declaringMethod ,
43
42
List <NamedConfigurationTypeDescriptor > interfaces ) implements ConfigurationTypeDescriptor {
43
+
44
+ public static final ConfigurationTypeDescriptor [] EMPTY_TYPE_DESCRIPTOR_ARRAY = new ConfigurationTypeDescriptor [0 ];
45
+
44
46
public static LambdaConfigurationTypeDescriptor fromReflectionNames (String declaringClass , List <String > interfaces ) {
45
- return new LambdaConfigurationTypeDescriptor (NamedConfigurationTypeDescriptor .fromReflectionName (declaringClass ), null ,
46
- interfaces . stream (). map ( NamedConfigurationTypeDescriptor :: fromReflectionName ). toList ( ));
47
+ return new LambdaConfigurationTypeDescriptor (NamedConfigurationTypeDescriptor .fromReflectionName (declaringClass ),
48
+ null , getNamedConfigurationTypeDescriptors ( interfaces ));
47
49
}
48
50
49
51
public static LambdaConfigurationTypeDescriptor fromTypeNames (String declaringClass , List <String > interfaces ) {
50
52
return new LambdaConfigurationTypeDescriptor (NamedConfigurationTypeDescriptor .fromTypeName (declaringClass ), null ,
51
- interfaces .stream ().map (NamedConfigurationTypeDescriptor ::fromTypeName ).toList ());
53
+ getNamedConfigurationTypeDescriptors (interfaces ));
54
+ }
55
+
56
+ private static List <NamedConfigurationTypeDescriptor > getNamedConfigurationTypeDescriptors (List <String > interfaces ) {
57
+ List <NamedConfigurationTypeDescriptor > reflectionInterfaces = new ArrayList <>(interfaces .size ());
58
+ for (var interfaceName : interfaces ) {
59
+ reflectionInterfaces .add (NamedConfigurationTypeDescriptor .fromReflectionName (interfaceName ));
60
+ }
61
+ return reflectionInterfaces ;
52
62
}
53
63
54
64
@ Override
@@ -67,11 +77,26 @@ public Collection<String> getAllQualifiedJavaNames() {
67
77
68
78
@ Override
69
79
public int compareTo (ConfigurationTypeDescriptor other ) {
70
- if (other instanceof LambdaConfigurationTypeDescriptor lambdaOther ) {
71
- return Comparator .comparing (LambdaConfigurationTypeDescriptor ::declaringClass )
72
- .thenComparing (LambdaConfigurationTypeDescriptor ::declaringMethod , Comparator .nullsFirst (ConfigurationParser .ConfigurationMethodDescriptor ::compareTo ))
73
- .thenComparing ((a , b ) -> Arrays .compare (a .interfaces .toArray (ConfigurationTypeDescriptor []::new ), b .interfaces .toArray (ConfigurationTypeDescriptor []::new )))
74
- .compare (this , lambdaOther );
80
+ if (other instanceof LambdaConfigurationTypeDescriptor otherLambda ) {
81
+ int result = declaringClass .compareTo (otherLambda .declaringClass ());
82
+ if (result != 0 ) {
83
+ return result ;
84
+ }
85
+ // Compare declaringMethod with nullsFirst
86
+ if (this .declaringMethod () == null && otherLambda .declaringMethod () != null ) {
87
+ return -1 ;
88
+ } else if (this .declaringMethod () != null && otherLambda .declaringMethod () == null ) {
89
+ return 1 ;
90
+ } else if (this .declaringMethod () != null ) {
91
+ result = this .declaringMethod ().compareTo (otherLambda .declaringMethod ());
92
+ if (result != 0 ) {
93
+ return result ;
94
+ }
95
+ }
96
+
97
+ return Arrays .compare (
98
+ interfaces .toArray (EMPTY_TYPE_DESCRIPTOR_ARRAY ),
99
+ otherLambda .interfaces ().toArray (EMPTY_TYPE_DESCRIPTOR_ARRAY ));
75
100
} else {
76
101
return getDescriptorType ().compareTo (other .getDescriptorType ());
77
102
}
0 commit comments