Open IrushiL opened 3 years ago
Random thought: Can we create a Ballerina module per Java Class?
In order to sort this design issue, we could generate a single Ballerina module per Java library, since we can make the assumption that Java modules do not have cyclic dependencies among them.
If we are to go ahead with this approach, the following design changes will have to be done.
Current Approach:
Java package -> Ballerina module
E.g.
import yaml_package.java.io as javaio;
import yaml_package.java.lang as javalang;
import yaml_package.org.yaml.snakeyaml as snakeyaml;
function foo() {
snakeyaml:Yaml yaml = snakeyaml:newYaml1();
}
Proposed Approach:
Instead of mapping a Ballerina module to a Java package, an entire Java library is mapped to a Ballerina module. This would be similar to generating single directory bindings. All bindgen files will be created inside a single directory.
Java library -> Ballerina module
In order to make the Java package hierarchy clear in the generated bindgen code and to handle duplicate simple class names, we could make the following changes.
E.g.
javaio_FileInputStream
javalang_String
snakeyaml_Yaml
E.g.
function foo() {
snakeyaml_Yaml yaml = snakeyaml_newYaml1();
}
The workaround would be to generate single directory mappings using the (-o|--output) <output>
option in the bindgen command.
Description: When generating module-level mappings Java packages are mapped onto Ballerina modules. However, doing this could cause cyclic dependencies since Java packages are allowed to make cyclic imports within the Java module they reside in and since it supports dynamic class loading.
This design issue should be sorted out if we are to support module-level mappings for Ballerina bindings. The alternative approach will be to let users use the single directory mappings.
Steps to reproduce: Assume there are 2 packages
org.test.first
andorg.test.second
and that these contain the following classes.Imagine a scenario where the user tries to import
org.test.second.A
inorg.test.first.A
andorg.test.second.B
inorg.test.first.B
. Even though this would be a valid import in Java, this would cause cyclic imports in Ballerina bindings.Affected Versions: Ballerina Swan Lake Beta 2
OS, DB, other environment details and versions:
Related Issues (optional): https://github.com/ballerina-platform/ballerina-lang/issues/31855
Suggested Labels (optional):
Suggested Assignees (optional):