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

Field annotations #624

Merged
merged 4 commits into from May 21, 2013

Conversation

Projects
None yet
4 participants
@daicoden
Copy link
Contributor

daicoden commented Apr 2, 2013

Let me know what you think of adding this functionality and if you have any better ideas for generate_java_fields.

This allows you to define an object in ruby and add field annotations. A use case is to create an object in ruby and pass it to a transformation library which uses fields and annotations for seralization.

Matt Wilson and others added some commits Mar 19, 2013

@ghost ghost assigned headius Apr 2, 2013

@jkingdon

This comment has been minimized.

Copy link

jkingdon commented Apr 22, 2013

Here is some documentation of java_field for the wiki (enclosed as a diff, as I couldn't find a better way to supply wiki changes as part of a pull request). I did not succeed in writing, and testing, a similar one for add_field_annotation. I don't know why my attempts failed, but I do have one question: what should add_field_annotation do if passed a name which does not exist? It seems to silently fail now.

diff --git a/GeneratingJavaClasses.md b/GeneratingJavaClasses.md
index 7c0d088..0921838 100644
--- a/GeneratingJavaClasses.md
+++ b/GeneratingJavaClasses.md
@@ -39,6 +39,25 @@ end

 The resulting Java class has an instance method named ```some_method``` and a static method named ```class_method```.

+Similarly, you can add java fields:
+
+```
+class Bar
+  java_field "java.lang.String name"
+  become_java!
+end
+b = Bar.new
+b.name = "chin-up"
+b.name
+# =>
+# "chin-up"
+b.name = 234
+# raises IllegalArgumentException
+```
+
+The type of a Java field currently must be a non-primitive type (for example, java.lang.Object not int).
+
+
 Generating Java Classes Ahead-of-time
 -------------------------------------

@enebo

This comment has been minimized.

Copy link

enebo commented on src/org/jruby/RubyClass.java in 48938ee May 20, 2013

This continue null check should be moved above fieldVisitor since we won't use it if we continue.

This comment has been minimized.

Copy link
Owner Author

daicoden replied May 21, 2013

Quick clarifying question, I'm not 100% sure how ASM works. Don't we need to visit the field here even if there are no annotations so we at least create a public field of that name on the reified class? Or does line 1357 fail to accomplish this?

This comment has been minimized.

Copy link

enebo replied May 21, 2013

gah. You are right. I conflated anno processing here with field creation. Ignore my comment (and Charles already merged this)

@enebo

This comment has been minimized.

Copy link
Member

enebo commented May 20, 2013

[Note: I made comment on 48938ee which would be nice to be addressed]

I find this a reasonable starting point and I think we can merge this as-is, but I feel this is an incomplete feature as it would be nice if we could use the equivalent of java_signature() instead of the more procedural mechanism we have in place. It would see a day where we can have:

java_field '@Persistent @Synchronized Integer baz'

I suspect JavaSignatureParser needs some work to process field signatures but it is my hope eventually the above signature is the only way we add stuff. I mostly mention this is anyone wants to look into JavaSignatureParser and allow a more cut-and-paste signature format.

@headius

This comment has been minimized.

Copy link
Member

headius commented May 21, 2013

I'm going to go ahead and merge this, since it seems like a good start. I agree with @enebo that we should (with your help) continue to build out this functionality and also try to expand tests to more complex cases.

headius added a commit that referenced this pull request May 21, 2013

@headius headius merged commit e33a5b6 into jruby:master May 21, 2013

1 check passed

default The Travis build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.