7
7
8
8
import java .lang .reflect .ParameterizedType ;
9
9
import java .util .Arrays ;
10
- import java .util .HashMap ;
11
- import java .util .Map ;
12
10
13
11
14
12
public class ControllerUtils {
15
13
16
14
private static final String FINALIZER_NAME_SUFFIX = "/finalizer" ;
17
15
18
- // this is just to support testing, this way we don't try to create class multiple times in memory with same name.
19
- // note that other solution is to add a random string to doneable class name
20
- private static Map <Class <? extends CustomResource >, Class <? extends CustomResourceDoneable <? extends CustomResource >>>
21
- doneableClassCache = new HashMap <>();
22
-
23
16
static String getFinalizer (ResourceController controller ) {
24
17
final String annotationFinalizerName = getAnnotation (controller ).finalizerName ();
25
18
if (!Controller .NULL .equals (annotationFinalizerName )) {
26
19
return annotationFinalizerName ;
27
20
}
28
- final String crdName = getAnnotation (controller ).crdName () + FINALIZER_NAME_SUFFIX ;
29
- return crdName ;
21
+ return getAnnotation (controller ).crdName () + FINALIZER_NAME_SUFFIX ;
30
22
}
31
23
32
- static boolean getGenerationEventProcessing (ResourceController controller ) {
24
+ static boolean getGenerationEventProcessing (ResourceController <?> controller ) {
33
25
return getAnnotation (controller ).generationAwareEventProcessing ();
34
26
}
35
27
36
28
static <R extends CustomResource > Class <R > getCustomResourceClass (ResourceController <R > controller ) {
37
- final Class < R > type = Arrays
29
+ return Arrays
38
30
.stream (controller .getClass ().getGenericInterfaces ())
39
31
.filter (i -> i instanceof ParameterizedType )
40
32
.map (i -> (ParameterizedType ) i )
41
33
.findFirst ()
42
34
.map (i -> (Class <R >) i .getActualTypeArguments ()[0 ])
43
35
.get ();
44
- return type ;
45
36
}
46
37
47
38
static String getCrdName (ResourceController controller ) {
@@ -60,7 +51,7 @@ static String getCrdName(ResourceController controller) {
60
51
}
61
52
}
62
53
63
- private static Controller getAnnotation (ResourceController controller ) {
54
+ private static Controller getAnnotation (ResourceController <?> controller ) {
64
55
return controller .getClass ().getAnnotation (Controller .class );
65
56
}
66
57
0 commit comments