Skip to content

Commit

Permalink
fix: JVM method names cannot be keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Oct 28, 2024
1 parent 3277cee commit 4c50b8a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/java/echo/src/main/java/ftl/echo/Echo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Echo {
@Export
@Verb
public EchoResponse echo(EchoRequest req, TimeClient time) {
var response = time.call();
var response = time.time();
return new EchoResponse("Hello, " + req.name().orElse("anonymous") + "! The time is " + response.toString() + ".");
}
}
2 changes: 1 addition & 1 deletion examples/kotlin/echo/src/main/kotlin/ftl/echo/Echo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ data class EchoResponse(val message: String)
@Export
@Verb
fun echo(req: EchoRequest, time: TimeClient): EchoResponse {
val response = time.call()
val response = time.time()
return EchoResponse(message = "Hello, ${req.name ?: "anonymous"}! The time is ${response.time}.")
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,16 @@ protected void generateDataObject(Module module, Data data, String packageName,
protected void generateVerb(Module module, Verb verb, String packageName, Map<DeclRef, Type> typeAliasMap,
Map<DeclRef, String> nativeTypeAliasMap, Path outputDir)
throws IOException {
TypeSpec.Builder clientBuilder = TypeSpec.interfaceBuilder(className(verb.getName()) + CLIENT)
String verbName = verb.getName();
TypeSpec.Builder clientBuilder = TypeSpec.interfaceBuilder(className(verbName) + CLIENT)
.addModifiers(Modifier.PUBLIC)
.addJavadoc("A client for the $L.$L verb", module.getName(), verb.getName());
.addJavadoc("A client for the $L.$L verb", module.getName(), verbName);

MethodSpec.Builder callMethod = MethodSpec.methodBuilder(verb.getName())
var methodName = verbName;
if (JAVA_KEYWORDS.contains(verbName)) {
methodName = verbName + "_";
}
MethodSpec.Builder callMethod = MethodSpec.methodBuilder(methodName)
.addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC)
.addAnnotation(AnnotationSpec.builder(VerbClient.class)
.addMember("module", "\"" + module.getName() + "\"")
Expand Down

0 comments on commit 4c50b8a

Please sign in to comment.