Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handling of Enum types #159

Closed
MatFi opened this issue Mar 2, 2022 · 8 comments
Closed

handling of Enum types #159

MatFi opened this issue Mar 2, 2022 · 8 comments

Comments

@MatFi
Copy link
Contributor

MatFi commented Mar 2, 2022

I am correct with the assumption that there is currently no way to handle Java Enum types. If I am wrong here, can someone provide me an example please?

In my case the specific problems appear when working with this Java object.

@aviks
Copy link
Collaborator

aviks commented Mar 2, 2022

No, we do not have any specific support for it as far as I know. I imagine you can get the id and name fields of the Enum and work with that?

For full support, we probably would want to write some convert methods here

Also, separately, I guess you have seen Taro.jl?

@mkitti
Copy link
Member

mkitti commented Mar 2, 2022

We may have some low level support in https://github.com/JuliaInterop/JavaCall.jl/blob/master/src/JNI.jl . Essentially the question comes down to how you would work with Enum types via JNI. If you can link that documentation, we can build up from there.

@MatFi
Copy link
Contributor Author

MatFi commented Mar 2, 2022

No, we do not have any specific support for it as far as I know. I imagine you can get the id and name fields of the Enum and work with that?

Sadly this seems not sufficient to me as I can not get set the fields this way (not an Java expert).

Also, separately, I guess you have seen Taro.jl?

Thanks, in fact Taro.jl is what I want to extend with some formatting features, this is why I came across this

@mkitti
Copy link
Member

mkitti commented Mar 2, 2022

This look informative:
https://stackoverflow.com/questions/11225261/how-to-return-enum-from-jni

@MatFi
Copy link
Contributor Author

MatFi commented Mar 3, 2022

This look informative: https://stackoverflow.com/questions/11225261/how-to-return-enum-from-jni

Worked for me! Thanks a lot!!

class = Symbol("org.apache.poi.ss.usermodel.ConditionalFormattingThreshold\$RangeType")
jclass = JavaCall.javaclassname(class)
jclassptr = JavaCall.JNI.FindClass(jclass)
jfieldID = JavaCall.JNI.GetStaticFieldID(jclassptr,"PERCENT",JavaCall.signature(JavaObject{class}))
jenum = JavaCall.JNI.GetStaticObjectField(jclassptr,jfieldID)
ret = JavaCall.convert_result(JavaObject{class},jenum)

@MatFi MatFi closed this as completed Mar 3, 2022
@MatFi
Copy link
Contributor Author

MatFi commented Mar 3, 2022

After some investigation I noticed that it is also possible to simply use the jfield function. so this JavaCall.jl actually supports enums to some extend

enum = @jimport "org.apache.poi.ss.usermodel.ConditionalFormattingThreshold\$RangeType"
ret = jfield(enum,"MAX",enum)

@mkitti
Copy link
Member

mkitti commented Mar 3, 2022

Could you do

enum = @jimport raw"org.apache.poi.ss.usermodel.ConditionalFormattingThreshold$RangeType"
ret = jfield(enum,"MAX",enum)

@mkitti
Copy link
Member

mkitti commented Mar 3, 2022

Perhaps another approach would be to use listfields(enum, "MAX")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants