Skip to content

Commit 9de6a88

Browse files
committed
Update to codegen changes
1 parent ec8aa1f commit 9de6a88

File tree

5 files changed

+28
-42
lines changed

5 files changed

+28
-42
lines changed

vertx-web-api-service/src/main/java/io/vertx/ext/web/api/service/generator/WebApiProxyHandlerGen.java

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,17 @@ public void generateActionSwitchEntry(ProxyMethodInfo m, CodeWriter writer) {
7979
.code(String.format("service.%s(\n", m.getName()))
8080
.indent().indent();
8181

82-
if (!m.isUseFutures()) {
83-
Stream<String> methodParamsTail = Stream.of("context", serviceCallHandler);
84-
writer.writeSeq(
85-
Stream.concat(
86-
((WebApiProxyMethodInfo) m).getParamsToExtract().stream().map(this::generateJsonParamExtractFromContext),
87-
methodParamsTail
88-
),
89-
",\n"
90-
);
91-
writer
92-
.unindent()
93-
.write(");\n");
94-
} else {
95-
Stream<String> methodParamsTail = Stream.of("context");
96-
writer.writeSeq(
97-
Stream.concat(
98-
((WebApiProxyMethodInfo) m).getParamsToExtract().stream().map(this::generateJsonParamExtractFromContext),
99-
methodParamsTail
100-
),
101-
",\n"
102-
);
103-
writer.write(")\n");
104-
writer
105-
.write(".onComplete(" + serviceCallHandler + ");\n");
106-
}
82+
Stream<String> methodParamsTail = Stream.of("context");
83+
writer.writeSeq(
84+
Stream.concat(
85+
((WebApiProxyMethodInfo) m).getParamsToExtract().stream().map(this::generateJsonParamExtractFromContext),
86+
methodParamsTail
87+
),
88+
",\n"
89+
);
90+
writer
91+
.unindent()
92+
.write(").onComplete(" + serviceCallHandler + ");\n");
10793
writer.unindent().unindent()
10894
.codeln("} catch (Exception e) {")
10995
.indent()

vertx-web-api-service/src/main/java/io/vertx/ext/web/api/service/generator/model/WebApiProxyMethodInfo.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public class WebApiProxyMethodInfo extends ProxyMethodInfo {
1919
final List<ParamInfo> paramsToExtract;
2020
final String requestContextName;
2121

22-
public WebApiProxyMethodInfo(Set<ClassTypeInfo> ownerTypes, String name, TypeInfo returnType, Text returnDescription, boolean fluent, boolean cacheReturn, List<ParamInfo> params, String comment, Doc doc, boolean staticMethod, boolean defaultMethod, List<TypeParamInfo.Method> typeParams, boolean proxyIgnore, boolean proxyClose, boolean deprecated, Text deprecatedDesc, boolean useFutures, boolean methodOverride) {
23-
super(ownerTypes, name, returnType, returnDescription, fluent, cacheReturn, params, comment, doc, staticMethod, defaultMethod, typeParams, proxyIgnore, proxyClose, deprecated, deprecatedDesc, useFutures, methodOverride);
24-
final int truncateParamsToIndex = useFutures ? 1 : 2;
22+
public WebApiProxyMethodInfo(Set<ClassTypeInfo> ownerTypes, String name, TypeInfo returnType, Text returnDescription, boolean fluent, boolean cacheReturn, List<ParamInfo> params, String comment, Doc doc, boolean staticMethod, boolean defaultMethod, List<TypeParamInfo.Method> typeParams, boolean proxyIgnore, boolean proxyClose, boolean deprecated, Text deprecatedDesc, boolean methodOverride) {
23+
super(ownerTypes, name, returnType, returnDescription, fluent, cacheReturn, params, comment, doc, staticMethod, defaultMethod, typeParams, proxyIgnore, proxyClose, deprecated, deprecatedDesc, methodOverride);
24+
final int truncateParamsToIndex = 1;
2525
paramsToExtract = params.subList(0, params.size() - truncateParamsToIndex);
2626
requestContextName = params.get(params.size() - truncateParamsToIndex).getName();
2727
}
@@ -44,7 +44,6 @@ public WebApiProxyMethodInfo(ProxyMethodInfo info) {
4444
info.isProxyClose(),
4545
info.isDeprecated(),
4646
info.getDeprecatedDesc(),
47-
info.isUseFutures(),
4847
info.isMethodOverride()
4948
);
5049
}

vertx-web-api-service/src/main/java/io/vertx/ext/web/api/service/generator/model/WebApiProxyModel.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,26 @@ protected void checkParamType(ExecutableElement elem, TypeInfo typeInfo, int pos
4545
}
4646

4747
@Override
48-
protected MethodInfo createMethodInfo(Set<ClassTypeInfo> ownerTypes, String methodName, String comment, Doc doc, TypeInfo returnType, Text returnDescription, boolean isFluent, boolean isCacheReturn, List<ParamInfo> mParams, ExecutableElement methodElt, boolean isStatic, boolean isDefault, ArrayList<TypeParamInfo.Method> typeParams, TypeElement declaringElt, boolean methodDeprecated, Text deprecatedDesc, boolean useFutures, boolean methodOverride) {
49-
ProxyMethodInfo baseInfo = (ProxyMethodInfo) super.createMethodInfo(ownerTypes, methodName, comment, doc, returnType, returnDescription, isFluent, isCacheReturn, mParams, methodElt, isStatic, isDefault, typeParams, declaringElt, methodDeprecated, deprecatedDesc, useFutures, methodOverride);
48+
protected MethodInfo createMethodInfo(Set<ClassTypeInfo> ownerTypes, String methodName, String comment, Doc doc, TypeInfo returnType, Text returnDescription, boolean isFluent, boolean isCacheReturn, List<ParamInfo> mParams, ExecutableElement methodElt, boolean isStatic, boolean isDefault, ArrayList<TypeParamInfo.Method> typeParams, TypeElement declaringElt, boolean methodDeprecated, Text methodDeprecatedDesc, boolean methodOverride) {
49+
ProxyMethodInfo baseInfo = (ProxyMethodInfo) super.createMethodInfo(ownerTypes, methodName, comment, doc, returnType, returnDescription, isFluent, isCacheReturn, mParams, methodElt, isStatic, isDefault, typeParams, declaringElt, methodDeprecated, deprecatedDesc, methodOverride);
5050
if (!isStatic && !baseInfo.isProxyClose()) {
5151
// Check signature constraints
5252

53-
TypeInfo ret;
54-
if (baseInfo.getKind() == MethodKind.FUTURE && baseInfo.isUseFutures()) {
55-
ret = ((ParameterizedTypeInfo)returnType).getArg(0);
56-
} else {
53+
if (!returnType.isParameterized()) {
54+
throw new GenException(methodElt, SIGNATURE_CONSTRAINT_ERROR);
55+
}
56+
ParameterizedTypeInfo pt = (ParameterizedTypeInfo) returnType;
57+
if (pt.getArgs().size() != 1) {
5758
throw new GenException(methodElt, SIGNATURE_CONSTRAINT_ERROR);
5859
}
60+
TypeInfo ret;
61+
ret = pt.getArg(0);
5962
if (!ServiceResponse.class.getName().equals(ret.getName())) {
6063
throw new GenException(methodElt, SIGNATURE_CONSTRAINT_ERROR);
6164
}
6265

6366
TypeInfo shouldBeServiceRequest;
64-
if (mParams.size() == 0) {
67+
if (mParams.isEmpty()) {
6568
throw new GenException(methodElt, SIGNATURE_CONSTRAINT_ERROR);
6669
}
6770
shouldBeServiceRequest = mParams.get(mParams.size() - 1).getType();
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.vertx.ext.web.api.service.generator.models;
22

3-
import io.vertx.core.AsyncResult;
4-
import io.vertx.core.Handler;
3+
import io.vertx.core.Future;
54
import io.vertx.ext.web.api.service.ServiceResponse;
65
import io.vertx.ext.web.api.service.WebApiServiceGen;
76

@@ -11,5 +10,5 @@
1110
@WebApiServiceGen
1211
public interface InvalidMissingContext {
1312

14-
void someMethod(Integer id, Handler<AsyncResult<ServiceResponse>> resultHandler);
13+
Future<ServiceResponse> someMethod(Integer id);
1514
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.vertx.ext.web.api.service.generator.models;
22

3-
import io.vertx.core.AsyncResult;
4-
import io.vertx.core.Handler;
3+
import io.vertx.core.Future;
54
import io.vertx.ext.web.api.service.ServiceRequest;
65
import io.vertx.ext.web.api.service.WebApiServiceGen;
76

@@ -11,5 +10,5 @@
1110
@WebApiServiceGen
1211
public interface InvalidWrongHandler {
1312

14-
void someMethod(ServiceRequest context, Handler<AsyncResult<Integer>> resultHandler);
13+
Future<Integer> someMethod(ServiceRequest context);
1514
}

0 commit comments

Comments
 (0)