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 @@ -215,6 +215,17 @@ private void printNativeEnum() {
}
print("\n");

// Provide aliases for compatibility with kotlin
for (EnumConstantDeclaration constant : constants) {
String nativeConstantName = nameTable.getNativeEnumConstantName(typeElement, constant);
String kotlinConstantName =
nameTable.getNativeKotlinEnumConstantName(typeElement, constant);
if (!nativeConstantName.equals(kotlinConstantName)) {
printf("#define %s %s\n", kotlinConstantName, nativeConstantName);
}
}
print("\n");

// Use different types for transpiled Java ordinals (which expects ordinals to be int32_t) and
// native code using the enum (where stricter ordinal types help clang warnings).
printf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,22 @@ public String getNativeEnumConstantName(
}
}

public String getNativeKotlinEnumConstantName(
TypeElement enumTypeElement, EnumConstantDeclaration constantDeclaration) {
return getNativeKotlinEnumConstantName(
enumTypeElement, constantDeclaration.getVariableElement());
}

public String getNativeKotlinEnumConstantName(
TypeElement enumTypeElement, VariableElement constantVariableElement) {
// Note that we stick to J2objc type name conventions here, avoiding type name churn in
// addition to the literal name change.
String enumBaseName = getFullName(enumTypeElement) + "_Enum";
String constantSuffix = getVariableBaseName(constantVariableElement);
constantSuffix = camelCaseName(constantSuffix, true);
return enumBaseName + constantSuffix;
}

public String getNativeEnumSwiftConstantName(EnumConstantDeclaration constantDeclaration) {
return camelCaseName(getVariableBaseName(constantDeclaration.getVariableElement()), false);
}
Expand Down