<NME> LambdaExpressionTest.java
<BEF> /*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.devtools.j2objc.ast;

import com.google.devtools.j2objc.GenerationTest;
import java.io.IOException;

/**
 * Unit tests for {@link LambdaExpression}.
 *
 * @author Seth Kirby
 */
public class LambdaExpressionTest extends GenerationTest {

  private String functionHeader = "interface Function<T, R> { R apply(T t); }";
  private String fourToOneHeader = "interface FourToOne<F, G, H, I, R> {"
      + "  R apply(F f, G g, H h, I i); }";

  public void testCaptureDetection() throws IOException {
    translateSourceFile(functionHeader + "interface A { boolean r(boolean a);"
        + "default int ret1() { return 2; }} interface B { default int ret() { return 1; } }"
        + "class Test { void f() { ((A & B)(a) -> a).ret(); } }", "Test", "Test.m");
    translateSourceFile(functionHeader + "interface A2 { boolean r();"
        + "default int ret1() { return 2; }} interface B { default int ret() { return 1; } }"
        + "class Test { void f() { ((A2 & B)() -> true).ret(); } }", "Test", "Test.m");
    String nonCaptureTranslation = translateSourceFile(
        functionHeader + "class Test { Function f = x -> x;}", "Test", "Test.m");
    String captureTranslationOuter = translateSourceFile(
        functionHeader + "class Test { int y; Function f = x -> y;}", "Test", "Test.m");
    String captureTranslation = translateSourceFile(
        functionHeader + "class Test { Function<Function, Function> f = y -> x -> y;}", "Test",
        "Test.m");
    assertTranslation(nonCaptureTranslation, "Test_$Lambda$1_get_instance(void);");
    assertTranslatedLines(captureTranslationOuter,
        "@interface Test_$Lambda$1 : NSObject < Function > {",
        " @public",
        "  Test *this$0_;",
        "}");
    assertTranslation(captureTranslation, "Test_$Lambda$1_get_instance(void);");
    assertTranslatedLines(captureTranslation,
        "@interface Test_$Lambda$2 : NSObject < Function > {",
        " @public",
        "  id<Function> val$y_;",
        "}");
  }

  public void testTypeInference() throws IOException {
    String quadObjectTranslation = translateSourceFile(
        fourToOneHeader + "class Test { FourToOne f = (a, b, c, d) -> 1;}", "Test", "Test.m");
    assertTranslatedLines(quadObjectTranslation,
        "- (id)applyWithId:(id)a",
        "           withId:(id)b",
        "           withId:(id)c",
        "           withId:(id)d {",
        "  return JavaLangInteger_valueOfWithInt_(1);",
        "}");
    String mixedObjectTranslation = translateSourceFile(fourToOneHeader
        + "class Test { FourToOne<String, Double, Integer, Boolean, String> f = "
        + "(a, b, c, d) -> \"1\";}", "Test", "Test.m");
    assertTranslatedLines(mixedObjectTranslation,
        "- (id)applyWithId:(NSString *)a",
        "           withId:(JavaLangDouble *)b",
        "           withId:(JavaLangInteger *)c",
        "           withId:(JavaLangBoolean *)d {",
        "  return @\"1\";",
        "}");
  }

  public void testOuterFunctions() throws IOException {
    String translation = translateSourceFile(
        functionHeader + "class Test { Function outerF = (x) -> x;}", "Test", "Test.m");
    assertTranslation(translation,
        "JreStrongAssign(&self->outerF_, JreLoadStatic(Test_$Lambda$1, instance));");
  }

  public void testStaticFunctions() throws IOException {
    String translation = translateSourceFile(
        functionHeader + "class Test { static Function staticF = (x) -> x;}", "Test", "Test.m");
    assertTranslatedSegments(translation,
        "id<Function> Test_staticF;",
        "if (self == [Test class]) {",
        "JreStrongAssign(&Test_staticF, JreLoadStatic(Test_$Lambda$1, instance))");
  }

  public void testNestedLambdas() throws IOException {
    String outerCapture = translateSourceFile(functionHeader
        + "class Test { Function<String, Function<String, String>> f = x -> y -> x;}", "Test",
        "Test.m");
    assertTranslation(outerCapture, "Test_$Lambda$1_get_instance(void);");
    assertTranslatedLines(outerCapture,
        "- (id)applyWithId:(NSString *)x {",
        "  return create_Test_$Lambda$2_initWithNSString_(x);",
        "}");
    assertTranslatedLines(outerCapture,
        "@interface Test_$Lambda$2 : NSObject < Function > {",
        " @public",
        "  NSString *val$x_;",
        "}");
    assertTranslatedLines(outerCapture,
        "- (id)applyWithId:(NSString *)y {",
        "  return JreRetainedLocalValue(val$x_);",
        "}");
    String noCapture = translateSourceFile(functionHeader
        + "class Test { Function<String, Function<String, String>> f = x -> y -> y;}", "Test",
        "Test.m");
    assertTranslation(noCapture, "Test_$Lambda$1_get_instance(void);");
    assertTranslation(noCapture, "Test_$Lambda$2_get_instance(void);");
    assertTranslatedLines(noCapture,
        "- (id)applyWithId:(NSString *)x {",
        "  return JreRetainedLocalValue(JreLoadStatic(Test_$Lambda$2, instance));",
        "}");
    assertTranslatedLines(noCapture,
        "- (id)applyWithId:(NSString *)y {",
        "  return JreRetainedLocalValue(y);",
        "}");
  }

  // There's no need for a cast_check call on a lambda whose type matches the assigned type.
  public void testNoCastCheck() throws IOException {
    String translation = translateSourceFile(
        functionHeader + "class Test { Function f = (Function) (x) -> x;}", "Test", "Test.m");
    assertNotInTranslation(translation, "cast_check");
  }

  // Test that we aren't trying to import lambda types.
  public void testImportExclusion() throws IOException {
    String translation = translateSourceFile(
        functionHeader + "class Test { Function f = (Function) (x) -> x;}", "Test", "Test.m");
    assertNotInTranslation(translation, "lambda$0.h");
  }

  // Check that lambdas are uniquely named.
  public void testLambdaUniquify() throws IOException {
    String translation = translateSourceFile(functionHeader
        + "class Test { class Foo{ class Bar { Function f = x -> x; }}\n"
        + "Function f = x -> x;}",
        "Test", "Test.m");
    assertTranslation(translation, "@interface Test_Foo_Bar_$Lambda$1 : NSObject < Function >");
    assertTranslation(translation, "@interface Test_$Lambda$1 : NSObject < Function >");
  }
    String translation = translateSourceFile(functionHeader
        + "class Test { void f(int operator) { Function l = (a) -> operator; } }",
        "Test", "Test.m");
    assertTranslatedSegments(translation, "captures->operator_ =");
  }

  public void testLargeArgumentCount() throws IOException {
  }

  public void testLargeArgumentCount() throws IOException {
    String interfaceHeader = "interface TooManyArgs<T> { T f(T a, T b, T c, T d, T e, T f, T g,"
        + " T h, T i, T j, T k, T l, T m, T n, T o, T p, T q, T r, T s, T t, T u, T v, T w, T x,"
        + " T y, T z, T aa, T ab, T ac, T ad, T ae, T af, T ag, T ah, T ai, T aj, T ak, T al,"
        + " T am, T an, T ao, T ap, T aq, T ar, T as, T at, T au, T av, T aw, T ax, T ay, T az,"
        + " T ba, T bb, T bc, T bd, T be, T bf, T bg, T bh, T bi, T bj, T bk, T bl, T bm, T bn,"
        + " T bo, T bp, T bq, T br, T bs, T bt, T bu, T bv, T bw, T bx, T by, T bz, T foo);}";
    String translation = translateSourceFile(interfaceHeader + "class Test { void a() {"
        + "Object foo = \"Foo\";"
        + "TooManyArgs fun = (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w,"
        + " x, y, z, aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am, an, ao, ap, aq, ar, as,"
        + " at, au, av, aw, ax, ay, az, ba, bb, bc, bd, be, bf, bg, bh, bi, bj, bk, bl, bm, bn,"
        + " bo, bp, bq, br, bs, bt, bu, bv, bw, bx, by, bz, bar) -> foo;}}",
        "Test", "Test.m");
    assertTranslatedLines(translation,
        "- (id)fWithId:(id)a",
        "       withId:(id)b",
        "       withId:(id)c",
        "       withId:(id)d",
        "       withId:(id)e");
    assertTranslatedLines(translation,
        "       withId:(id)bw",
        "       withId:(id)bx",
        "       withId:(id)by",
        "       withId:(id)bz",
        "       withId:(id)bar {",
        "  return JreRetainedLocalValue(val$foo_);",
        "}");
  }

  public void testCapturingBasicTypeReturn() throws IOException {
    String header = "interface I { int foo(); }";
    String translation = translateSourceFile(
        header + "class Test { int f = 1234; void foo() { I i = () -> f; } }", "Test",
        "Test.m");
    assertTranslatedLines(translation,
        "- (jint)foo {",
        "  return this$0_->f_;",
        "}");
  }

  // Verify that an #include is generated for the lambda's functionalType.
  public void testLambdaFunctionalTypeImport() throws IOException {
    String translation = translateSourceFile("import java.util.*;"
        + "class Test { "
        + "  public void test(List<String> names) { "
        + "    Collections.sort(names, (p1, p2) -> p1.compareTo(p2)); "
        + "  }"
        + "}", "Test", "Test.m");
    assertTranslation(translation, "#include \"java/util/Comparator.h\"");
  }

  public void testClassLiteralNamesInLambda() throws IOException {
    String translation = translateSourceFile("package foo.bar; import java.io.Serializable; "
        + "interface Comparator<T> {"
        + "  int compare(T o1, T o2);"
        + "  default Comparator<T> thenComparing(Comparator<? super T> other) {"
        + "    return (Comparator<T> & Serializable) (c1, c2) -> {"
        + "      int res = compare(c1, c2);"
        + "      return (res != 0) ? res : other.compare(c1, c2);"
        + "    }; "
        + "  }"
        + "}", "Comparator", "foo/bar/Comparator.m");
    assertTranslatedLines(translation,
        "@interface FooBarComparator_$Lambda$1 : "
            + "NSObject < FooBarComparator, JavaIoSerializable > {",
        " @public",
        "  id<FooBarComparator> this$0_;",
        "  id<FooBarComparator> val$other_;",
        "}");
    assertTranslatedLines(translation,
        "- (jint)compareWithId:(id)c1",
        "               withId:(id)c2 {",
        "  jint res = [this$0_ compareWithId:c1 withId:c2];",
        "  return (res != 0) ? res : [((id<FooBarComparator>) nil_chk(val$other_)) "
            + "compareWithId:c1 withId:c2];",
        "}");
  }
}

<MSG> Issue #777: hid local variables in generated lambdas.

	Change on 2016/08/17 by tball <tball@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=130529109

<DFF> @@ -152,7 +152,7 @@ public class LambdaExpressionTest extends GenerationTest {
     String translation = translateSourceFile(functionHeader
         + "class Test { void f(int operator) { Function l = (a) -> operator; } }",
         "Test", "Test.m");
-    assertTranslatedSegments(translation, "captures->operator_ =");
+    assertTranslatedSegments(translation, "captures__->operator_ =");
   }
 
   public void testLargeArgumentCount() throws IOException {

{'commit': 'diff --git a/translator/src/main/java/com/google/devtools/j2objc/translate/LambdaRewriter.java b/translator/src/main/java/com/google/devtools/j2objc/translate/LambdaRewriter.java\nindex 9a5f20558..2a02ad772 100644\n--- a/translator/src/main/java/com/google/devtools/j2objc/translate/LambdaRewriter.java\n+++ b/translator/src/main/java/com/google/devtools/j2objc/translate/LambdaRewriter.java\n@@ -276,21 +276,21 @@ public class LambdaRewriter extends TreeVisitor {\n       String lambdaCaptureStructName = lambdaName + "_captures";\n       statements.add(\n           new NativeStatement(\n-              "LambdaBase<" + funcWithoutID + "> *result = NSAllocateObject(cls, sizeof("\n+              "LambdaBase<" + funcWithoutID + "> *result__ = NSAllocateObject(cls, sizeof("\n               + lambdaCaptureStructName + "), nil);"));\n       statements.add(\n           new NativeStatement(\n-              lambdaCaptureStructName + " *captures = (" + lambdaCaptureStructName\n-              + " *) &result->captures_;"));\n+              lambdaCaptureStructName + " *captures__ = (" + lambdaCaptureStructName\n+              + " *) &result__->captures_;"));\n       funcImplStatements.add(\n           0,\n           new NativeStatement(\n-              lambdaCaptureStructName + " *captures = (" + lambdaCaptureStructName\n+              lambdaCaptureStructName + " *captures__ = (" + lambdaCaptureStructName\n               + " *) &self_->captures_;"));\n       funcDeallocStatements.add(\n           0,\n           new NativeStatement(\n-              lambdaCaptureStructName + " *captures = (" + lambdaCaptureStructName\n+              lambdaCaptureStructName + " *captures__ = (" + lambdaCaptureStructName\n               + " *) &self_->captures_;"));\n \n       // Add an outerField to the capture struct (and init of the capture struct) if we have one.\n@@ -302,18 +302,18 @@ public class LambdaRewriter extends TreeVisitor {\n             + outerField.getSimpleName().toString() + ";\\n";\n         statements.add(\n             new NativeStatement(\n-                "captures->" + outerField.getSimpleName().toString()\n+                "captures__->" + outerField.getSimpleName().toString()\n                 + " = [" + outerField.getSimpleName().toString() + "_ retain];"));\n         funcDeallocStatements.add(\n             new NativeStatement(\n-                "[captures->" + outerField.getSimpleName().toString() + " release];"));\n+                "[captures__->" + outerField.getSimpleName().toString() + " release];"));\n \n         // Note that the init of the captures struct is 0 in funcImplStatements.\n         funcImplStatements.add(\n             1,\n             new NativeStatement(\n                 nameTable.getObjCType(outerField.asType())\n-                + " " + outerField.getSimpleName().toString() + "_ = captures->"\n+                + " " + outerField.getSimpleName().toString() + "_ = captures__->"\n                 + outerField.getSimpleName().toString() + ";"));\n         // TODO(user): This self should be unnecessary, but SuperMethodInvocationRewriter\n         // adds a ThisExpression node after the OuterReferenceResolver has already run, so it\n@@ -322,7 +322,7 @@ public class LambdaRewriter extends TreeVisitor {\n             2,\n             new NativeStatement(\n                 nameTable.getObjCType(outerField.asType())\n-                + " self = captures->" + outerField.getSimpleName().toString() + ";"));\n+                + " self = captures__->" + outerField.getSimpleName().toString() + ";"));\n \n         funcGet.addParameter(new SingleVariableDeclaration(outerField));\n \n@@ -351,26 +351,26 @@ public class LambdaRewriter extends TreeVisitor {\n         if (!var.asType().getKind().isPrimitive() && !ElementUtil.isWeakReference(var)) {\n           statements.add(\n               new NativeStatement(\n-                  "JreStrongAssign(&captures->" + varName + ", " + varName + ");"));\n+                  "JreStrongAssign(&captures__->" + varName + ", " + varName + ");"));\n           funcDeallocStatements.add(\n               1,\n               new NativeStatement(\n-                  "RELEASE_(captures->" + varName + ");"));\n+                  "RELEASE_(captures__->" + varName + ");"));\n         } else {\n           statements.add(\n               new NativeStatement(\n-                  "captures->" + varName + " = " + varName + ";"));\n+                  "captures__->" + varName + " = " + varName + ";"));\n         }\n         funcImplStatements.add(\n             1,\n             new NativeStatement(\n                 nameTable.getObjCType(var.asType()) + " " + varName\n-                + " = captures->" + varName + ";"));\n+                + " = captures__->" + varName + ";"));\n         funcGet.addParameter(new SingleVariableDeclaration(var));\n         funcGetInvocation.addArgument(Name.newName(varPath));\n       }\n \n-      statements.add(new NativeStatement("return [result autorelease];"));\n+      statements.add(new NativeStatement("return [result__ autorelease];"));\n \n       // Make the closure struct.\n       NativeDeclaration lambdaCaptureStruct =\ndiff --git a/translator/src/test/java/com/google/devtools/j2objc/ast/LambdaExpressionTest.java b/translator/src/test/java/com/google/devtools/j2objc/ast/LambdaExpressionTest.java\nindex d3c28f89c..3884cb5cb 100644\n--- a/translator/src/test/java/com/google/devtools/j2objc/ast/LambdaExpressionTest.java\n+++ b/translator/src/test/java/com/google/devtools/j2objc/ast/LambdaExpressionTest.java\n@@ -152,7 +152,7 @@ public class LambdaExpressionTest extends GenerationTest {\n     String translation = translateSourceFile(functionHeader\n         + "class Test { void f(int operator) { Function l = (a) -> operator; } }",\n         "Test", "Test.m");\n-    assertTranslatedSegments(translation, "captures->operator_ =");\n+    assertTranslatedSegments(translation, "captures__->operator_ =");\n   }\n \n   public void testLargeArgumentCount() throws IOException {\n', 'commit_subject': 'Issue #777: hid local variables in generated lambdas.', 'repo_name': 'google/j2objc', 'committer': {'name': 'Tom Ball', 'email': '413a605d00e3df24790ca07c68ba8993b8d2bae1@google.com', 'time_sec': '1473291270', 'tz_offset': '-420', 'date': {'seconds': '1473291270'}}, 'commit_tree': 'adb7a5d92e821e0087c3ab073f62ccd24856b224', 'commit_message': 'Issue #777: hid local variables in generated lambdas.\n\n\tChange on 2016/08/17 by tball <tball@google.com>\n\n-------------\nCreated by MOE: https://github.com/google/moe\nMOE_MIGRATED_REVID=130529109\n', 'language_name': 'Python', 'license': 'apache-2.0', 'hunks': '@@ -152,7 +152,7 @@ public class LambdaExpressionTest extends GenerationTest {\n     String translation = translateSourceFile(functionHeader\n         + "class Test { void f(int operator) { Function l = (a) -> operator; } }",\n         "Test", "Test.m");\n-    assertTranslatedSegments(translation, "captures->operator_ =");\n+    assertTranslatedSegments(translation, "captures__->operator_ =");\n   }\n \n   public void testLargeArgumentCount() throws IOException {\n', 'addition_count': 1, 'deletion_count': 1, 'src_file': 'a/translator/src/test/java/com/google/devtools/j2objc/ast/LambdaExpressionTest.java', 'tgt_file': 'b/translator/src/test/java/com/google/devtools/j2objc/ast/LambdaExpressionTest.java', 'file_extension': '.java', 'before_file': '/*\n * Licensed under the Apache License, Version 2.0 (the "License");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an "AS IS" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage com.google.devtools.j2objc.ast;\n\nimport com.google.devtools.j2objc.GenerationTest;\nimport java.io.IOException;\n\n/**\n * Unit tests for {@link LambdaExpression}.\n *\n * @author Seth Kirby\n */\npublic class LambdaExpressionTest extends GenerationTest {\n\n  private String functionHeader = "interface Function<T, R> { R apply(T t); }";\n  private String fourToOneHeader = "interface FourToOne<F, G, H, I, R> {"\n      + "  R apply(F f, G g, H h, I i); }";\n\n  public void testCaptureDetection() throws IOException {\n    translateSourceFile(functionHeader + "interface A { boolean r(boolean a);"\n        + "default int ret1() { return 2; }} interface B { default int ret() { return 1; } }"\n        + "class Test { void f() { ((A & B)(a) -> a).ret(); } }", "Test", "Test.m");\n    translateSourceFile(functionHeader + "interface A2 { boolean r();"\n        + "default int ret1() { return 2; }} interface B { default int ret() { return 1; } }"\n        + "class Test { void f() { ((A2 & B)() -> true).ret(); } }", "Test", "Test.m");\n    String nonCaptureTranslation = translateSourceFile(\n        functionHeader + "class Test { Function f = x -> x;}", "Test", "Test.m");\n    String captureTranslationOuter = translateSourceFile(\n        functionHeader + "class Test { int y; Function f = x -> y;}", "Test", "Test.m");\n    String captureTranslation = translateSourceFile(\n        functionHeader + "class Test { Function<Function, Function> f = y -> x -> y;}", "Test",\n        "Test.m");\n    assertTranslation(nonCaptureTranslation, "Test_$Lambda$1_get_instance(void);");\n    assertTranslatedLines(captureTranslationOuter,\n        "@interface Test_$Lambda$1 : NSObject < Function > {",\n        " @public",\n        "  Test *this$0_;",\n        "}");\n    assertTranslation(captureTranslation, "Test_$Lambda$1_get_instance(void);");\n    assertTranslatedLines(captureTranslation,\n        "@interface Test_$Lambda$2 : NSObject < Function > {",\n        " @public",\n        "  id<Function> val$y_;",\n        "}");\n  }\n\n  public void testTypeInference() throws IOException {\n    String quadObjectTranslation = translateSourceFile(\n        fourToOneHeader + "class Test { FourToOne f = (a, b, c, d) -> 1;}", "Test", "Test.m");\n    assertTranslatedLines(quadObjectTranslation,\n        "- (id)applyWithId:(id)a",\n        "           withId:(id)b",\n        "           withId:(id)c",\n        "           withId:(id)d {",\n        "  return JavaLangInteger_valueOfWithInt_(1);",\n        "}");\n    String mixedObjectTranslation = translateSourceFile(fourToOneHeader\n        + "class Test { FourToOne<String, Double, Integer, Boolean, String> f = "\n        + "(a, b, c, d) -> \\"1\\";}", "Test", "Test.m");\n    assertTranslatedLines(mixedObjectTranslation,\n        "- (id)applyWithId:(NSString *)a",\n        "           withId:(JavaLangDouble *)b",\n        "           withId:(JavaLangInteger *)c",\n        "           withId:(JavaLangBoolean *)d {",\n        "  return @\\"1\\";",\n        "}");\n  }\n\n  public void testOuterFunctions() throws IOException {\n    String translation = translateSourceFile(\n        functionHeader + "class Test { Function outerF = (x) -> x;}", "Test", "Test.m");\n    assertTranslation(translation,\n        "JreStrongAssign(&self->outerF_, JreLoadStatic(Test_$Lambda$1, instance));");\n  }\n\n  public void testStaticFunctions() throws IOException {\n    String translation = translateSourceFile(\n        functionHeader + "class Test { static Function staticF = (x) -> x;}", "Test", "Test.m");\n    assertTranslatedSegments(translation,\n        "id<Function> Test_staticF;",\n        "if (self == [Test class]) {",\n        "JreStrongAssign(&Test_staticF, JreLoadStatic(Test_$Lambda$1, instance))");\n  }\n\n  public void testNestedLambdas() throws IOException {\n    String outerCapture = translateSourceFile(functionHeader\n        + "class Test { Function<String, Function<String, String>> f = x -> y -> x;}", "Test",\n        "Test.m");\n    assertTranslation(outerCapture, "Test_$Lambda$1_get_instance(void);");\n    assertTranslatedLines(outerCapture,\n        "- (id)applyWithId:(NSString *)x {",\n        "  return create_Test_$Lambda$2_initWithNSString_(x);",\n        "}");\n    assertTranslatedLines(outerCapture,\n        "@interface Test_$Lambda$2 : NSObject < Function > {",\n        " @public",\n        "  NSString *val$x_;",\n        "}");\n    assertTranslatedLines(outerCapture,\n        "- (id)applyWithId:(NSString *)y {",\n        "  return JreRetainedLocalValue(val$x_);",\n        "}");\n    String noCapture = translateSourceFile(functionHeader\n        + "class Test { Function<String, Function<String, String>> f = x -> y -> y;}", "Test",\n        "Test.m");\n    assertTranslation(noCapture, "Test_$Lambda$1_get_instance(void);");\n    assertTranslation(noCapture, "Test_$Lambda$2_get_instance(void);");\n    assertTranslatedLines(noCapture,\n        "- (id)applyWithId:(NSString *)x {",\n        "  return JreRetainedLocalValue(JreLoadStatic(Test_$Lambda$2, instance));",\n        "}");\n    assertTranslatedLines(noCapture,\n        "- (id)applyWithId:(NSString *)y {",\n        "  return JreRetainedLocalValue(y);",\n        "}");\n  }\n\n  // There\'s no need for a cast_check call on a lambda whose type matches the assigned type.\n  public void testNoCastCheck() throws IOException {\n    String translation = translateSourceFile(\n        functionHeader + "class Test { Function f = (Function) (x) -> x;}", "Test", "Test.m");\n    assertNotInTranslation(translation, "cast_check");\n  }\n\n  // Test that we aren\'t trying to import lambda types.\n  public void testImportExclusion() throws IOException {\n    String translation = translateSourceFile(\n        functionHeader + "class Test { Function f = (Function) (x) -> x;}", "Test", "Test.m");\n    assertNotInTranslation(translation, "lambda$0.h");\n  }\n\n  // Check that lambdas are uniquely named.\n  public void testLambdaUniquify() throws IOException {\n    String translation = translateSourceFile(functionHeader\n        + "class Test { class Foo{ class Bar { Function f = x -> x; }}\\n"\n        + "Function f = x -> x;}",\n        "Test", "Test.m");\n    assertTranslation(translation, "@interface Test_Foo_Bar_$Lambda$1 : NSObject < Function >");\n    assertTranslation(translation, "@interface Test_$Lambda$1 : NSObject < Function >");\n  }\n    String translation = translateSourceFile(functionHeader\n        + "class Test { void f(int operator) { Function l = (a) -> operator; } }",\n        "Test", "Test.m");\n    assertTranslatedSegments(translation, "captures->operator_ =");\n  }\n\n  public void testLargeArgumentCount() throws IOException {\n  }\n\n  public void testLargeArgumentCount() throws IOException {\n    String interfaceHeader = "interface TooManyArgs<T> { T f(T a, T b, T c, T d, T e, T f, T g,"\n        + " T h, T i, T j, T k, T l, T m, T n, T o, T p, T q, T r, T s, T t, T u, T v, T w, T x,"\n        + " T y, T z, T aa, T ab, T ac, T ad, T ae, T af, T ag, T ah, T ai, T aj, T ak, T al,"\n        + " T am, T an, T ao, T ap, T aq, T ar, T as, T at, T au, T av, T aw, T ax, T ay, T az,"\n        + " T ba, T bb, T bc, T bd, T be, T bf, T bg, T bh, T bi, T bj, T bk, T bl, T bm, T bn,"\n        + " T bo, T bp, T bq, T br, T bs, T bt, T bu, T bv, T bw, T bx, T by, T bz, T foo);}";\n    String translation = translateSourceFile(interfaceHeader + "class Test { void a() {"\n        + "Object foo = \\"Foo\\";"\n        + "TooManyArgs fun = (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w,"\n        + " x, y, z, aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am, an, ao, ap, aq, ar, as,"\n        + " at, au, av, aw, ax, ay, az, ba, bb, bc, bd, be, bf, bg, bh, bi, bj, bk, bl, bm, bn,"\n        + " bo, bp, bq, br, bs, bt, bu, bv, bw, bx, by, bz, bar) -> foo;}}",\n        "Test", "Test.m");\n    assertTranslatedLines(translation,\n        "- (id)fWithId:(id)a",\n        "       withId:(id)b",\n        "       withId:(id)c",\n        "       withId:(id)d",\n        "       withId:(id)e");\n    assertTranslatedLines(translation,\n        "       withId:(id)bw",\n        "       withId:(id)bx",\n        "       withId:(id)by",\n        "       withId:(id)bz",\n        "       withId:(id)bar {",\n        "  return JreRetainedLocalValue(val$foo_);",\n        "}");\n  }\n\n  public void testCapturingBasicTypeReturn() throws IOException {\n    String header = "interface I { int foo(); }";\n    String translation = translateSourceFile(\n        header + "class Test { int f = 1234; void foo() { I i = () -> f; } }", "Test",\n        "Test.m");\n    assertTranslatedLines(translation,\n        "- (jint)foo {",\n        "  return this$0_->f_;",\n        "}");\n  }\n\n  // Verify that an #include is generated for the lambda\'s functionalType.\n  public void testLambdaFunctionalTypeImport() throws IOException {\n    String translation = translateSourceFile("import java.util.*;"\n        + "class Test { "\n        + "  public void test(List<String> names) { "\n        + "    Collections.sort(names, (p1, p2) -> p1.compareTo(p2)); "\n        + "  }"\n        + "}", "Test", "Test.m");\n    assertTranslation(translation, "#include \\"java/util/Comparator.h\\"");\n  }\n\n  public void testClassLiteralNamesInLambda() throws IOException {\n    String translation = translateSourceFile("package foo.bar; import java.io.Serializable; "\n        + "interface Comparator<T> {"\n        + "  int compare(T o1, T o2);"\n        + "  default Comparator<T> thenComparing(Comparator<? super T> other) {"\n        + "    return (Comparator<T> & Serializable) (c1, c2) -> {"\n        + "      int res = compare(c1, c2);"\n        + "      return (res != 0) ? res : other.compare(c1, c2);"\n        + "    }; "\n        + "  }"\n        + "}", "Comparator", "foo/bar/Comparator.m");\n    assertTranslatedLines(translation,\n        "@interface FooBarComparator_$Lambda$1 : "\n            + "NSObject < FooBarComparator, JavaIoSerializable > {",\n        " @public",\n        "  id<FooBarComparator> this$0_;",\n        "  id<FooBarComparator> val$other_;",\n        "}");\n    assertTranslatedLines(translation,\n        "- (jint)compareWithId:(id)c1",\n        "               withId:(id)c2 {",\n        "  jint res = [this$0_ compareWithId:c1 withId:c2];",\n        "  return (res != 0) ? res : [((id<FooBarComparator>) nil_chk(val$other_)) "\n            + "compareWithId:c1 withId:c2];",\n        "}");\n  }\n}\n', 'message': 'Issue #777: hid local variables in generated lambdas.\n\n\tChange on 2016/08/17 by tball <tball@google.com>\n\n-------------\nCreated by MOE: https://github.com/google/moe\nMOE_MIGRATED_REVID=130529109\n', 'author_name': 'Tom Ball', 'lang': 'java'}