Created
September 16, 2013 20:27
-
-
Save daicoden/6586144 to your computer and use it in GitHub Desktop.
Patch that would be helpful to ethers if it gets into jruby 1.7.5.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JRuby 1.5 cleanup | |
# COMITTED UPSTREAM - But leaving here in case we need refernce. | |
# There was some implementation changed, and I didn't have tests to catch everything | |
# this is here until we can get it commited upstream | |
module JRuby | |
class JavaSignature | |
# FIXME: Can make this accept whole list too if that is actual contract | |
# FIXME: Can be literals too | |
def as_java_type(string) | |
type = primitive? string | |
return type if type | |
# If annotation makes it in strip @ before we try and match it. | |
if string.is_a?(String) | |
string = string[1..-1] if string.start_with? '@' | |
end | |
eval make_class_jiable(string) | |
end | |
def make_class_jiable(string) | |
if string.is_a?(Java::OrgJrubyAstJava_signature::ReferenceTypeNode) | |
# Basically, if a package segment is capitalized, it's assumed to be a class in the package name. | |
name = string.getFullyTypedName() | |
klass_names,package_parts = name.split(".").partition{|n| n =~ /^[A-Z]/ } | |
"#{package_parts.join(".")}.#{klass_names.join("::")}" | |
elsif string.is_a?(Java::OrgJruby::RubyClass) | |
return string.class.to_s | |
else | |
new_list = [] | |
string.split(/\./).inject(false) do |last_cap, segment| | |
if segment =~ /[A-Z]/ | |
if last_cap | |
new_list << "::" + segment | |
else | |
new_list << "." + segment | |
end | |
last_cap = true | |
else | |
new_list << "." + segment | |
last_cap = false | |
end | |
end | |
"Java::#{new_list.join("")[1..-1]}" | |
end | |
end | |
end | |
end | |
class Class | |
def add_field_signature(name, type) | |
self_r = JRuby.reference0(self) | |
signature = JRuby::JavaSignature.new(nil, nil) | |
java_return_type = signature.as_java_type(type) | |
self_r.add_field_signature(name, java_return_type.java_class) | |
end | |
end |
JavaSignature may actually be committed upstream, I can't figure out what my comment is saying.
add_field_signature is definitely busted, it only works for primitives, this patch works for objects as well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@tarcieri