@@ -138,33 +138,9 @@ void processInterfaces(CombinedIndexBuildItem combinedIndexBuildItem,
138
138
Set <Type > returnTypes = new HashSet <>();
139
139
140
140
IndexView index = combinedIndexBuildItem .getIndex ();
141
- for (AnnotationInstance annotation : index .getAnnotations (PATH )) {
142
- AnnotationTarget target = annotation .target ();
143
- ClassInfo theInfo ;
144
- if (target .kind () == AnnotationTarget .Kind .CLASS ) {
145
- theInfo = target .asClass ();
146
- } else if (target .kind () == AnnotationTarget .Kind .METHOD ) {
147
- theInfo = target .asMethod ().declaringClass ();
148
- } else {
149
- continue ;
150
- }
151
-
152
- if (!isRestClientInterface (index , theInfo )) {
153
- continue ;
154
- }
155
141
156
- interfaces .put (theInfo .name (), theInfo );
157
-
158
- // Find Return types
159
- for (MethodInfo method : theInfo .methods ()) {
160
- Type type = method .returnType ();
161
- if (!type .name ().toString ().contains ("java.lang" )) {
162
- if (!returnTypes .contains (type )) {
163
- returnTypes .add (type );
164
- }
165
- }
166
- }
167
- }
142
+ findInterfaces (index , interfaces , returnTypes , REGISTER_REST_CLIENT );
143
+ findInterfaces (index , interfaces , returnTypes , PATH );
168
144
169
145
if (interfaces .isEmpty ()) {
170
146
return ;
@@ -207,16 +183,17 @@ public void register(RegistrationContext registrationContext) {
207
183
// The spec is not clear whether we should add superinterfaces too - let's keep aligned with SmallRye for now
208
184
configurator .addType (restClientName );
209
185
configurator .addQualifier (REST_CLIENT );
210
- final ScopeInfo scope = computeDefaultScope (config , entry );
186
+ final String configPrefix = computeConfigPrefix (restClientName .toString (), entry .getValue ());
187
+ final ScopeInfo scope = computeDefaultScope (config , entry , configPrefix );
211
188
configurator .scope (scope );
212
189
configurator .creator (m -> {
213
190
// return new RestClientBase(proxyType, baseUri).create();
214
191
ResultHandle interfaceHandle = m .loadClass (restClientName .toString ());
215
192
ResultHandle baseUriHandle = m .load (getAnnotationParameter (entry .getValue (), "baseUri" ));
216
- ResultHandle configKeyHandle = m .load (getAnnotationParameter ( entry . getValue (), "configKey" ) );
193
+ ResultHandle configPrefixHandle = m .load (configPrefix );
217
194
ResultHandle baseHandle = m .newInstance (
218
195
MethodDescriptor .ofConstructor (RestClientBase .class , Class .class , String .class , String .class ),
219
- interfaceHandle , baseUriHandle , configKeyHandle );
196
+ interfaceHandle , baseUriHandle , configPrefixHandle );
220
197
ResultHandle ret = m .invokeVirtualMethod (
221
198
MethodDescriptor .ofMethod (RestClientBase .class , "create" , Object .class ), baseHandle );
222
199
m .returnValue (ret );
@@ -232,13 +209,62 @@ public void register(RegistrationContext registrationContext) {
232
209
restClientRecorder .setSslEnabled (sslNativeConfig .isEnabled ());
233
210
}
234
211
235
- private ScopeInfo computeDefaultScope (Config config , Map .Entry <DotName , ClassInfo > entry ) {
236
- DotName restClientName = entry .getKey ();
212
+ private void findInterfaces (IndexView index , Map <DotName , ClassInfo > interfaces , Set <Type > returnTypes ,
213
+ DotName annotationToFind ) {
214
+ for (AnnotationInstance annotation : index .getAnnotations (annotationToFind )) {
215
+ AnnotationTarget target = annotation .target ();
216
+ ClassInfo theInfo ;
217
+ if (target .kind () == AnnotationTarget .Kind .CLASS ) {
218
+ theInfo = target .asClass ();
219
+ } else if (target .kind () == AnnotationTarget .Kind .METHOD ) {
220
+ theInfo = target .asMethod ().declaringClass ();
221
+ } else {
222
+ continue ;
223
+ }
224
+
225
+ if (!isRestClientInterface (index , theInfo )) {
226
+ continue ;
227
+ }
228
+
229
+ interfaces .put (theInfo .name (), theInfo );
230
+
231
+ // Find Return types
232
+ processInterfaceReturnTypes (theInfo , returnTypes );
233
+ for (Type interfaceType : theInfo .interfaceTypes ()) {
234
+ ClassInfo interfaceClassInfo = index .getClassByName (interfaceType .name ());
235
+ if (interfaceClassInfo != null ) {
236
+ processInterfaceReturnTypes (interfaceClassInfo , returnTypes );
237
+ }
238
+ }
239
+ }
240
+ }
241
+
242
+ private void processInterfaceReturnTypes (ClassInfo classInfo , Set <Type > returnTypes ) {
243
+ for (MethodInfo method : classInfo .methods ()) {
244
+ Type type = method .returnType ();
245
+ if (!type .name ().toString ().contains ("java.lang" )) {
246
+ if (!returnTypes .contains (type )) {
247
+ returnTypes .add (type );
248
+ }
249
+ }
250
+ }
251
+ }
252
+
253
+ private String computeConfigPrefix (String interfaceName , ClassInfo classInfo ) {
254
+ String propertyPrefixFromAnnotation = getAnnotationParameter (classInfo , "configKey" );
255
+
256
+ if (propertyPrefixFromAnnotation != null && !propertyPrefixFromAnnotation .isEmpty ()) {
257
+ return propertyPrefixFromAnnotation ;
258
+ }
259
+
260
+ return interfaceName ;
261
+ }
262
+
263
+ private ScopeInfo computeDefaultScope (Config config , Map .Entry <DotName , ClassInfo > entry , String configPrefix ) {
237
264
// Initialize a default @Dependent scope as per the spec
238
265
ScopeInfo scopeInfo = BuiltinScope .DEPENDENT .getInfo ();
239
- final String REST_SCOPE_FORMAT = "%s/" + RestClientBase .MP_REST + "/scope" ;
240
266
final Optional <String > scopeConfig = config
241
- .getOptionalValue (String .format (REST_SCOPE_FORMAT , restClientName . toString () ), String .class );
267
+ .getOptionalValue (String .format (RestClientBase . REST_SCOPE_FORMAT , configPrefix ), String .class );
242
268
if (scopeConfig .isPresent ()) {
243
269
final DotName scope = DotName .createSimple (scopeConfig .get ());
244
270
final BuiltinScope builtinScope = BuiltinScope .from (scope );
@@ -247,7 +273,7 @@ private ScopeInfo computeDefaultScope(Config config, Map.Entry<DotName, ClassInf
247
273
} else {
248
274
log .warn (String .format (
249
275
"Unsupported default scope %s provided for rest client %s. Defaulting to @Dependent." ,
250
- scope , restClientName ));
276
+ scope , entry . getKey () ));
251
277
}
252
278
} else {
253
279
final Set <DotName > annotations = entry .getValue ().annotations ().keySet ();
0 commit comments