Created
December 12, 2012 23:58
-
-
Save xaviershay/4272848 to your computer and use it in GitHub Desktop.
This file contains 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
diff --git a/lib/ruby/shared/jruby/core_ext/class.rb b/lib/ruby/shared/jruby/core_ext/class.rb | |
index eca4b54..39c88d6 100644 | |
--- a/lib/ruby/shared/jruby/core_ext/class.rb | |
+++ b/lib/ruby/shared/jruby/core_ext/class.rb | |
@@ -140,7 +140,7 @@ class Class | |
annotations.each_with_index do |param_annos, i| | |
for cls, params in param_annos | |
params ||= {} | |
- self_r.add_parameter_annotation(name, i, _anno_class(cls)) | |
+ self_r.add_parameter_annotation(name, i, _anno_class(cls), params) | |
end | |
end | |
diff --git a/spec/java_integration/fixtures/ParameterAnnotations.java b/spec/java_integration/fixtures/ParameterAnnotations.java | |
new file mode 100644 | |
index 0000000..41cb8b8 | |
--- /dev/null | |
+++ b/spec/java_integration/fixtures/ParameterAnnotations.java | |
@@ -0,0 +1,33 @@ | |
+package java_integration.fixtures; | |
+ | |
+import java.lang.ArrayStoreException; | |
+import java.lang.annotation.Annotation; | |
+import java.lang.annotation.ElementType; | |
+import java.lang.annotation.Retention; | |
+import java.lang.annotation.RetentionPolicy; | |
+import java.lang.annotation.Target; | |
+import java.lang.reflect.Method; | |
+import java.util.ArrayList; | |
+import java.util.Collection; | |
+import java.util.List; | |
+ | |
+public class ParameterAnnotations { | |
+ @Retention(RetentionPolicy.RUNTIME) | |
+ @Target(ElementType.PARAMETER) | |
+ public @interface Annotated { | |
+ } | |
+ | |
+ public static List<Annotation> countAnnotated(Class cls) { | |
+ Method[] declaredMethods = cls.getDeclaredMethods(); | |
+ List<Annotation> annos = new ArrayList<Annotation>(); | |
+ for (Method method: declaredMethods) { | |
+ for (Annotation[] annotations : method.getParameterAnnotations()) { | |
+ for (Annotation annotation : annotations) { | |
+ annos.add(annotation); | |
+ } | |
+ } | |
+ } | |
+ | |
+ return annos; | |
+ } | |
+} | |
diff --git a/spec/java_integration/reify/annos_spec.rb b/spec/java_integration/reify/annos_spec.rb | |
index 82b32d1..53eee16 100644 | |
--- a/spec/java_integration/reify/annos_spec.rb | |
+++ b/spec/java_integration/reify/annos_spec.rb | |
@@ -20,6 +20,19 @@ describe "JRuby annotation processing:" do | |
end | |
end | |
+ context "parameter annotations using #add_parameter_annotation" do | |
+ class ClassWithAnnotatedParams | |
+ add_parameter_annotation 'foo', [{Java::java_integration.fixtures.ParameterAnnotations::Annotated => {}}] | |
+ def foo(x); end | |
+ | |
+ become_java! | |
+ end | |
+ | |
+ it "has an annotated parameter" do | |
+ Java::java_integration.fixtures.ParameterAnnotations.countAnnotated(ClassWithAnnotatedParams).size.should == 1 | |
+ end | |
+ end | |
+ | |
context "method annotations using #java_signature" do | |
class ClassWithAnnotatedMethods2 | |
java_signature("@java_integration.fixtures.MethodAnnotations.Annotated void foo()") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment