2
2
3
3
import static io .javaoperatorsdk .operator .ControllerUtils .CONTROLLERS_RESOURCE_PATH ;
4
4
import static io .javaoperatorsdk .operator .ControllerUtils .DONEABLES_RESOURCE_PATH ;
5
- import static javax .lang .model .type .TypeKind .DECLARED ;
6
- import static javax .lang .model .type .TypeKind .TYPEVAR ;
7
5
8
6
import com .google .auto .service .AutoService ;
9
7
import com .squareup .javapoet .ClassName ;
17
15
import io .javaoperatorsdk .operator .api .ResourceController ;
18
16
import java .io .PrintWriter ;
19
17
import java .util .HashSet ;
20
- import java .util .List ;
21
18
import java .util .Set ;
22
- import java .util .stream .IntStream ;
23
19
import javax .annotation .processing .AbstractProcessor ;
24
20
import javax .annotation .processing .ProcessingEnvironment ;
25
21
import javax .annotation .processing .Processor ;
32
28
import javax .lang .model .element .Modifier ;
33
29
import javax .lang .model .element .PackageElement ;
34
30
import javax .lang .model .element .TypeElement ;
35
- import javax .lang .model .element .TypeParameterElement ;
36
31
import javax .lang .model .type .DeclaredType ;
37
32
import javax .lang .model .type .TypeMirror ;
38
- import javax .lang .model .type .TypeVariable ;
39
33
import javax .tools .Diagnostic ;
40
34
import javax .tools .JavaFileObject ;
41
35
@@ -78,7 +72,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
78
72
annotatedElements .stream ()
79
73
.filter (element -> element .getKind ().equals (ElementKind .CLASS ))
80
74
.map (e -> (TypeElement ) e )
81
- .forEach (e -> this . generateDoneableClass ( e ) );
75
+ .forEach (this :: generateDoneableClass );
82
76
}
83
77
} finally {
84
78
if (roundEnv .processingOver ()) {
@@ -153,15 +147,10 @@ private void generateDoneableClass(TypeElement controllerClassSymbol) {
153
147
}
154
148
}
155
149
156
- private TypeMirror findResourceType (TypeElement controllerClassSymbol ) throws Exception {
150
+ private TypeMirror findResourceType (TypeElement controllerClassSymbol ) {
157
151
try {
158
- final var chain =
159
- typeParameterResolver .findChain (
160
- processingEnv .getTypeUtils (),
161
- processingEnv .getElementUtils (),
162
- (DeclaredType ) controllerClassSymbol .asType ());
163
- final var customResourceClass = getCustomResourceClass (chain );
164
- return customResourceClass ;
152
+ return typeParameterResolver .resolve (
153
+ processingEnv .getTypeUtils (), (DeclaredType ) controllerClassSymbol .asType ());
165
154
} catch (Exception e ) {
166
155
e .printStackTrace ();
167
156
return null ;
@@ -174,40 +163,4 @@ private String makeQualifiedClassName(String packageName, String className) {
174
163
}
175
164
return packageName + "." + className ;
176
165
}
177
-
178
- private TypeMirror getCustomResourceClass (List <DeclaredType > chain ) {
179
- var lastIndex = chain .size () - 1 ;
180
- String typeName ;
181
- final List <? extends TypeMirror > typeArguments = (chain .get (lastIndex )).getTypeArguments ();
182
- if (typeArguments .get (0 ).getKind () == TYPEVAR ) {
183
- typeName = ((TypeVariable ) typeArguments .get (0 )).asElement ().getSimpleName ().toString ();
184
- } else if (typeArguments .get (0 ).getKind () == DECLARED ) {
185
- return typeArguments .get (0 );
186
- } else {
187
- typeName = "" ;
188
- }
189
-
190
- while (lastIndex > 0 ) {
191
- lastIndex -= 1 ;
192
- final List <? extends TypeMirror > tArguments = (chain .get (lastIndex )).getTypeArguments ();
193
- final List <? extends TypeParameterElement > typeParameters =
194
- ((TypeElement ) ((chain .get (lastIndex )).asElement ())).getTypeParameters ();
195
- final String tName = typeName ;
196
- final var typeIndex =
197
- IntStream .range (0 , typeParameters .size ())
198
- .filter (i -> typeParameters .get (i ).getSimpleName ().toString ().equals (tName ))
199
- .findFirst ()
200
- .getAsInt ();
201
-
202
- final TypeMirror matchedType = tArguments .get (typeIndex );
203
- if (matchedType .getKind () == TYPEVAR ) {
204
- typeName = ((TypeVariable ) matchedType ).asElement ().getSimpleName ().toString ();
205
- } else if (matchedType .getKind () == DECLARED ) {
206
- return matchedType ;
207
- } else {
208
- typeName = "" ;
209
- }
210
- }
211
- return null ;
212
- }
213
166
}
0 commit comments