Ejemplo n.º 1
0
  private static RaiseException argumentError(
      ThreadContext context, ParameterTypes[] methods, IRubyObject receiver, Class[] argTypes) {
    boolean constructor =
        methods[0] instanceof JavaConstructor || methods[0] instanceof JavaProxyConstructor;

    StringBuffer fullError = new StringBuffer();
    fullError.append("no ");
    if (constructor) {
      fullError.append("constructor");
    } else {
      fullError.append("method '").append(((JavaMethod) methods[0]).name().toString()).append("' ");
    }
    fullError.append("for arguments ").append(CodegenUtils.prettyParams(argTypes)).append(" on ");
    if (receiver instanceof RubyModule) {
      fullError.append(((RubyModule) receiver).getName());
    } else {
      fullError.append(receiver.getMetaClass().getRealClass().getName());
    }

    if (methods.length > 1) {
      fullError.append("\n  available overloads:");
      for (ParameterTypes method : methods) {
        fullError.append("\n    " + CodegenUtils.prettyParams(method.getParameterTypes()));
      }
    }

    return context.runtime.newNameError(fullError.toString(), null);
  }
Ejemplo n.º 2
0
 private Method getMethod(String name, Class... argTypes) {
   try {
     return getObject().getClass().getMethod(name, argTypes);
   } catch (NoSuchMethodException nsme) {
     throw JavaMethod.newMethodNotFoundError(
         getRuntime(), getObject().getClass(), name + CodegenUtils.prettyParams(argTypes), name);
   }
 }
Ejemplo n.º 3
0
 private RubyMethod getRubyMethod(String name, Class... argTypes) {
   Method jmethod = getMethod(name, argTypes);
   if (Modifier.isStatic(jmethod.getModifiers())) {
     return RubyMethod.newMethod(
         metaClass.getSingletonClass(),
         CodegenUtils.prettyParams(argTypes),
         metaClass.getSingletonClass(),
         name,
         getMethodInvoker(jmethod),
         getMetaClass());
   } else {
     return RubyMethod.newMethod(
         metaClass,
         CodegenUtils.prettyParams(argTypes),
         metaClass,
         name,
         getMethodInvoker(jmethod),
         this);
   }
 }
Ejemplo n.º 4
0
 @Override
 public String toString() {
   return ""
       + (statik ? "static " : "")
       + nativeReturn.getSimpleName()
       + " "
       + nativeTarget.getSimpleName()
       + "."
       + nativeName
       + CodegenUtils.prettyShortParams(nativeSignature);
 }
Ejemplo n.º 5
0
 public boolean match(Class type, IRubyObject arg) {
   return type.equals(argClass(arg))
       || (type.isPrimitive() && CodegenUtils.getBoxType(type) == argClass(arg));
 }