Skip to content

Commit 60d6e94

Browse files
committed
format
1 parent 807ab32 commit 60d6e94

File tree

1 file changed

+56
-63
lines changed

1 file changed

+56
-63
lines changed

http-generator-client/src/main/java/io/avaje/http/generator/client/ClientMethodWriter.java

Lines changed: 56 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
package io.avaje.http.generator.client;
22

3-
import java.util.Set;
3+
import io.avaje.http.generator.core.*;
44

55
import javax.lang.model.element.TypeElement;
6-
7-
import io.avaje.http.generator.core.Append;
8-
import io.avaje.http.generator.core.BeanParamReader;
9-
import io.avaje.http.generator.core.ControllerReader;
10-
import io.avaje.http.generator.core.MethodParam;
11-
import io.avaje.http.generator.core.MethodReader;
12-
import io.avaje.http.generator.core.ParamType;
13-
import io.avaje.http.generator.core.PathSegments;
14-
import io.avaje.http.generator.core.ProcessingContext;
15-
import io.avaje.http.generator.core.UType;
16-
import io.avaje.http.generator.core.Util;
17-
import io.avaje.http.generator.core.WebMethod;
6+
import java.util.Set;
187

198
/** Write code to register Web route for a given controller method. */
209
class ClientMethodWriter {
@@ -53,15 +42,15 @@ void addImportTypes(ControllerReader reader) {
5342
}
5443

5544
private void methodStart(Append writer) {
56-
for (final MethodParam param : method.params()) {
45+
for (MethodParam param : method.params()) {
5746
checkBodyHandler(param);
5847
}
5948
writer.append(" // %s %s", webMethod, method.webMethodPath()).eol();
6049
writer.append(" @Override").eol();
6150
writer.append(
6251
" public %s%s %s(", methodGenericParams, returnType.shortType(), method.simpleName());
63-
var count = 0;
64-
for (final MethodParam param : method.params()) {
52+
int count = 0;
53+
for (MethodParam param : method.params()) {
6554
if (count++ > 0) {
6655
writer.append(", ");
6756
}
@@ -88,8 +77,8 @@ void write() {
8877
}
8978
writer.append("clientContext.request()").eol();
9079

91-
final var pathSegments = method.pathSegments();
92-
final var segments = pathSegments.segments();
80+
PathSegments pathSegments = method.pathSegments();
81+
Set<PathSegments.Segment> segments = pathSegments.segments();
9382

9483
writeHeaders();
9584
writePaths(segments);
@@ -101,43 +90,45 @@ void write() {
10190
}
10291

10392
private void writeEnd() {
104-
final var webMethod = method.webMethod();
93+
WebMethod webMethod = method.webMethod();
10594
writer.append(" .%s()", webMethod.name()).eol();
10695
if (returnType == UType.VOID) {
10796
writer.append(" .asVoid();").eol();
10897
} else {
109-
final var known = KNOWN_RESPONSE.get(returnType.full());
98+
String known = KNOWN_RESPONSE.get(returnType.full());
11099
if (known != null) {
111100
writer.append(" %s", known).eol();
112-
}else if (COMPLETABLE_FUTURE.equals(returnType.mainType())) {
113-
writeAsyncResponse();
114-
} else if (HTTP_CALL.equals(returnType.mainType())) {
115-
writeCallResponse();
116-
} else {
117-
writeSyncResponse();
118-
}
101+
} else {
102+
if (COMPLETABLE_FUTURE.equals(returnType.mainType())) {
103+
writeAsyncResponse();
104+
} else if (HTTP_CALL.equals(returnType.mainType())) {
105+
writeCallResponse();
106+
} else {
107+
writeSyncResponse();
108+
}
109+
}
119110
}
120111
writer.append(" }").eol().eol();
121112
}
122113

123114
private void writeSyncResponse() {
124115
writer.append(" ");
125-
final var type0 = returnType.mainType();
126-
final var type1 = returnType.param0();
116+
String type0 = returnType.mainType();
117+
String type1 = returnType.param0();
127118
writeResponse(type0, type1);
128119
}
129120

130121
private void writeAsyncResponse() {
131122
writer.append(" .async()");
132-
final var type0 = returnType.param0();
133-
final var type1 = returnType.param1();
123+
String type0 = returnType.param0();
124+
String type1 = returnType.param1();
134125
writeResponse(type0, type1);
135126
}
136127

137128
private void writeCallResponse() {
138129
writer.append(" .call()");
139-
final var type0 = returnType.param0();
140-
final var type1 = returnType.param1();
130+
String type0 = returnType.param0();
131+
String type1 = returnType.param1();
141132
writeResponse(type0, type1);
142133
}
143134

@@ -162,21 +153,23 @@ private void writeWithHandler() {
162153
}
163154

164155
private void writeQueryParams(PathSegments pathSegments) {
165-
for (final MethodParam param : method.params()) {
166-
final var paramType = param.paramType();
167-
if ((paramType == ParamType.QUERYPARAM) && (pathSegments.segment(param.paramName()) == null)) {
168-
if (isMap(param)) {
169-
writer.append(" .queryParam(%s)", param.name()).eol();
170-
} else {
171-
writer.append(" .queryParam(\"%s\", %s)", param.paramName(), param.name()).eol();
172-
}
173-
}
156+
for (MethodParam param : method.params()) {
157+
ParamType paramType = param.paramType();
158+
if (paramType == ParamType.QUERYPARAM) {
159+
if (pathSegments.segment(param.paramName()) == null) {
160+
if (isMap(param)) {
161+
writer.append(" .queryParam(%s)", param.name()).eol();
162+
} else {
163+
writer.append(" .queryParam(\"%s\", %s)", param.paramName(), param.name()).eol();
164+
}
165+
}
166+
}
174167
}
175168
}
176169

177170
private void writeHeaders() {
178-
for (final MethodParam param : method.params()) {
179-
final var paramType = param.paramType();
171+
for (MethodParam param : method.params()) {
172+
ParamType paramType = param.paramType();
180173
if (paramType == ParamType.HEADER) {
181174
if (isMap(param)) {
182175
writer.append(" .header(%s)", param.name()).eol();
@@ -188,13 +181,13 @@ private void writeHeaders() {
188181
}
189182

190183
private void writeBeanParams(PathSegments segments) {
191-
for (final MethodParam param : method.params()) {
192-
final var varName = param.name();
193-
final var paramType = param.paramType();
194-
final var segment = segments.segment(varName);
184+
for (MethodParam param : method.params()) {
185+
final String varName = param.name();
186+
ParamType paramType = param.paramType();
187+
PathSegments.Segment segment = segments.segment(varName);
195188
if (segment == null && paramType == ParamType.BEANPARAM) {
196-
final var formBeanType = ctx.typeElement(param.rawType());
197-
final var form =
189+
TypeElement formBeanType = ctx.typeElement(param.rawType());
190+
BeanParamReader form =
198191
new BeanParamReader(
199192
ctx, formBeanType, param.name(), param.shortType(), ParamType.QUERYPARAM);
200193
form.writeFormParams(writer);
@@ -203,10 +196,10 @@ private void writeBeanParams(PathSegments segments) {
203196
}
204197

205198
private void writeFormParams(PathSegments segments) {
206-
for (final MethodParam param : method.params()) {
207-
final var varName = param.name();
208-
final var paramType = param.paramType();
209-
final var segment = segments.segment(varName);
199+
for (MethodParam param : method.params()) {
200+
final String varName = param.name();
201+
ParamType paramType = param.paramType();
202+
PathSegments.Segment segment = segments.segment(varName);
210203
if (segment == null) {
211204
// not a path or matrix parameter
212205
writeFormParam(param, paramType);
@@ -222,17 +215,17 @@ private void writeFormParam(MethodParam param, ParamType paramType) {
222215
writer.append(" .formParam(\"%s\", %s)", param.paramName(), param.name()).eol();
223216
}
224217
} else if (paramType == ParamType.FORM) {
225-
final var formBeanType = ctx.typeElement(param.rawType());
226-
final var form =
218+
TypeElement formBeanType = ctx.typeElement(param.rawType());
219+
BeanParamReader form =
227220
new BeanParamReader(
228221
ctx, formBeanType, param.name(), param.shortType(), ParamType.FORMPARAM);
229222
form.writeFormParams(writer);
230223
}
231224
}
232225

233226
private void writeBody() {
234-
for (final MethodParam param : method.params()) {
235-
final var paramType = param.paramType();
227+
for (MethodParam param : method.params()) {
228+
ParamType paramType = param.paramType();
236229
if (paramType == ParamType.BODY) {
237230
writer.append(" .body(%s)", param.name()).eol();
238231
}
@@ -243,7 +236,7 @@ private void writePaths(Set<PathSegments.Segment> segments) {
243236
if (!segments.isEmpty()) {
244237
writer.append(" ");
245238
}
246-
for (final PathSegments.Segment segment : segments) {
239+
for (PathSegments.Segment segment : segments) {
247240
if (segment.isLiteral()) {
248241
writer.append(".path(\"").append(segment.literalSection()).append("\")");
249242
} else {
@@ -261,18 +254,18 @@ private boolean isMap(MethodParam param) {
261254
}
262255

263256
private boolean isMap(String type0) {
264-
return "java.util.Map".equals(type0);
257+
return type0.equals("java.util.Map");
265258
}
266259

267260
private boolean isList(String type0) {
268-
return "java.util.List".equals(type0);
261+
return type0.equals("java.util.List");
269262
}
270263

271264
private boolean isStream(String type0) {
272-
return "java.util.stream.Stream".equals(type0);
265+
return type0.equals("java.util.stream.Stream");
273266
}
274267

275268
private boolean isHttpResponse(String type0) {
276-
return "java.net.http.HttpResponse".equals(type0);
269+
return type0.equals("java.net.http.HttpResponse");
277270
}
278271
}

0 commit comments

Comments
 (0)