mirror of
https://github.com/cincheo/jsweet.git
synced 2026-02-07 14:06:35 +00:00
integrated PR https://github.com/cincheo/jsweet/pull/217 fixing https://github.com/cincheo/jsweet/issues/216
This commit is contained in:
parent
0a782017b0
commit
8041fba8b2
@ -7,7 +7,7 @@
|
||||
</condition>
|
||||
|
||||
<target name="install-toolsjar">
|
||||
<property name="lib.path" value="C:/Program Files/Java/jdk1.8.0_60/lib/tools.jar">
|
||||
<property name="lib.path" value="${env.JAVA_HOME}/lib/tools.jar">
|
||||
</property>
|
||||
<echo>installing local tools.jar in local maven: ${lib.path}</echo>
|
||||
<echo>Java home: ${env.JAVA_HOME}</echo>
|
||||
|
||||
@ -1559,9 +1559,10 @@ public class Java2TypeScriptAdapter<C extends JSweetContext> extends AbstractPri
|
||||
if (assignedType.tsym.isInterface() && !context.isFunctionalType(assignedType.tsym)) {
|
||||
JCLambda lambda = (JCLambda) expression;
|
||||
MethodSymbol method = (MethodSymbol) assignedType.tsym.getEnclosedElements().get(0);
|
||||
print("(() => { " + VAR_DECL_KEYWORD + " f = function() { this." + method.getSimpleName() + " = ")
|
||||
.print(lambda);
|
||||
print("}; return new f(); })()");
|
||||
print("(() => { ");
|
||||
print(VAR_DECL_KEYWORD + " v = ").print(lambda).print(";");
|
||||
print(VAR_DECL_KEYWORD + " f = function() { this." + method.getSimpleName() + " = v; };");
|
||||
print("return new f(); })()");
|
||||
return true;
|
||||
}
|
||||
} else if (expression instanceof JCNewClass) {
|
||||
|
||||
@ -206,7 +206,7 @@ public class SyntaxTests extends AbstractTest {
|
||||
public void testLambdasWithInterfaces() {
|
||||
eval((logHandler, r) -> {
|
||||
Assert.assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
assertEquals("ok1,ok2,ok3,ok4", r.get("trace"));
|
||||
assertEquals("ok1,ok2,ok3,ok4,ok5", r.get("trace"));
|
||||
}, getSourceFile(LambdasWithInterfaces.class));
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,8 @@ public class LambdasWithInterfaces {
|
||||
|
||||
static Array<String> trace = new Array<String>();
|
||||
|
||||
private final String result = "ok5";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new LambdasWithInterfaces().handler(new ANonFunctionalInterface2() {
|
||||
|
||||
@ -25,6 +27,9 @@ public class LambdasWithInterfaces {
|
||||
new LambdasWithInterfaces().handler4(() -> {
|
||||
trace.push("ok4");
|
||||
});
|
||||
|
||||
new LambdasWithInterfaces().test5();
|
||||
|
||||
$export("trace", trace.join(","));
|
||||
}
|
||||
|
||||
@ -40,6 +45,10 @@ public class LambdasWithInterfaces {
|
||||
i.m();
|
||||
}
|
||||
|
||||
public void test5() {
|
||||
ClosureOverFieldInterface5 i = () -> trace.push(result);
|
||||
i.m();
|
||||
}
|
||||
}
|
||||
|
||||
interface ANonFunctionalInterface2 {
|
||||
@ -54,3 +63,7 @@ interface AFunctionalInterface3 {
|
||||
interface AFunctionalInterface4 {
|
||||
void m();
|
||||
}
|
||||
|
||||
interface ClosureOverFieldInterface5 {
|
||||
void m();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user