예제 #1
0
  @Override
  public Object interpret(
      ThreadContext context,
      DynamicScope currDynScope,
      IRubyObject self,
      Object[] temp,
      Block aBlock) {
    // FIXME: Receiver is not being used...should we be retrieving it?
    IRubyObject receiver = (IRubyObject) getReceiver().retrieve(context, self, currDynScope, temp);
    IRubyObject[] args = prepareArguments(context, self, getCallArgs(), currDynScope, temp);
    Block block = prepareBlock(context, self, currDynScope, temp);
    RubyModule klazz = context.getFrameKlazz();
    // SSS FIXME: Even though we may know the method name in some instances,
    // we are not making use of it here.  It is cleaner in the sense of not
    // relying on implicit information whose data flow doesn't show up in the IR.
    String methodName = context.getCurrentFrame().getName(); // methAddr.getName();

    checkSuperDisabledOrOutOfMethod(context, klazz, methodName);
    RubyClass superClass =
        RuntimeHelpers.findImplementerIfNecessary(self.getMetaClass(), klazz).getSuperClass();
    DynamicMethod method =
        superClass != null ? superClass.searchMethod(methodName) : UndefinedMethod.INSTANCE;

    Object rVal =
        method.isUndefined()
            ? RuntimeHelpers.callMethodMissing(
                context, self, method.getVisibility(), methodName, CallType.SUPER, args, block)
            : method.call(context, self, superClass, methodName, args, block);

    return hasUnusedResult() ? null : rVal;
  }
예제 #2
0
파일: SuperInstr.java 프로젝트: ryfow/jruby
  protected Object interpretSuper(
      ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
    // SSS FIXME: We should check in the current module (for instance methods) or the current
    // module's meta class (for class methods)
    //
    // RubyModule currM = context.getCurrentScope().getStaticScope().getModule();
    // RubyModule klazz = (isInstanceMethodSuper) ? currM : currM.getMetaClass();
    //
    // The question is how do we know what this 'super' ought to do?
    // For 'super' that occurs in a method scope, this is easy to figure out.
    // But, what about 'super' that occurs in block scope?  How do we figure that out?
    RubyModule klazz = context.getFrameKlazz();

    // SSS FIXME: Even though we may know the method name in some instances,
    // we are not making use of it here.
    String methodName = context.getCurrentFrame().getName(); // methAddr.getName();

    checkSuperDisabledOrOutOfMethod(context, klazz, methodName);
    RubyClass superClass =
        RuntimeHelpers.findImplementerIfNecessary(self.getMetaClass(), klazz).getSuperClass();
    DynamicMethod method =
        superClass != null ? superClass.searchMethod(methodName) : UndefinedMethod.INSTANCE;

    Object rVal =
        method.isUndefined()
            ? RuntimeHelpers.callMethodMissing(
                context, self, method.getVisibility(), methodName, CallType.SUPER, args, block)
            : method.call(context, self, superClass, methodName, args, block);

    return hasUnusedResult() ? null : rVal;
  }
 private IRubyObject callEachType(
     MethodType type, IRubyObject rubyReceiver, String methodName, Block block, Object... args) {
   Ruby runtime = rubyReceiver.getRuntime();
   IRubyObject[] rubyArgs = null;
   if (args != null && args.length > 0) {
     rubyArgs = JavaUtil.convertJavaArrayToRuby(runtime, args);
     for (int i = 0; i < rubyArgs.length; i++) {
       IRubyObject obj = rubyArgs[i];
       if (obj instanceof JavaObject) {
         rubyArgs[i] = Java.wrap(runtime, obj);
       }
     }
   }
   ThreadContext context = runtime.getCurrentContext();
   switch (type) {
     case CALLMETHOD_NOARG:
       return RuntimeHelpers.invoke(context, rubyReceiver, methodName);
     case CALLMETHOD:
       return RuntimeHelpers.invoke(context, rubyReceiver, methodName, rubyArgs);
     case CALLMETHOD_WITHBLOCK:
       return RuntimeHelpers.invoke(context, rubyReceiver, methodName, rubyArgs, block);
     case CALLSUPER:
       return RuntimeHelpers.invokeSuper(context, rubyReceiver, rubyArgs, Block.NULL_BLOCK);
     case CALLSUPER_WITHBLOCK:
       return RuntimeHelpers.invokeSuper(context, rubyReceiver, rubyArgs, block);
     default:
       break;
   }
   return null;
 }
예제 #4
0
 @JRubyMethod(frame = true, meta = true)
 public static IRubyObject inherited(
     ThreadContext context, IRubyObject recv, IRubyObject subclass) {
   IRubyObject subJavaClass = RuntimeHelpers.invoke(context, subclass, "java_class");
   if (subJavaClass.isNil()) {
     subJavaClass = RuntimeHelpers.invoke(context, recv, "java_class");
     RuntimeHelpers.invoke(context, subclass, "java_class=", subJavaClass);
   }
   return RuntimeHelpers.invokeSuper(context, recv, subclass, Block.NULL_BLOCK);
 }
예제 #5
0
 @JRubyMethod(name = "[]", meta = true, rest = true)
 public static IRubyObject op_aref(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
   IRubyObject javaClass = RuntimeHelpers.invoke(context, recv, "java_class");
   if (args.length > 0) {
     // construct new array proxy (ArrayJavaProxy)
     ArrayJavaProxyCreator ajpc = new ArrayJavaProxyCreator(context.runtime);
     ajpc.setup(context, javaClass, args);
     return ajpc;
   } else {
     return Java.get_proxy_class(
         javaClass, RuntimeHelpers.invoke(context, javaClass, "array_class"));
   }
 }
예제 #6
0
 private BlockBody createBlockBody19(
     Object scriptObject, ThreadContext context, int index, String descriptor)
     throws NumberFormatException {
   String[] firstSplit = descriptor.split(",");
   String[] secondSplit;
   if (firstSplit[2].length() == 0) {
     secondSplit = new String[0];
   } else {
     secondSplit = firstSplit[2].split(";");
     // FIXME: Big fat hack here, because scope names are expected to be interned strings by the
     // parser
     for (int i = 0; i < secondSplit.length; i++) {
       secondSplit[i] = secondSplit[i].intern();
     }
   }
   BlockBody body =
       RuntimeHelpers.createCompiledBlockBody19(
           context,
           scriptObject,
           firstSplit[0],
           Integer.parseInt(firstSplit[1]),
           secondSplit,
           Boolean.valueOf(firstSplit[3]),
           Integer.parseInt(firstSplit[4]),
           Boolean.valueOf(firstSplit[5]));
   return blockBodies[index] = body;
 }
예제 #7
0
  private static Class<?> getJavaClass(ThreadContext context, RubyModule module) {
    try {
      IRubyObject jClass = RuntimeHelpers.invoke(context, module, "java_class");

      return !(jClass instanceof JavaClass) ? null : ((JavaClass) jClass).javaClass();
    } catch (Exception e) {
      return null;
    }
  }
예제 #8
0
 @JRubyMethod(name = "min", frame = true, compat = CompatVersion.RUBY1_9)
 public IRubyObject min(ThreadContext context, Block block) {
   if (block.isGiven()) {
     return RuntimeHelpers.invokeSuper(context, this, block);
   } else {
     int c = RubyComparable.cmpint(context, begin.callMethod(context, "<=>", end), begin, end);
     if (c > 0 || (c == 0 && isExclusive)) return context.getRuntime().getNil();
     return begin;
   }
 }
예제 #9
0
 public DynamicMethod searchWithCache(RubyClass clazz, int index, String name1) {
   CacheEntry entry = clazz.searchWithCache(name1);
   DynamicMethod method = entry.method;
   if (entry.method == UndefinedMethod.INSTANCE) {
     return RuntimeHelpers.selectMethodMissing(
         clazz, method.getVisibility(), name1, CallType.FUNCTIONAL);
   }
   methodCache[index] = entry;
   return method;
 }
예제 #10
0
 private DynamicMethod cacheAndGet(
     ThreadContext context, RubyClass selfType, int index, String methodName) {
   CacheEntry entry = selfType.searchWithCache(methodName);
   DynamicMethod method = entry.method;
   if (method.isUndefined()) {
     return RuntimeHelpers.selectMethodMissing(
         context, selfType, method.getVisibility(), methodName, CallType.FUNCTIONAL);
   }
   methodCache[index] = entry;
   return method;
 }
예제 #11
0
 private static IRubyObject callMethodMissing(
     CacheEntry entry,
     CallType callType,
     ThreadContext context,
     IRubyObject self,
     String name,
     IRubyObject arg) {
   return RuntimeHelpers.selectMethodMissing(
           context, self, entry.method.getVisibility(), name, callType)
       .call(context, self, self.getMetaClass(), name, arg, Block.NULL_BLOCK);
 }
예제 #12
0
 @JRubyMethod(name = "open", required = 1, frame = true, meta = true)
 public static IRubyObject open(
     final ThreadContext context, IRubyObject recv, IRubyObject filename, Block block)
     throws IOException {
   Ruby runtime = recv.getRuntime();
   IRubyObject io =
       RuntimeHelpers.invoke(
           context, runtime.getFile(), "open", filename, runtime.newString("rb"));
   RubyGzipReader gzio = newInstance(recv, new IRubyObject[] {io}, block);
   return RubyGzipFile.wrapBlock(context, gzio, block);
 }
예제 #13
0
파일: RubyGlobal.java 프로젝트: shugo/jruby
    @Override
    public IRubyObject op_aset(ThreadContext context, IRubyObject key, IRubyObject value) {
      if (!key.respondsTo("to_str")) {
        throw getRuntime().newTypeError("can't convert " + key.getMetaClass() + " into String");
      }
      if (!value.respondsTo("to_str") && !value.isNil()) {
        throw getRuntime().newTypeError("can't convert " + value.getMetaClass() + " into String");
      }

      RubyString actualKey = getCorrectKey(key, context);

      if (value.isNil()) {
        return super.delete(context, actualKey, org.jruby.runtime.Block.NULL_BLOCK);
      }

      // return super.aset(getRuntime().newString("sadfasdF"), getRuntime().newString("sadfasdF"));
      return super.op_aset(
          context,
          RuntimeHelpers.invoke(context, actualKey, "to_str"),
          value.isNil() ? getRuntime().getNil() : RuntimeHelpers.invoke(context, value, "to_str"));
    }
 public void onDrawFrame(javax.microedition.khronos.opengles.GL10 gl) {
   if (callbackProcs[CB_DRAW_FRAME] != null) {
     try {
       RuntimeHelpers.invoke(
           getRuby().getCurrentContext(),
           callbackProcs[CB_DRAW_FRAME],
           "call",
           JavaUtil.convertJavaToRuby(getRuby(), gl));
     } catch (RaiseException re) {
       re.printStackTrace();
     }
   }
 }
 public void onSignalStrengthsChanged(android.telephony.SignalStrength signalStrength) {
   if (callbackProcs[CB_SIGNAL_STRENGTHS_CHANGED] != null) {
     try {
       RuntimeHelpers.invoke(
           getRuby().getCurrentContext(),
           callbackProcs[CB_SIGNAL_STRENGTHS_CHANGED],
           "call",
           JavaUtil.convertJavaToRuby(getRuby(), signalStrength));
     } catch (RaiseException re) {
       re.printStackTrace();
     }
   }
 }
예제 #16
0
  @Override
  public Object interpret(
      ThreadContext context,
      DynamicScope currDynScope,
      IRubyObject self,
      Object[] temp,
      Block block) {
    Ruby runtime = context.runtime;
    IRubyObject receiver = (IRubyObject) getObject().retrieve(context, self, currDynScope, temp);
    ByteList boundValue = RuntimeHelpers.getDefinedCall(context, self, receiver, getName().string);

    return boundValue == null ? context.nil : RubyString.newStringShared(runtime, boundValue);
  }
 public void onDataConnectionStateChanged(int state, int networkType) {
   if (callbackProcs[CB_DATA_CONNECTION_STATE_CHANGED] != null) {
     try {
       RuntimeHelpers.invoke(
           getRuby().getCurrentContext(),
           callbackProcs[CB_DATA_CONNECTION_STATE_CHANGED],
           "call",
           JavaUtil.convertJavaToRuby(getRuby(), state),
           JavaUtil.convertJavaToRuby(getRuby(), networkType));
     } catch (RaiseException re) {
       re.printStackTrace();
     }
   }
 }
예제 #18
0
  /*
   * call-seq:
   *  new(version = default)
   *
   * Create a new document with +version+ (defaults to "1.0")
   */
  @JRubyMethod(name = "new", meta = true, rest = true, required = 0)
  public static IRubyObject rbNew(ThreadContext context, IRubyObject cls, IRubyObject[] args) {
    XmlDocument doc = null;
    try {
      Document docNode = createNewDocument();
      doc = new XmlDocument(context.getRuntime(), (RubyClass) cls, docNode);
    } catch (Exception ex) {
      throw context.getRuntime().newRuntimeError("couldn't create document: " + ex.toString());
    }

    RuntimeHelpers.invoke(context, doc, "initialize", args);

    return doc;
  }
 public void onClick(android.content.DialogInterface dialog, int which) {
   if (callbackProcs[CB_CLICK] != null) {
     try {
       RuntimeHelpers.invoke(
           getRuby().getCurrentContext(),
           callbackProcs[CB_CLICK],
           "call",
           JavaUtil.convertJavaToRuby(getRuby(), dialog),
           JavaUtil.convertJavaToRuby(getRuby(), which));
     } catch (RaiseException re) {
       re.printStackTrace();
     }
   }
 }
예제 #20
0
 @Override
 public void setNode(ThreadContext context, Node node) {
   this.node = node;
   if (node != null) {
     resetCache();
     if (node.getNodeType() != Node.DOCUMENT_NODE) {
       doc = document(context);
       setInstanceVariable("@document", doc);
       if (doc != null) {
         RuntimeHelpers.invoke(context, doc, "decorate", this);
       }
     }
   }
 }
 public void onSurfaceChanged(javax.microedition.khronos.opengles.GL10 gl, int width, int height) {
   if (callbackProcs[CB_SURFACE_CHANGED] != null) {
     try {
       RuntimeHelpers.invoke(
           getRuby().getCurrentContext(),
           callbackProcs[CB_SURFACE_CHANGED],
           "call",
           JavaUtil.convertJavaToRuby(getRuby(), gl),
           JavaUtil.convertJavaToRuby(getRuby(), width),
           JavaUtil.convertJavaToRuby(getRuby(), height));
     } catch (RaiseException re) {
       re.printStackTrace();
     }
   }
 }
 public void onCallForwardingIndicatorChanged(boolean cfi) {
   if (callbackProcs[CB_CALL_FORWARDING_INDICATOR_CHANGED] != null) {
     super.onCallForwardingIndicatorChanged(cfi);
     try {
       RuntimeHelpers.invoke(
           getRuby().getCurrentContext(),
           callbackProcs[CB_CALL_FORWARDING_INDICATOR_CHANGED],
           "call",
           JavaUtil.convertJavaToRuby(getRuby(), cfi));
     } catch (RaiseException re) {
       re.printStackTrace();
     }
   } else {
     super.onCallForwardingIndicatorChanged(cfi);
   }
 }
 public void onSurfaceCreated(
     javax.microedition.khronos.opengles.GL10 gl,
     javax.microedition.khronos.egl.EGLConfig config) {
   if (callbackProcs[CB_SURFACE_CREATED] != null) {
     try {
       RuntimeHelpers.invoke(
           getRuby().getCurrentContext(),
           callbackProcs[CB_SURFACE_CREATED],
           "call",
           JavaUtil.convertJavaToRuby(getRuby(), gl),
           JavaUtil.convertJavaToRuby(getRuby(), config));
     } catch (RaiseException re) {
       re.printStackTrace();
     }
   }
 }
예제 #24
0
  @Override
  public Object interpret(
      ThreadContext context,
      DynamicScope currDynScope,
      IRubyObject self,
      Object[] temp,
      Block block) {
    Object receiver = array.retrieve(context, self, currDynScope, temp);

    // Don't call to_ary if we we have an array already and we are asked not to run to_ary on arrays
    if (dontToAryArrays.isTrue() && receiver instanceof RubyArray) {
      return receiver;
    } else {
      return RuntimeHelpers.aryToAry((IRubyObject) receiver);
    }
  }
 public void onMessageWaitingIndicatorChanged(boolean mwi) {
   if (callbackProcs[CB_MESSAGE_WAITING_INDICATOR_CHANGED] != null) {
     super.onMessageWaitingIndicatorChanged(mwi);
     try {
       RuntimeHelpers.invoke(
           getRuby().getCurrentContext(),
           callbackProcs[CB_MESSAGE_WAITING_INDICATOR_CHANGED],
           "call",
           JavaUtil.convertJavaToRuby(getRuby(), mwi));
     } catch (RaiseException re) {
       re.printStackTrace();
     }
   } else {
     super.onMessageWaitingIndicatorChanged(mwi);
   }
 }
 public void onServiceStateChanged(android.telephony.ServiceState serviceState) {
   if (callbackProcs[CB_SERVICE_STATE_CHANGED] != null) {
     super.onServiceStateChanged(serviceState);
     try {
       RuntimeHelpers.invoke(
           getRuby().getCurrentContext(),
           callbackProcs[CB_SERVICE_STATE_CHANGED],
           "call",
           JavaUtil.convertJavaToRuby(getRuby(), serviceState));
     } catch (RaiseException re) {
       re.printStackTrace();
     }
   } else {
     super.onServiceStateChanged(serviceState);
   }
 }
 public void onSignalStrengthChanged(int asu) {
   if (callbackProcs[CB_SIGNAL_STRENGTH_CHANGED] != null) {
     super.onSignalStrengthChanged(asu);
     try {
       RuntimeHelpers.invoke(
           getRuby().getCurrentContext(),
           callbackProcs[CB_SIGNAL_STRENGTH_CHANGED],
           "call",
           JavaUtil.convertJavaToRuby(getRuby(), asu));
     } catch (RaiseException re) {
       re.printStackTrace();
     }
   } else {
     super.onSignalStrengthChanged(asu);
   }
 }
 public void onCellLocationChanged(android.telephony.CellLocation location) {
   if (callbackProcs[CB_CELL_LOCATION_CHANGED] != null) {
     super.onCellLocationChanged(location);
     try {
       RuntimeHelpers.invoke(
           getRuby().getCurrentContext(),
           callbackProcs[CB_CELL_LOCATION_CHANGED],
           "call",
           JavaUtil.convertJavaToRuby(getRuby(), location));
     } catch (RaiseException re) {
       re.printStackTrace();
     }
   } else {
     super.onCellLocationChanged(location);
   }
 }
 public void onDataActivity(int direction) {
   if (callbackProcs[CB_DATA_ACTIVITY] != null) {
     super.onDataActivity(direction);
     try {
       RuntimeHelpers.invoke(
           getRuby().getCurrentContext(),
           callbackProcs[CB_DATA_ACTIVITY],
           "call",
           JavaUtil.convertJavaToRuby(getRuby(), direction));
     } catch (RaiseException re) {
       re.printStackTrace();
     }
   } else {
     super.onDataActivity(direction);
   }
 }
 public void onCallStateChanged(int state, java.lang.String incomingNumber) {
   if (callbackProcs[CB_CALL_STATE_CHANGED] != null) {
     super.onCallStateChanged(state, incomingNumber);
     try {
       RuntimeHelpers.invoke(
           getRuby().getCurrentContext(),
           callbackProcs[CB_CALL_STATE_CHANGED],
           "call",
           JavaUtil.convertJavaToRuby(getRuby(), state),
           JavaUtil.convertJavaToRuby(getRuby(), incomingNumber));
     } catch (RaiseException re) {
       re.printStackTrace();
     }
   } else {
     super.onCallStateChanged(state, incomingNumber);
   }
 }