Permalink
Browse files

fix #148 in the simplest way possible

this allows annotations to use ints, not longs or any other thing.
It's kind of naive--but it's a start.
  • Loading branch information...
baroquebobcat committed Sep 25, 2011
1 parent f1b5c19 commit 605c377a2aef2ba3b742d24dc595f4b374c64ce4
@@ -339,13 +339,13 @@ def annotation_value(node, typer)
case node
when String
java.lang.String.new(node.literal)
when Fixnum
java.lang.Integer.new(node.literal)
when Array
node.children.map {|node| annotation_value(node, typer)}
else
# TODO Support other types
ref = value.type_refence(typer)
desc = BiteScript::Signature.class_id(ref)
BiteScript::ASM::Type.getType(desc)
raise "Unsupported Annotation Value Type"
end
end
end
@@ -157,6 +157,8 @@ def annotate(annotations)
def annotation_value(value)
case value
when Java::JavaLang::Integer
value.to_s
when Java::JavaLang::String, String
value.to_s.inspect
when Array
@@ -0,0 +1,58 @@
class TestAnnotations < Test::Unit::TestCase
def deprecated
@deprecated ||= java.lang.Deprecated.java_class
end
def test_annotation_on_a_method
cls, = compile(<<-EOF)
$Deprecated
def foo
'foo'
end
EOF
assert_not_nil cls.java_class.java_method('foo').annotation(deprecated)
assert_nil cls.java_class.annotation(deprecated)
end
def test_annotation_on_a_class
script, cls = compile(<<-EOF)
$Deprecated
class Annotated
end
EOF
assert_not_nil cls.java_class.annotation(deprecated)
end
def test_annotation_on_a_field
cls, = compile(<<-EOF)
class AnnotatedField
def initialize
$Deprecated
@foo = 1
end
end
EOF
assert_not_nil cls.java_class.declared_fields[0].annotation(deprecated)
end
def test_annotation_with_an_integer
jruby_method = Java::OrgJrubyAnno::JRubyMethod.java_class
cls, = compile(<<-EOF)
import org.jruby.*
import org.jruby.anno.*
import org.jruby.runtime.*
import org.jruby.runtime.builtin.*
$JRubyMethod["name" => "bar", "optional" => 1]
def bar(baz:int)
end
EOF
method_annotation = cls.java_class.java_method('bar', :int).annotation(jruby_method)
assert_equal 1, method_annotation.optional
end
end
@@ -1654,38 +1654,6 @@ def foo(bar:String)
cls.main(nil)
end
end
def test_annotations
deprecated = java.lang.Deprecated.java_class
cls, = compile(<<-EOF)
$Deprecated
def foo
'foo'
end
EOF
assert_not_nil cls.java_class.java_method('foo').annotation(deprecated)
assert_nil cls.java_class.annotation(deprecated)
script, cls = compile(<<-EOF)
$Deprecated
class Annotated
end
EOF
assert_not_nil cls.java_class.annotation(deprecated)
cls, = compile(<<-EOF)
class AnnotatedField
def initialize
$Deprecated
@foo = 1
end
end
EOF
assert_not_nil cls.java_class.declared_fields[0].annotation(deprecated)
end
def test_super
cls, = compile(<<-EOF)
class Foo

0 comments on commit 605c377

Please sign in to comment.