vert-x3 / vertx-codetrans Goto Github PK
View Code? Open in Web Editor NEWCode translator
License: Apache License 2.0
Code translator
License: Apache License 2.0
Currently we only translate new DataObject()
and not new DataObject(JsonObject)
.
We should support at least this construction with a JsonObject literal such as new DataObject(new JsonObject().put("foo", "Foo"))
I found the same conversion issue that was fixed for example includes (#1) also happens when code is written in the adoc test.
I have adapted the reproducer to show the issue https://github.com/alexlehm/docgen-issue
renderJsonObjectToString (and related JsonArray-methods) needs to know what method is used for encoding (encode or encodePrettily) so I can map to the correct one on the Scala-side.
We can find this in the documentation about service discovery:
var client = reference.getAs(HttpClient.`class`)
but
HttpClient.`class`
isn't a valid Kotlin code
normally, we have to use HttpClient::class.java
val client = reference?.getAs(HttpClient::class.java)
The javascript generator append ; after each statements. Semi-colons are unnecessary after conditional structures:
Currently CodeWriter.renderNewMap and CodeWriter.renderNewList have an empty parameter list.
renderNewList should get one param to indicate the type of the list
renderNewMap should get two params indicating key and value-type of the map.
Ruby always produces \n
line endings while tests requre line endings to be system default (\r\n
on Windows)
It would be great if codetrans supported the accessing and translation of member variables.
For example, the vertx-web REST example currently does not translate because it uses member variables.
MethodSignature currently only provides param-types and names but no information about the return-type of the method.
All methods for JsonObjects and JsonArray (e.g. renderJsonObjectMemberSelect) should provide the actual method used on the Java-side as I need this in Scala to map to the correct types.
This is needed as Scala doesn't have native Json support and has to distinguish the types being used.
Function has been added to codegen. It should also be added here.
Buffer buff = Buffer.buffer();
for (int i = 0; i < buff.length(); i += 4) {
System.out.println("int value at " + i + " is " + buff.getInt(i));
}
method reduce
of class TreeScanner
while return 4
only, the Identifier i
has being discard.
when the method forLoop
of CodeBuilder invoker, update
only render 4
code of reduce
of class TreeScanner
public R reduce(R r1, R r2) {
return r1;
}
current the test does:
assertEquals("\\n\\r\\t\\f\\b\\\"\\\\'\\u0000A\\u007F", writer.getBuffer().toString());
it should evaluate the string and compare the eval.
when using a string with a char like "\u0000" in a java example, the converted string in Javascript and groovy is the binary representation of the string (including the nul char), which is kind of inconvenient (even though it may be allowed in javascript)
https://github.com/alexlehm/docgen-issue
(named the project docgen-issue before I noticed that this is actually in codetrans)
CodeBuilder.apiType should also get called for DataObjects because I need to import them on the Scala-side (no native Json-support, just as in Java)
Translated code does not compile if Java method returns short/byte/int/long/float/double/boolean/char or boxed equivalent.
Hey, I'm trying to have a browse of this repo but I'm not exactly sure how it works, how it relates to Vertx, and which files correspond to what. Is it possible to update the documentation to make it a little easier for possible contributors? ;)
Hi,
Java methods like isSuccessful are not correctly translated to Javascript. It will result in something like that:
Java code:
Request data = new Request().setInput(sampleInput);
ex.check(data, checkResult -> {
if(checkResult.succeeded()) {
if (checkResult.result().isSuccessful()) {
System.out.println("Yeah! ");
} else {
System.out.println("Nah!");
}
} else {
System.out.println("ERROR: "+checkResult.cause().getLocalizedMessage());
}
});
Generated JS code (copied from the adoc file):
var data = {
"input" : sampleInput
};
ex.check(data, function (checkResult, checkResult_err) {
if (checkResult_err == null) {
if (checkResult.uccessful) {
console.log("Yeah! ");
} else {
console.log("Nah!");
}
} else {
console.log("ERROR: " + checkResult_err.getLocalizedMessage());
}
});
Carefully look at line 6 of the Javascript: checkResult.uccessful instead of .successful
Reproducer: https://github.com/doernemt/vertx-codetrans-js-reproducer
As @cbeust mentioned me off the record, Kotlin code translated as:
var message = MailMessage()
message.from = "[email protected] (Example User)"
message.to = "[email protected]"
message.cc = "Another User <[email protected]>"
message.text = "this is the plain message text"
would be more idiomatic written with a val
and apply
:
val message = MailMessage().apply {
from = "[email protected] (Example User)"
to = "[email protected]"
cc = "Another User <[email protected]>"
text = "this is the plain message text"
}
CodeBuilder.enhancedForLoop needs to provide the TypeInfo of the object the enhancedforloop is called on.
This is important for Scala to know the type of collection it is called on so I can use the correct conversions.
Array declaration and creation support can be useful in some places like Postgres client examples of array value.
Some code writers can produce interpolated strings where the dollar sign is the special char.
If the original java code has a string which contains the dollar sign, the resulting snippet can be invalid.
i.e we handle fine:
foo(id -> {
// Block of statements
});
but not yet
foo(id -> /* expression */);
which result in a class cast exception:
java.lang.ClassCastException: com.sun.tools.javac.tree.JCTree$JCMethodInvocation cannot be cast to com.sun.source.tree.BlockTree
at io.vertx.codetrans.ModelBuilder.visitLambdaExpression(ModelBuilder.java:774)
at io.vertx.codetrans.ModelBuilder.visitLambdaExpression(ModelBuilder.java:88)
at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1628)
at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:68)
at io.vertx.codetrans.ModelBuilder.scan(ModelBuilder.java:123)
at io.vertx.codetrans.ModelBuilder.lambda$visitMethodInvocation$8(ModelBuilder.java:531)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.