protected RubyArray buildRubyArray(Class[] classes) {
   RubyArray result = getRuntime().newArray(classes.length);
   for (int i = 0; i < classes.length; i++) {
     result.append(JavaClass.get(getRuntime(), classes[i]));
   }
   return result;
 }
Exemplo n.º 2
0
  private static JavaClass getTargetType(ThreadContext context, Ruby runtime, IRubyObject type) {
    JavaClass targetType;

    if (type instanceof RubyString || type instanceof RubySymbol) {
      targetType = runtime.getJavaSupport().getNameClassMap().get(type.asJavaString());
      if (targetType == null) targetType = JavaClass.forNameVerbose(runtime, type.asJavaString());
    } else if (type instanceof RubyModule && type.respondsTo("java_class")) {
      targetType = (JavaClass) Helpers.invoke(context, type, "java_class");
    } else if (type instanceof JavaProxy) {
      if (((JavaProxy) type).getObject() instanceof Class) {
        targetType = JavaClass.get(runtime, (Class) ((JavaProxy) type).getObject());
      } else {
        throw runtime.newTypeError("not a valid target type: " + type);
      }
    } else {
      throw runtime.newTypeError("unable to convert to type: " + type);
    }

    return targetType;
  }
 @JRubyMethod
 public IRubyObject java_class() {
   return JavaClass.get(getRuntime(), getJavaClass());
 }