Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8622c166ac53
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 895e1f4de3cf
Choose a head ref
  • 2 commits
  • 5 files changed
  • 2 contributors

Commits on Sep 29, 2016

  1. Fix Java::JavaLangReflect::GenericSignatureFormatError when reflectin…

    …g reified annotation values
    cheister committed Sep 29, 2016
    Copy the full SHA
    1ddb0ae View commit details

Commits on Sep 30, 2016

  1. Merge pull request #4187 from cheister/fix-generic-signature-format-e…

    …rror
    
    Fix Java::JavaLangReflect::GenericSignatureFormatError when reflecting reified annotation values
    headius authored Sep 30, 2016
    Copy the full SHA
    895e1f4 View commit details
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyClass.java
Original file line number Diff line number Diff line change
@@ -1407,7 +1407,7 @@ public synchronized void reify(String classDumpDir, boolean useChildLoader) {

// calculate an appropriate name, for anonymous using inspect like format e.g. "Class:0x628fad4a"
final String name = getBaseName() != null ? getName() :
( "Class:0x" + Integer.toHexString(System.identityHashCode(this)) );
( "Class_0x" + Integer.toHexString(System.identityHashCode(this)) );

final String javaName = "rubyobj." + name.replaceAll("::", ".");
final String javaPath = "rubyobj/" + name.replaceAll("::", "/");
10 changes: 10 additions & 0 deletions spec/java_integration/fixtures/Reflector.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package java_integration.fixtures;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Array;
import java.util.Collection;
@@ -88,5 +89,14 @@ public static Collection<Method> findMethods(final Object obj, final String meth
return matchedMethods;
}

public static <A extends Annotation> A getDeclaredAnnotation(Class<?> clazz,
Class<A> annotationType) {
for (Annotation a : clazz.getDeclaredAnnotations()) {
if (annotationType.isAssignableFrom(a.annotationType())) {
return (A) a;
}
}
return null;
}
}

9 changes: 9 additions & 0 deletions spec/java_integration/fixtures/Service.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package java_integration.fixtures;

import org.jruby.java.codegen.Reified;

public class Service implements Reified {
public String getName() {
return "ServiceName";
}
}
14 changes: 14 additions & 0 deletions spec/java_integration/fixtures/ServiceAnnotation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package java_integration.fixtures;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ServiceAnnotation {
Class<?> service();
}
13 changes: 12 additions & 1 deletion spec/java_integration/reify/become_java_spec.rb
Original file line number Diff line number Diff line change
@@ -195,7 +195,18 @@ def ola(*args); "OLA #{args.join(' ')}" end
klass = Class.new(ReifiedSample)
hexid = klass.inspect.match(/(0x[0-9a-f]+)/)[1]
klass = klass.become_java!
expect( klass.getName ).to match /^rubyobj.Class.?#{hexid}/ # rubyobj.Class:0x599f1b7
expect( klass.getName ).to match /^rubyobj\.Class_#{hexid}/ # rubyobj.Class_0x599f1b7
end

it 'works when reflecting annotations' do
klass = Class.new(ReifiedSample)
klass.add_class_annotations(Java::java_integration.fixtures.ServiceAnnotation => {
'service' => Class.new(Java::java_integration.fixtures.Service).become_java!(false)
})
klass = klass.become_java!(false)
annotation = Reflector.getDeclaredAnnotation(klass, Java::java_integration.fixtures.ServiceAnnotation)
expect( annotation ).not_to be_nil
expect( annotation.service ).not_to be_nil
end

describe "java fields" do