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 @@ -748,7 +748,7 @@ private NativeTypeVisitor(
public Void visitDeclared(DeclaredType type, StringBuilder builder) {
builder.append(toNativeType(type, methodExecutable, referencedTypes));
List<? extends TypeMirror> typeArguments = type.getTypeArguments();
if (!typeArguments.isEmpty()) {
if (options.asObjCGenericDecl() && !typeArguments.isEmpty()) {
String typeArgsString = buildTypeArgumentString(typeArguments);
builder.append("<").append(typeArgsString).append(">");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ObjectiveCKmpMethodTranslatorTest extends GenerationTest {
@Override
public void setUp() throws IOException {
super.setUp();
options.load(new String[] {"--objc-generics"});
addSourceFile(
"""
package com.google.common.collect;
Expand Down Expand Up @@ -276,7 +277,8 @@ public List<List<String>> getMatrix() {
assertInTranslation(
testImplementation,
"return (NSArray<NSArray<NSString *> *> *) [Adapter"
+ " fromJavaUtilList_JavaUtilList_WithJavaUtilList:(id<JavaUtilList>) [self getMatrix]]");
+ " fromJavaUtilList_JavaUtilList_WithJavaUtilList:(id<JavaUtilList>) [self"
+ " getMatrix]]");
}

/** Tests mixed nested collection conversion with @ObjectiveCKmpMethod. */
Expand Down Expand Up @@ -1061,7 +1063,6 @@ public ImmutableList<CustomClass> getItems() {
assertNotInTranslation(
concreteHeader, "- (void)setItems:(NSArray<MyPkgCustomClass *> *)items;");
assertNotInTranslation(concreteHeader, "- (NSArray<MyPkgCustomClass *> *)getItems;");
assertNotInTranslation(concreteHeader, "@class MyPkgCustomClass;");

String concreteImpl = translateSourceFile("ConcreteClass", "ConcreteClass.m");
assertNotInTranslation(concreteImpl, "- (void)setItems:(NSArray<MyPkgCustomClass *> *)items {");
Expand Down Expand Up @@ -1405,6 +1406,37 @@ void ConstTest_initWithList_(ConstTest *self_, NSArray<NSString *> *list) {
""");
}

public void testObjCGenerics() throws IOException {

addSourceFile(
"""
import com.google.j2objc.annotations.ObjectiveCKmpMethod;
import java.util.List;
public class GenericsOn {
@ObjectiveCKmpMethod(selector="setList:", adapter=Adapter.class)
public void setList(List<String> list) {}
}
""",
"GenericsOn.java");
String headerOn = translateSourceFile("GenericsOn", "GenericsOn.h");
assertInTranslation(headerOn, "- (void)setList:(NSArray<NSString *> *)list;");

options.setAsObjCGenericDecl(false);
addSourceFile(
"""
import com.google.j2objc.annotations.ObjectiveCKmpMethod;
import java.util.List;
public class GenericsOff {
@ObjectiveCKmpMethod(selector="setList:", adapter=Adapter.class)
public void setList(List<String> list) {}
}
""",
"GenericsOff.java");
String headerOff = translateSourceFile("GenericsOff", "GenericsOff.h");
assertInTranslation(headerOff, "- (void)setList:(NSArray *)list;");
options.setAsObjCGenericDecl(true);
}

public void testSetOfBooleanFails() throws IOException {
addSourceFile(
"""
Expand Down