nativelibs4java / JNAerator

JNAerator: native bindings generator for JNA / BridJ / Node.js
http://jnaerator.googlecode.com
507 stars 109 forks source link

JNAerator: Anonymous nested unions/structs are converted to nested classes with same name as enclosing class #132

Open mvarnim opened 2 years ago

mvarnim commented 2 years ago

Issue description

A c union containing anonymous unions and structs is defined in a header file:

typedef union myUnion{
    double data[4];
    struct{
        union{
            struct{
                double vec[3];

            };
            struct{
                double i;
                double j;
                double k;
            };
        };
        double s;
    };
} myUnion;

This is converted to Java classes by JNAerator in the form:

public class myUnion extends Union {
    public double[] data = new double[4];
    public field1_struct field1;
    public static class field1_struct extends Structure {
        public field1_union field1;
        public double s;
        public static class field1_union extends Union {
            public field1_struct field1;
            public field2_struct field2;
            public static class field1_struct extends Structure {
                /** C type : double[3] */...

The inner class field1_struct, which represents the inner anonymous struct, has the same name as the enclosing class, which represents the outer anonymous struct. JNAerator generates these names automatically in the absence of struct names in the native code.

This leads to the Java error The nested type field1_struct cannot hide an enclosing type.

An interim solution is manual modification of the generated Java files after running JNAerator.