Skip to content

Enum not available in Java #51

Open
@zvasicek56

Description

@zvasicek56

Enums are not propagated to Java code.

The C++ code

 class adapter: public scapix::bridge::object<adapter>
 {
    public:

        enum class AdapterEnum : std::uint32_t
        {
            One = 1, Two
        };
        void adapter_test(AdapterEnum evt) {};
 };

is translated by the scapix generator to the following Java code:

public class Adapter extends com.scapix.Bridge
{
	public Adapter() { super(nop); _init(); }

        public native void adapterTest(int evt);
}

To address this issue, the scapix generator should generate the following code:

public class Adapter extends com.scapix.Bridge
{
	public Adapter() { super(nop); _init(); }

	public static enum AdapterEnum {
            One(1),
            Two(2);
    	      
    	    private final int value;

            AdapterEnum(final int val) {
                  value = val;
            }

   	    public int getValue() { return value; }
      }

     public native void adapterTest(AdapterEnum evt);

The nested enum AdapterEnum must be public to allow it to be used from external code.

Another option is to get the integer values from the native library but this causes more overhead.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions