1
1
package io .avaje .http .generator .client ;
2
2
3
3
import java .io .IOException ;
4
+ import java .io .Writer ;
4
5
import java .util .LinkedHashSet ;
5
6
import java .util .List ;
6
7
import java .util .Set ;
14
15
import javax .lang .model .element .AnnotationValue ;
15
16
import javax .lang .model .element .Element ;
16
17
import javax .lang .model .element .TypeElement ;
18
+ import javax .tools .FileObject ;
17
19
18
20
import io .avaje .http .generator .core .ClientPrism ;
19
21
import io .avaje .http .generator .core .ControllerReader ;
24
26
@ SupportedAnnotationTypes ({ClientPrism .PRISM_TYPE , ImportPrism .PRISM_TYPE })
25
27
public class ClientProcessor extends AbstractProcessor {
26
28
27
- private static final String METAINF_SERVICES_PROVIDER =
28
- "META-INF/services/io.avaje.http.client.HttpApiProvider" ;
29
+ private static final String METAINF_SERVICES_PROVIDER = "META-INF/services/io.avaje.http.client.HttpApiProvider" ;
29
30
30
31
private final Set <String > generatedClients = new LinkedHashSet <>();
31
32
@@ -68,24 +69,24 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
68
69
}
69
70
return false ;
70
71
}
71
-
72
+
72
73
private void writeServicesFile () {
73
74
try {
74
- final var metaInfWriter = ctx .createMetaInfWriter (METAINF_SERVICES_PROVIDER );
75
- final var writer = metaInfWriter .openWriter ();
76
- for (final String generatedClient : generatedClients ) {
75
+ final FileObject metaInfWriter = ctx .createMetaInfWriter (METAINF_SERVICES_PROVIDER );
76
+ final Writer writer = metaInfWriter .openWriter ();
77
+ for (String generatedClient : generatedClients ) {
77
78
writer .append (generatedClient ).append ("$Provider\n " );
78
79
}
79
80
writer .close ();
80
- } catch (final IOException e ) {
81
+ } catch (IOException e ) {
81
82
ctx .logError (null , "Error writing services file " + e , e );
82
83
}
83
84
}
84
85
85
86
private void writeForImported (Element importedElement ) {
86
- for (final AnnotationMirror annotationMirror : importedElement .getAnnotationMirrors ()) {
87
- for (final AnnotationValue value : annotationMirror .getElementValues ().values ()) {
88
- for (final Object apiClassDef : (List <?>) value .getValue ()) {
87
+ for (AnnotationMirror annotationMirror : importedElement .getAnnotationMirrors ()) {
88
+ for (AnnotationValue value : annotationMirror .getElementValues ().values ()) {
89
+ for (Object apiClassDef : (List <?>) value .getValue ()) {
89
90
writeImported (apiClassDef .toString ());
90
91
}
91
92
}
@@ -94,28 +95,28 @@ private void writeForImported(Element importedElement) {
94
95
95
96
private void writeImported (String fullName ) {
96
97
// trim .class suffix
97
- final var apiClassName = fullName .substring (0 , fullName .length () - 6 );
98
- final var typeElement = ctx .typeElement (apiClassName );
98
+ String apiClassName = fullName .substring (0 , fullName .length () - 6 );
99
+ TypeElement typeElement = ctx .typeElement (apiClassName );
99
100
if (typeElement != null ) {
100
101
writeClient (typeElement );
101
102
}
102
103
}
103
104
104
105
private void writeClient (Element controller ) {
105
106
if (controller instanceof TypeElement ) {
106
- final var reader = new ControllerReader ((TypeElement ) controller , ctx );
107
+ ControllerReader reader = new ControllerReader ((TypeElement ) controller , ctx );
107
108
reader .read (false );
108
109
try {
109
110
generatedClients .add (writeClientAdapter (ctx , reader ));
110
- } catch (final Throwable e ) {
111
+ } catch (Throwable e ) {
111
112
e .printStackTrace ();
112
113
ctx .logError (reader .beanType (), "Failed to write client class " + e );
113
114
}
114
115
}
115
116
}
116
117
117
- protected String writeClientAdapter (ProcessingContext ctx , ControllerReader reader )
118
- throws IOException {
118
+ protected String writeClientAdapter (ProcessingContext ctx , ControllerReader reader ) throws IOException {
119
119
return new ClientWriter (reader , ctx , useJsonB ).write ();
120
120
}
121
+
121
122
}
0 commit comments