Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.devtools.j2objc.ast.Block;
import com.google.devtools.j2objc.ast.BodyDeclaration;
import com.google.devtools.j2objc.ast.CastExpression;
import com.google.devtools.j2objc.ast.ClassInstanceCreation;
import com.google.devtools.j2objc.ast.CompilationUnit;
import com.google.devtools.j2objc.ast.EnumDeclaration;
import com.google.devtools.j2objc.ast.Expression;
Expand All @@ -42,6 +43,7 @@
import com.google.devtools.j2objc.ast.SingleVariableDeclaration;
import com.google.devtools.j2objc.ast.Statement;
import com.google.devtools.j2objc.ast.ThisExpression;
import com.google.devtools.j2objc.ast.TreeVisitor;
import com.google.devtools.j2objc.ast.TypeDeclaration;
import com.google.devtools.j2objc.ast.UnitTreeVisitor;
import com.google.devtools.j2objc.types.ExecutablePair;
Expand Down Expand Up @@ -164,9 +166,37 @@ public ObjectiveCKmpMethodTranslator(CompilationUnit unit) {
// originally executed in the translator pipeline.
@Override
public void run() {
Set<AbstractTypeDeclaration> existingTypes = new HashSet<>(unit.getTypes());
super.run();
new LambdaTypeElementAdder(unit).run();
new LambdaRewriter(unit).run();
new InnerClassExtractor(unit).run();

Functionizer functionizer = new Functionizer(unit);
var unused = functionizer.visit(unit);
InitializationNormalizer initNormalizer = new InitializationNormalizer(unit);

// Pass 1: Run Functionizer and InitializationNormalizer exclusively over newly introduced
// lambda type declarations created during this translation pass.
for (AbstractTypeDeclaration type : unit.getTypes()) {
if (!existingTypes.contains(type)) {
type.accept(functionizer);
type.accept(initNormalizer);
}
}

// Pass 2: Run Functionizer specifically on ClassInstanceCreation nodes across the unit.
// This updates newly generated lambda instantiations (e.g., inside generated adapter methods).
unit.accept(
new TreeVisitor() {
@Override
public void endVisit(ClassInstanceCreation node) {
functionizer.endVisit(node);
}
});

new StaticVarRewriter(unit).run();
new PrivateDeclarationResolver(unit).run();
}

private String getOverrideSignature(ExecutablePair method) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,14 @@ public void setBooleanSet(Set<Boolean> set) {}
impl,
"""
- (void)setBooleanSet:(NSSet<NSNumber *> *)set {
[self setBooleanSetWithJavaUtilSet:(id<JavaUtilSet>) [Adapter toJavaUtilSetWithId:set withJavaUtilFunctionFunction:TestSetOfBoolean_$Lambda$1_instance]];
[self setBooleanSetWithJavaUtilSet:(id<JavaUtilSet>) [Adapter toJavaUtilSetWithId:set withJavaUtilFunctionFunction:JreLoadStatic(TestSetOfBoolean_$Lambda$1, instance)]];
}
""");
assertInTranslation(
impl,
"""
- (id)applyWithId:(id)elem {
return Adapter_toBooleanWithId_(elem);
}
""");
}
Expand All @@ -1682,7 +1689,14 @@ public void setBooleanSet(Set<Boolean> set) {}
impl,
"""
- (void)setBooleanSet:(NSSet<NSNumber *> *)set {
[self setBooleanSetWithJavaUtilSet:(id<JavaUtilSet>) [Adapter toJavaUtilSetWithId:set withJavaUtilFunctionFunction:TestSetLeaf_$Lambda$1_instance]];
[self setBooleanSetWithJavaUtilSet:(id<JavaUtilSet>) [Adapter toJavaUtilSetWithId:set withJavaUtilFunctionFunction:JreLoadStatic(TestSetLeaf_$Lambda$1, instance)]];
}
""");
assertInTranslation(
impl,
"""
- (id)applyWithId:(id)elem {
return Adapter_toBooleanWithId_(elem);
}
""");
}
Expand All @@ -1706,7 +1720,14 @@ public void setBooleanList(List<Boolean> list) {}
impl,
"""
- (void)setBooleanList:(NSArray<NSNumber *> *)list {
[self setBooleanListWithJavaUtilList:(id<JavaUtilList>) [Adapter toJavaUtilListWithId:list withJavaUtilFunctionFunction:TestListParam_$Lambda$1_instance]];
[self setBooleanListWithJavaUtilList:(id<JavaUtilList>) [Adapter toJavaUtilListWithId:list withJavaUtilFunctionFunction:JreLoadStatic(TestListParam_$Lambda$1, instance)]];
}
""");
assertInTranslation(
impl,
"""
- (id)applyWithId:(id)elem {
return Adapter_toBooleanWithId_(elem);
}
""");
}
Expand All @@ -1731,7 +1752,14 @@ public void setListSet(Set<List<String>> set) {}
impl,
"""
- (void)setListSet:(NSSet<NSArray<NSString *> *> *)set {
[self setListSetWithJavaUtilSet:(id<JavaUtilSet>) [Adapter toJavaUtilSetWithId:set withJavaUtilFunctionFunction:TestSetOfList_$Lambda$1_instance]];
[self setListSetWithJavaUtilSet:(id<JavaUtilSet>) [Adapter toJavaUtilSetWithId:set withJavaUtilFunctionFunction:JreLoadStatic(TestSetOfList_$Lambda$1, instance)]];
}
""");
assertInTranslation(
impl,
"""
- (id)applyWithId:(id)elem {
return (id<JavaUtilList>) Adapter_toJavaUtilListWithId_(elem);
}
""");
}
Expand Down Expand Up @@ -1989,7 +2017,14 @@ public void verifyList(List<List<List<Foo>>> list) {}
"""
- (void)verifyList:(NSArray<NSArray<NSArray<Foo *> *> *> *)list {
[self verifyListWithJavaUtilList:(id<JavaUtilList>) [Adapter toJavaUtilListWithId:list \
withJavaUtilFunctionFunction:TestClass_$Lambda$1_instance]];
withJavaUtilFunctionFunction:JreLoadStatic(TestClass_$Lambda$1, instance)]];
}
""");
assertInTranslation(
impl,
"""
- (id)applyWithId:(id)elem {
return (id<JavaUtilList>) Adapter_toJavaUtilList_JavaUtilList_WithId_(elem);
}
""");
}
Expand Down