4
4
5
5
import javax .lang .model .element .TypeElement ;
6
6
import java .util .Set ;
7
- import java .util .stream .Collectors ;
8
7
9
8
/**
10
9
* Write code to register Web route for a given controller method.
@@ -23,15 +22,13 @@ class ClientMethodWriter {
23
22
private final UType returnType ;
24
23
private MethodParam bodyHandlerParam ;
25
24
private String methodGenericParams = "" ;
26
- private final boolean useJsonb ;
27
25
28
- ClientMethodWriter (MethodReader method , Append writer , ProcessingContext ctx , boolean useJsonb ) {
26
+ ClientMethodWriter (MethodReader method , Append writer , ProcessingContext ctx ) {
29
27
this .method = method ;
30
28
this .writer = writer ;
31
29
this .webMethod = method .webMethod ();
32
30
this .ctx = ctx ;
33
31
this .returnType = Util .parseType (method .returnType ());
34
- this .useJsonb = useJsonb ;
35
32
}
36
33
37
34
void addImportTypes (ControllerReader reader ) {
@@ -114,55 +111,37 @@ private void writeEnd() {
114
111
115
112
private void writeSyncResponse () {
116
113
writer .append (" " );
117
- writeResponse (returnType );
114
+ String type0 = returnType .mainType ();
115
+ String type1 = returnType .param0 ();
116
+ writeResponse (type0 , type1 );
118
117
}
119
118
120
119
private void writeAsyncResponse () {
121
120
writer .append (" .async()" );
122
- writeResponse (UType .parse (returnType .param0 ()));
121
+ String type0 = returnType .param0 ();
122
+ String type1 = returnType .param1 ();
123
+ writeResponse (type0 , type1 );
123
124
}
124
125
125
126
private void writeCallResponse () {
126
127
writer .append (" .call()" );
127
- writeResponse (UType .parse (returnType .param0 ()));
128
+ String type0 = returnType .param0 ();
129
+ String type1 = returnType .param1 ();
130
+ writeResponse (type0 , type1 );
128
131
}
129
132
130
- private void writeResponse (UType type ) {
131
- final var mainType = type .mainType ();
132
- final var param1 = type .paramRaw ();
133
- if (isList (mainType )) {
134
- writer .append (".list(" );
135
- writeGeneric (UType .parse (param1 ));
136
- } else if (isStream (mainType )) {
137
- writer .append (".stream(" );
138
- writeGeneric (UType .parse (param1 ));
139
- } else if (isHttpResponse (mainType )) {
133
+ private void writeResponse (String type0 , String type1 ) {
134
+ if (isList (type0 )) {
135
+ writer .append (".list(%s.class);" , Util .shortName (type1 )).eol ();
136
+ } else if (isStream (type0 )) {
137
+ writer .append (".stream(%s.class);" , Util .shortName (type1 )).eol ();
138
+ } else if (isHttpResponse (type0 )){
140
139
writeWithHandler ();
141
140
} else {
142
- writer .append (".bean(" , Util .shortName (mainType )).eol ();
143
- writeGeneric (type );
141
+ writer .append (".bean(%s.class);" , Util .shortName (type0 )).eol ();
144
142
}
145
143
}
146
144
147
- void writeGeneric (UType type ) {
148
- if (useJsonb && type .isGeneric ()) {
149
- final var params =
150
- type .importTypes ().stream ()
151
- .skip (1 )
152
- .map (Util ::shortName )
153
- .collect (Collectors .joining (".class, " ))
154
- + ".class" ;
155
-
156
- writer .append (
157
- "Types.newParameterizedType(%s.class, %s)" , Util .shortName (type .mainType ()), params );
158
- } else {
159
- writer .append ("%s.class" , Util .shortName (type .mainType ()));
160
- }
161
- writer .append (");" );
162
-
163
- writer .eol ();
164
- }
165
-
166
145
private void writeWithHandler () {
167
146
if (bodyHandlerParam != null ) {
168
147
writer .append (".handler(%s);" , bodyHandlerParam .name ()).eol ();
0 commit comments