lgrignon 2017-02-04 17:36:45 +01:00
parent 0a782017b0
commit 8041fba8b2
4 changed files with 19 additions and 5 deletions

View File

@ -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>

View File

@ -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) {

View File

@ -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));
}

View File

@ -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();
}