org.jruby.RubyClass - java examples

Here are the examples of the java api org.jruby.RubyClass taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

18 View Complete Implementation : Type.java
Copyright GNU General Public License v3.0
Author : apicloudcom
private static final void defineBuiltinType(Ruby runtime, RubyClreplaced builtinClreplaced, NativeType nativeType, String... names) {
    try {
        if (names.length > 0) {
            for (String n : names) {
                builtinClreplaced.setConstant(n.toUpperCase(), new Builtin(runtime, builtinClreplaced, nativeType, n.toLowerCase()));
            }
        } else {
            builtinClreplaced.setConstant(nativeType.name(), new Builtin(runtime, builtinClreplaced, nativeType, nativeType.name().toLowerCase()));
        }
    } catch (UnsupportedOperationException ex) {
    }
}

18 View Complete Implementation : JavaInterfaceTemplate.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public static void addRealImplClreplacedNew(RubyClreplaced clazz) {
    RubyClreplaced singleton = clazz.getSingletonClreplaced();
    singleton.addMethod("new", new org.jruby.internal.runtime.methods.JavaMethod(singleton, Visibility.PUBLIC) {

        private Constructor proxyConstructor;

        @Override
        public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
            replacedert self instanceof RubyClreplaced : "new defined on non-clreplaced";
            RubyClreplaced clazzSelf = (RubyClreplaced) self;
            // if we haven't been here before, reify the clreplaced
            Clreplaced reifiedClreplaced = clazzSelf.getReifiedClreplaced();
            if (proxyConstructor == null || proxyConstructor.getDeclaringClreplaced() != reifiedClreplaced) {
                if (reifiedClreplaced == null) {
                    reifiedClreplaced = Java.generateRealClreplaced(clazzSelf);
                }
                proxyConstructor = Java.getRealClreplacedConstructor(context.getRuntime(), reifiedClreplaced);
            }
            IRubyObject newObj = Java.constructProxy(context.getRuntime(), proxyConstructor, clazzSelf);
            RuntimeHelpers.invoke(context, newObj, "initialize", args, block);
            return newObj;
        }
    });
}

18 View Complete Implementation : MarshalStream.java
Copyright GNU General Public License v3.0
Author : apicloudcom
private List<Variable<Object>> getVariables(IRubyObject value) throws IOException {
    List<Variable<Object>> variables = null;
    if (value instanceof CoreObjectType) {
        int nativeTypeIndex = ((CoreObjectType) value).getNativeTypeIndex();
        if (nativeTypeIndex != ClreplacedIndex.OBJECT && nativeTypeIndex != ClreplacedIndex.BASICOBJECT) {
            if (shouldMarshalEncoding(value) || (!value.isImmediate() && value.hasVariables() && nativeTypeIndex != ClreplacedIndex.CLreplaced && nativeTypeIndex != ClreplacedIndex.MODULE)) {
                // object has instance vars and isn't a clreplaced, get a snapshot to be marshalled
                // and output the ivar header here
                variables = value.getVariableList();
                // write `I' instance var signet if clreplaced is NOT a direct subclreplaced of Object
                write(TYPE_IVAR);
            }
            RubyClreplaced type = value.getMetaClreplaced();
            switch(nativeTypeIndex) {
                case ClreplacedIndex.STRING:
                case ClreplacedIndex.REGEXP:
                case ClreplacedIndex.ARRAY:
                case ClreplacedIndex.HASH:
                    type = dumpExtended(type);
                    break;
            }
            if (nativeTypeIndex != value.getMetaClreplaced().index && nativeTypeIndex != ClreplacedIndex.STRUCT) {
                // object is a custom clreplaced that extended one of the native types other than Object
                writeUserClreplaced(value, type);
            }
        }
    }
    return variables;
}

18 View Complete Implementation : TypeConverter.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Converts this object to type 'targetType' using 'convertMethod' method and raises TypeError exception on failure (MRI: rb_convert_type).
 *
 * @param obj the object to convert
 * @param targetType is the type we are trying to convert to
 * @param convertMethod is the method to be called to try and convert to targeType
 * @return the converted value
 */
public static final IRubyObject convertToType(IRubyObject obj, RubyClreplaced target, String convertMethod) {
    if (target.isInstance(obj))
        return obj;
    IRubyObject val = convertToType(obj, target, convertMethod, true);
    if (!target.isInstance(val))
        throw obj.getRuntime().newTypeError(obj.getMetaClreplaced() + "#" + convertMethod + " should return " + target.getName());
    return val;
}

18 View Complete Implementation : TypeConverter.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Converts this object to type 'targetType' using 'convertMethod' method (MRI: convert_type 1.9).
 *
 * @param obj the object to convert
 * @param targetType is the type we are trying to convert to
 * @param convertMethodIndex the fast index to use for calling the method
 * @param convertMethod is the method to be called to try and convert to targeType
 * @param raiseOnError will throw an Error if conversion does not work
 * @return the converted value
 */
public static final IRubyObject convertToType19(IRubyObject obj, RubyClreplaced target, String convertMethod, boolean raise) {
    IRubyObject r = obj.checkCallMethod(obj.getRuntime().getCurrentContext(), convertMethod);
    if (r == null) {
        return handleUncoercibleObject(raise, obj, target);
    }
    return r;
}

18 View Complete Implementation : CallableSelector.java
Copyright GNU General Public License v3.0
Author : apicloudcom
private static void warnMultipleMatches(IRubyObject[] args, List<ParameterTypes> newFinds) {
    RubyClreplaced[] argTypes = new RubyClreplaced[args.length];
    for (int i = 0; i < argTypes.length; i++) {
        argTypes[i] = args[i].getMetaClreplaced();
    }
    StringBuilder builder = new StringBuilder("multiple Java methods for arguments (");
    boolean first = true;
    for (RubyClreplaced argType : argTypes) {
        if (!first) {
            builder.append(",");
        }
        first = false;
        builder.append(argType);
    }
    builder.append("), using first:");
    for (ParameterTypes types : newFinds) {
        builder.append("\n  ").append(types);
    }
    args[0].getRuntime().getWarnings().warn(builder.toString());
}

17 View Complete Implementation : SuperCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
protected IRubyObject cacheAndCall(IRubyObject caller, RubyClreplaced selfType, Block block, ThreadContext context, IRubyObject self, String name, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3) {
    CacheEntry entry = selfType != null ? selfType.searchWithCache(name) : CacheEntry.NULL_CACHE;
    DynamicMethod method = entry.method;
    if (methodMissing(method, caller)) {
        return callMethodMissing(context, self, name, method, arg1, arg2, arg3, block);
    }
    cache = new SuperTuple(name, entry);
    return method.call(context, self, selfType, name, arg1, arg2, arg3, block);
}

17 View Complete Implementation : TypeConverter.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Converts this object to type 'targetType' using 'convertMethod' method (MRI: convert_type).
 *
 * @param obj the object to convert
 * @param targetType is the type we are trying to convert to
 * @param convertMethodIndex the fast index to use for calling the method
 * @param convertMethod is the method to be called to try and convert to targeType
 * @param raiseOnError will throw an Error if conversion does not work
 * @return the converted value
 */
public static final IRubyObject convertToType(IRubyObject obj, RubyClreplaced target, String convertMethod, boolean raise) {
    if (!obj.respondsTo(convertMethod)) {
        return handleUncoercibleObject(raise, obj, target);
    }
    return obj.callMethod(obj.getRuntime().getCurrentContext(), convertMethod);
}

17 View Complete Implementation : JavaCallable.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public static void registerRubyMethods(Ruby runtime, RubyClreplaced result) {
    result.defineAnnotatedMethods(JavaCallable.clreplaced);
}

17 View Complete Implementation : JavaInterfaceTemplate.java
Copyright GNU General Public License v3.0
Author : apicloudcom
private static void checkAlreadyReified(final RubyClreplaced clazz, Ruby runtime) throws RaiseException {
    // not allowed for original (non-generated) Java clreplacedes
    // note: not allowing for any previously created clreplaced right now;
    // this restriction might be loosened later for generated clreplacedes
    if ((Java.NEW_STYLE_EXTENSION && clazz.getReifiedClreplaced() != null) || (clazz.hasInstanceVariable("@java_clreplaced") && clazz.getInstanceVariable("@java_clreplaced").isTrue() && !clazz.getSingletonClreplaced().isMethodBound("java_proxy_clreplaced", false)) || (clazz.hasInstanceVariable("@java_proxy_clreplaced") && clazz.getInstanceVariable("@java_proxy_clreplaced").isTrue())) {
        throw runtime.newArgumentError("can not add Java interface to existing Java clreplaced");
    }
}

17 View Complete Implementation : JRuby.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public static void sysFail(Ruby runtime, String message, int n) {
    IRubyObject arg = (message != null) ? runtime.newString(message) : runtime.getNil();
    RubyClreplaced instance = runtime.getErrno(n);
    if (instance == null) {
        instance = runtime.getSystemCallError();
        throw new RaiseException((RubyException) (instance.newInstance(runtime.getCurrentContext(), new IRubyObject[] { arg, runtime.newFixnum(n) }, Block.NULL_BLOCK)));
    } else {
        throw new RaiseException((RubyException) (instance.newInstance(runtime.getCurrentContext(), new IRubyObject[] { arg }, Block.NULL_BLOCK)));
    }
}

17 View Complete Implementation : CachingCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
protected IRubyObject cacheAndCall(IRubyObject caller, RubyClreplaced selfType, Block block, ThreadContext context, IRubyObject self, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3) {
    CacheEntry entry = selfType.searchWithCache(methodName);
    DynamicMethod method = entry.method;
    if (methodMissing(method, caller)) {
        return callMethodMissing(context, self, method, arg1, arg2, arg3, block);
    }
    updateCache(entry);
    return method.call(context, self, selfType, methodName, arg1, arg2, arg3, block);
}

17 View Complete Implementation : SuperCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
protected IRubyObject cacheAndCall(IRubyObject caller, RubyClreplaced selfType, Block block, ThreadContext context, IRubyObject self, String name) {
    CacheEntry entry = selfType != null ? selfType.searchWithCache(name) : CacheEntry.NULL_CACHE;
    DynamicMethod method = entry.method;
    if (methodMissing(method, caller)) {
        return callMethodMissing(context, self, name, method, block);
    }
    cache = new SuperTuple(name, entry);
    return method.call(context, self, selfType, name, block);
}

17 View Complete Implementation : InvokeDynamicSupport.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public static IRubyObject fallback(JRubyCallSite site, ThreadContext context, IRubyObject caller, IRubyObject self, String name, IRubyObject arg0, IRubyObject arg1) {
    RubyClreplaced selfClreplaced = pollAndGetClreplaced(context, self);
    CacheEntry entry = selfClreplaced.searchWithCache(name);
    if (methodMissing(entry, site.callType(), name, caller)) {
        return callMethodMissing(entry, site.callType(), context, self, name, arg0, arg1);
    }
    site.setTarget(createGWT(TEST_2, TARGET_2, FALLBACK_2, entry, site));
    return entry.method.call(context, self, selfClreplaced, name, arg0, arg1);
}

17 View Complete Implementation : JavaInterfaceTemplate.java
Copyright GNU General Public License v3.0
Author : apicloudcom
private static void appendFeaturesToClreplaced(ThreadContext context, IRubyObject self, final RubyClreplaced clazz) {
    Ruby runtime = context.getRuntime();
    checkAlreadyReified(clazz, runtime);
    IRubyObject javaClreplacedObj = RuntimeHelpers.getInstanceVariable(self, runtime, "@java_clreplaced");
    IRubyObject javaInterfaces;
    if (!clazz.hasInstanceVariable("@java_interfaces")) {
        javaInterfaces = RubyArray.newArray(runtime, javaClreplacedObj);
        RuntimeHelpers.setInstanceVariable(javaInterfaces, clazz, "@java_interfaces");
        initInterfaceImplMethods(context, clazz);
    } else {
        javaInterfaces = RuntimeHelpers.getInstanceVariable(clazz, runtime, "@java_interfaces");
        // we've already done the above priming logic, just add another interface
        // to the list of intentions unless we're past the point of no return or
        // already intend to implement the given interface
        if (!(javaInterfaces.isFrozen() || ((RubyArray) javaInterfaces).includes(context, javaClreplacedObj))) {
            ((RubyArray) javaInterfaces).append(javaClreplacedObj);
        }
    }
}

17 View Complete Implementation : SuperCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
protected IRubyObject cacheAndCall(IRubyObject caller, RubyClreplaced selfType, Block block, IRubyObject[] args, ThreadContext context, IRubyObject self, String name) {
    CacheEntry entry = selfType != null ? selfType.searchWithCache(name) : CacheEntry.NULL_CACHE;
    DynamicMethod method = entry.method;
    if (methodMissing(method, caller)) {
        return callMethodMissing(context, self, name, method, args, block);
    }
    cache = new SuperTuple(name, entry);
    return method.call(context, self, selfType, name, args, block);
}

17 View Complete Implementation : SuperCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg1) {
    RubyModule klazz = context.getFrameKlazz();
    String name = context.getFrameName();
    RubyClreplaced selfType = pollAndGetClreplaced(context, self, klazz, name);
    SuperTuple myCache = cache;
    if (selfType != null && myCache.cacheOk(name, selfType)) {
        return myCache.cache.method.call(context, self, selfType, name, arg1);
    }
    return cacheAndCall(caller, selfType, context, self, name, arg1);
}

17 View Complete Implementation : CachingCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
protected IRubyObject cacheAndCall(IRubyObject caller, RubyClreplaced selfType, Block block, IRubyObject[] args, ThreadContext context, IRubyObject self) {
    CacheEntry entry = selfType.searchWithCache(methodName);
    DynamicMethod method = entry.method;
    if (methodMissing(method, caller)) {
        return callMethodMissing(context, self, method, args, block);
    }
    updateCache(entry);
    return method.call(context, self, selfType, methodName, args, block);
}

17 View Complete Implementation : TypeConverter.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Converts this object to type 'targetType' using 'convertMethod' method and raises TypeError exception on failure (MRI: rb_convert_type).
 *
 * @param obj the object to convert
 * @param targetType is the type we are trying to convert to
 * @param convertMethodIndex the fast index to use for calling the method
 * @param convertMethod is the method to be called to try and convert to targeType
 * @return the converted value
 */
@Deprecated
public static final IRubyObject convertToType(IRubyObject obj, RubyClreplaced target, int convertMethodIndex, String convertMethod) {
    if (target.isInstance(obj))
        return obj;
    IRubyObject val = convertToType(obj, target, convertMethod, true);
    if (!target.isInstance(val))
        throw obj.getRuntime().newTypeError(obj.getMetaClreplaced() + "#" + convertMethod + " should return " + target.getName());
    return val;
}

17 View Complete Implementation : RealClassGenerator.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public static Clreplaced createRealImplClreplaced(Clreplaced superClreplaced, Clreplaced[] interfaces, RubyClreplaced rubyClreplaced, Ruby ruby, String name) {
    String[] superTypeNames = new String[interfaces.length];
    Map<String, List<Method>> simpleToAll = buildSimpleToAllMap(interfaces, superTypeNames);
    Clreplaced newClreplaced = defineRealImplClreplaced(ruby, name, superClreplaced, superTypeNames, simpleToAll);
    return newClreplaced;
}

17 View Complete Implementation : SuperCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3) {
    RubyModule klazz = context.getFrameKlazz();
    String name = context.getFrameName();
    RubyClreplaced selfType = pollAndGetClreplaced(context, self, klazz, name);
    SuperTuple myCache = cache;
    if (selfType != null && myCache.cacheOk(name, selfType)) {
        return myCache.cache.method.call(context, self, selfType, name, arg1, arg2, arg3);
    }
    return cacheAndCall(caller, selfType, context, self, name, arg1, arg2, arg3);
}

17 View Complete Implementation : Struct.java
Copyright GNU General Public License v3.0
Author : apicloudcom
static final boolean isStruct(Ruby runtime, RubyClreplaced klreplaced) {
    return klreplaced.isKindOfModule(runtime.fastGetModule("FFI").getClreplaced("Struct"));
}

17 View Complete Implementation : TypeConverter.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Higher level conversion utility similar to convertToType but it can throw an
 * additional TypeError during conversion (MRI: rb_check_convert_type).
 *
 * @param obj the object to convert
 * @param targetType is the type we are trying to convert to
 * @param convertMethod is the method to be called to try and convert to targeType
 * @return the converted value
 */
public static final IRubyObject convertToTypeOrRaise(IRubyObject obj, RubyClreplaced target, String convertMethod) {
    if (target.isInstance(obj))
        return obj;
    IRubyObject val = TypeConverter.convertToType(obj, target, convertMethod, true);
    if (val.isNil())
        return val;
    if (!target.isInstance(val))
        throw obj.getRuntime().newTypeError(obj.getMetaClreplaced() + "#" + convertMethod + " should return " + target.getName());
    return val;
}

17 View Complete Implementation : MappedType.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public static RubyClreplaced createConverterTypeClreplaced(Ruby runtime, RubyModule ffiModule) {
    RubyClreplaced convClreplaced = ffiModule.fastGetClreplaced("Type").defineClreplacedUnder("Mapped", ffiModule.fastGetClreplaced("Type"), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
    convClreplaced.defineAnnotatedMethods(MappedType.clreplaced);
    convClreplaced.defineAnnotatedConstants(MappedType.clreplaced);
    return convClreplaced;
}

17 View Complete Implementation : RespondToCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
@Override
protected IRubyObject cacheAndCall(IRubyObject caller, RubyClreplaced selfType, ThreadContext context, IRubyObject self, IRubyObject arg0, IRubyObject arg1) {
    CacheEntry entry = selfType.searchWithCache(methodName);
    DynamicMethod method = entry.method;
    if (methodMissing(method, caller)) {
        return callMethodMissing(context, self, method, arg0, arg1);
    }
    // alternate logic to cache the result of respond_to if it's the standard one
    if (entry.method == context.getRuntime().getRespondToMethod()) {
        String name = arg0.asJavaString();
        RespondToTuple tuple = recacheRespondsTo(entry, name, selfType, !arg1.isTrue(), context);
        respondToTuple = tuple;
        return tuple.respondsTo;
    }
    // normal logic if it's not the builtin respond_to? method
    cache = entry;
    return method.call(context, self, selfType, methodName, arg0, arg1);
}

17 View Complete Implementation : TypeConverter.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public static IRubyObject handleUncoercibleObject(boolean raise, IRubyObject obj, RubyClreplaced target) throws RaiseException {
    if (raise) {
        String type;
        if (obj.isNil()) {
            type = "nil";
        } else if (obj instanceof RubyBoolean) {
            type = obj.isTrue() ? "true" : "false";
        } else {
            type = obj.getMetaClreplaced().getRealClreplaced().getName();
        }
        throw obj.getRuntime().newTypeError("can't convert " + type + " into " + target);
    } else {
        return obj.getRuntime().getNil();
    }
}

17 View Complete Implementation : InvokeDynamicSupport.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public static RubyClreplaced pollAndGetClreplaced(ThreadContext context, IRubyObject self) {
    context.callThreadPoll();
    RubyClreplaced selfType = self.getMetaClreplaced();
    return selfType;
}

17 View Complete Implementation : MarshalStream.java
Copyright GNU General Public License v3.0
Author : apicloudcom
private void userNewCommon(IRubyObject value, DynamicMethod method) throws IOException {
    registerLinkTarget(value);
    write(TYPE_USRMARSHAL);
    RubyClreplaced metaclreplaced = value.getMetaClreplaced().getRealClreplaced();
    writeAndRegisterSymbol(metaclreplaced.getName());
    IRubyObject marshaled;
    if (method != null) {
        marshaled = method.call(runtime.getCurrentContext(), value, value.getMetaClreplaced(), "marshal_dump");
    } else {
        marshaled = value.callMethod(runtime.getCurrentContext(), "marshal_dump");
    }
    dumpObject(marshaled);
}

17 View Complete Implementation : SuperCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
protected IRubyObject cacheAndCall(IRubyObject caller, RubyClreplaced selfType, Block block, ThreadContext context, IRubyObject self, String name, IRubyObject arg) {
    CacheEntry entry = selfType != null ? selfType.searchWithCache(name) : CacheEntry.NULL_CACHE;
    DynamicMethod method = entry.method;
    if (methodMissing(method, caller)) {
        return callMethodMissing(context, self, name, method, arg, block);
    }
    cache = new SuperTuple(name, entry);
    return method.call(context, self, selfType, name, arg, block);
}

17 View Complete Implementation : RespondToCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
@Override
public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject name) {
    RubyClreplaced klreplaced = self.getMetaClreplaced();
    RespondToTuple tuple = respondToTuple;
    if (tuple.cacheOk(klreplaced)) {
        String strName = name.asJavaString();
        if (strName.equals(tuple.name) && tuple.checkVisibility)
            return tuple.respondsTo;
    }
    // go through normal call logic, which will hit overridden cacheAndCall
    IRubyObject respond = super.call(context, caller, self, name);
    if (!respond.isTrue() && context.getRuntime().is1_9()) {
        respond = self.callMethod(context, "respond_to_missing?", new IRubyObject[] { name, context.getRuntime().getFalse() });
        respond = context.getRuntime().newBoolean(respond.isTrue());
    }
    return respond;
}

17 View Complete Implementation : JavaObject.java
Copyright GNU General Public License v3.0
Author : apicloudcom
protected static void registerRubyMethods(Ruby runtime, RubyClreplaced result) {
    result.defineAnnotatedMethods(JavaObject.clreplaced);
}

17 View Complete Implementation : TypeConverter.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Converts this object to type 'targetType' using 'convertMethod' method and raises TypeError exception on failure (MRI: rb_convert_type in 1.9).
 *
 * @param obj the object to convert
 * @param targetType is the type we are trying to convert to
 * @param convertMethod is the method to be called to try and convert to targeType
 * @return the converted value
 */
public static final IRubyObject convertToType19(IRubyObject obj, RubyClreplaced target, String convertMethod) {
    if (target.isInstance(obj))
        return obj;
    IRubyObject val = convertToType19(obj, target, convertMethod, true);
    if (!target.isInstance(val)) {
        String cname = obj.getMetaClreplaced().toString();
        throw obj.getRuntime().newTypeError("can't convert " + cname + " to " + target.getName() + " (" + cname + "#" + convertMethod + " gives " + val.getMetaClreplaced() + ")");
    }
    return val;
}

17 View Complete Implementation : CachingCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
protected IRubyObject cacheAndCall(IRubyObject caller, RubyClreplaced selfType, Block block, ThreadContext context, IRubyObject self, IRubyObject arg) {
    CacheEntry entry = selfType.searchWithCache(methodName);
    DynamicMethod method = entry.method;
    if (methodMissing(method, caller)) {
        return callMethodMissing(context, self, method, arg, block);
    }
    updateCache(entry);
    return method.call(context, self, selfType, methodName, arg, block);
}

17 View Complete Implementation : UnmarshalStream.java
Copyright GNU General Public License v3.0
Author : apicloudcom
private IRubyObject defaultObjectUnmarshal() throws IOException {
    RubySymbol clreplacedName = (RubySymbol) unmarshalObject(false);
    RubyClreplaced type = null;
    try {
        type = getClreplacedFromPath(runtime, clreplacedName.toString());
    } catch (RaiseException e) {
        if (runtime.fastGetModule("NameError").isInstance(e.getException())) {
            throw runtime.newArgumentError("undefined clreplaced/module " + clreplacedName.asJavaString());
        }
        throw e;
    }
    replacedert type != null : "type shouldn't be null.";
    IRubyObject result = (IRubyObject) type.unmarshal(this);
    return result;
}

17 View Complete Implementation : CachingCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
protected IRubyObject cacheAndCall(IRubyObject caller, RubyClreplaced selfType, Block block, ThreadContext context, IRubyObject self, IRubyObject arg1, IRubyObject arg2) {
    CacheEntry entry = selfType.searchWithCache(methodName);
    DynamicMethod method = entry.method;
    if (methodMissing(method, caller)) {
        return callMethodMissing(context, self, method, arg1, arg2, block);
    }
    updateCache(entry);
    return method.call(context, self, selfType, methodName, arg1, arg2, block);
}

17 View Complete Implementation : RespondToCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
@Override
public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject name, IRubyObject bool) {
    RubyClreplaced klreplaced = self.getMetaClreplaced();
    RespondToTuple tuple = respondToTuple;
    if (tuple.cacheOk(klreplaced)) {
        String strName = name.asJavaString();
        if (strName.equals(tuple.name) && !bool.isTrue() == tuple.checkVisibility)
            return tuple.respondsTo;
    }
    // go through normal call logic, which will hit overridden cacheAndCall
    IRubyObject respond = super.call(context, caller, self, name, bool);
    if (!respond.isTrue() && context.getRuntime().is1_9()) {
        respond = self.callMethod(context, "respond_to_missing?", new IRubyObject[] { name, bool });
        respond = context.getRuntime().newBoolean(respond.isTrue());
    }
    return respond;
}

17 View Complete Implementation : InvokeDynamicSupport.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public static IRubyObject fallback(JRubyCallSite site, ThreadContext context, IRubyObject caller, IRubyObject self, String name, IRubyObject arg0) {
    RubyClreplaced selfClreplaced = pollAndGetClreplaced(context, self);
    CacheEntry entry = selfClreplaced.searchWithCache(name);
    if (methodMissing(entry, site.callType(), name, caller)) {
        return callMethodMissing(entry, site.callType(), context, self, name, arg0);
    }
    site.setTarget(createGWT(TEST_1, TARGET_1, FALLBACK_1, entry, site));
    return entry.method.call(context, self, selfClreplaced, name, arg0);
}

17 View Complete Implementation : SuperCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg1, IRubyObject arg2) {
    RubyModule klazz = context.getFrameKlazz();
    String name = context.getFrameName();
    RubyClreplaced selfType = pollAndGetClreplaced(context, self, klazz, name);
    SuperTuple myCache = cache;
    if (selfType != null && myCache.cacheOk(name, selfType)) {
        return myCache.cache.method.call(context, self, selfType, name, arg1, arg2);
    }
    return cacheAndCall(caller, selfType, context, self, name, arg1, arg2);
}

17 View Complete Implementation : MarshalStream.java
Copyright GNU General Public License v3.0
Author : apicloudcom
private boolean hreplacedingletonMethods(RubyClreplaced type) {
    for (DynamicMethod method : type.getMethods().values()) {
        // We do not want to capture cached methods
        if (method.getImplementationClreplaced() == type) {
            return true;
        }
    }
    return false;
}

17 View Complete Implementation : RespondToCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
@Override
protected IRubyObject cacheAndCall(IRubyObject caller, RubyClreplaced selfType, ThreadContext context, IRubyObject self, IRubyObject arg) {
    CacheEntry entry = selfType.searchWithCache(methodName);
    DynamicMethod method = entry.method;
    if (methodMissing(method, caller)) {
        return callMethodMissing(context, self, method, arg);
    }
    // alternate logic to cache the result of respond_to if it's the standard one
    if (entry.method == context.getRuntime().getRespondToMethod()) {
        String name = arg.asJavaString();
        RespondToTuple tuple = recacheRespondsTo(entry, name, selfType, true, context);
        respondToTuple = tuple;
        return tuple.respondsTo;
    }
    // normal logic if it's not the builtin respond_to? method
    cache = entry;
    return method.call(context, self, selfType, methodName, arg);
}

17 View Complete Implementation : SuperCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self) {
    RubyModule klazz = context.getFrameKlazz();
    String name = context.getFrameName();
    RubyClreplaced selfType = pollAndGetClreplaced(context, self, klazz, name);
    SuperTuple myCache = cache;
    if (selfType != null && myCache.cacheOk(name, selfType)) {
        return myCache.cache.method.call(context, self, selfType, name);
    }
    return cacheAndCall(caller, selfType, context, self, name);
}

17 View Complete Implementation : TypeConverter.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Higher level conversion utility similar to convertToType but it can throw an
 * additional TypeError during conversion (MRI: rb_check_convert_type).
 *
 * @param obj the object to convert
 * @param targetType is the type we are trying to convert to
 * @param convertMethodIndex the fast index to use for calling the method
 * @param convertMethod is the method to be called to try and convert to targeType
 * @return the converted value
 */
public static final IRubyObject convertToTypeWithCheck(IRubyObject obj, RubyClreplaced target, String convertMethod) {
    if (target.isInstance(obj))
        return obj;
    IRubyObject val = TypeConverter.convertToType(obj, target, convertMethod, false);
    if (val.isNil())
        return val;
    if (!target.isInstance(val))
        throw obj.getRuntime().newTypeError(obj.getMetaClreplaced() + "#" + convertMethod + " should return " + target.getName());
    return val;
}

17 View Complete Implementation : RubyUNIXServer.java
Copyright GNU General Public License v3.0
Author : apicloudcom
static void createUNIXServer(Ruby runtime) {
    RubyClreplaced rb_cUNIXServer = runtime.defineClreplaced("UNIXServer", runtime.fastGetClreplaced("UNIXSocket"), UNIXSERVER_ALLOCATOR);
    runtime.getObject().fastSetConstant("UNIXserver", rb_cUNIXServer);
    rb_cUNIXServer.defineAnnotatedMethods(RubyUNIXServer.clreplaced);
}

17 View Complete Implementation : InvokeDynamicSupport.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public static IRubyObject fallback(JRubyCallSite site, ThreadContext context, IRubyObject caller, IRubyObject self, String name, IRubyObject[] args) {
    RubyClreplaced selfClreplaced = pollAndGetClreplaced(context, self);
    CacheEntry entry = selfClreplaced.searchWithCache(name);
    if (methodMissing(entry, site.callType(), name, caller)) {
        return callMethodMissing(entry, site.callType(), context, self, name, args);
    }
    site.setTarget(createGWT(TEST_N, TARGET_N, FALLBACK_N, entry, site));
    return entry.method.call(context, self, selfClreplaced, name, args);
}

17 View Complete Implementation : RuntimeCache.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public DynamicMethod getMethod(ThreadContext context, RubyClreplaced selfType, int index, String methodName) {
    CacheEntry myCache = getCacheEntry(index);
    if (CacheEntry.typeOk(myCache, selfType)) {
        return myCache.method;
    }
    return cacheAndGet(context, selfType, index, methodName);
}

17 View Complete Implementation : SuperCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject... args) {
    RubyModule klazz = context.getFrameKlazz();
    String name = context.getFrameName();
    RubyClreplaced selfType = pollAndGetClreplaced(context, self, klazz, name);
    SuperTuple myCache = cache;
    if (selfType != null && myCache.cacheOk(name, selfType)) {
        return myCache.cache.method.call(context, self, selfType, name, args);
    }
    return cacheAndCall(caller, selfType, args, context, self, name);
}

17 View Complete Implementation : RespondToCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
private static RespondToTuple recacheRespondsTo(CacheEntry respondToMethod, String newString, RubyClreplaced klreplaced, boolean checkVisibility, ThreadContext context) {
    Ruby runtime = context.getRuntime();
    CacheEntry respondToLookupResult = klreplaced.searchWithCache(newString);
    IRubyObject respondsTo;
    if (!respondToLookupResult.method.isUndefined() && !respondToLookupResult.method.isNotImplemented()) {
        respondsTo = checkVisibilityAndCache(respondToLookupResult, checkVisibility, runtime);
    } else {
        respondsTo = runtime.getFalse();
    }
    return new RespondToTuple(newString, checkVisibility, respondToMethod, respondToLookupResult, respondsTo);
}

17 View Complete Implementation : TypeConverter.java
Copyright GNU General Public License v3.0
Author : apicloudcom
/**
 * Higher level conversion utility similar to convertToType but it can throw an
 * additional TypeError during conversion (MRI: rb_check_convert_type).
 *
 * @param obj the object to convert
 * @param targetType is the type we are trying to convert to
 * @param convertMethodIndex the fast index to use for calling the method
 * @param convertMethod is the method to be called to try and convert to targeType
 * @return the converted value
 */
public static final IRubyObject convertToTypeWithCheck19(IRubyObject obj, RubyClreplaced target, String convertMethod) {
    if (target.isInstance(obj))
        return obj;
    IRubyObject val = TypeConverter.convertToType19(obj, target, convertMethod, false);
    if (val.isNil())
        return val;
    if (!target.isInstance(val))
        throw obj.getRuntime().newTypeError(obj.getMetaClreplaced() + "#" + convertMethod + " should return " + target.getName());
    return val;
}

17 View Complete Implementation : RubyUNIXSocket.java
Copyright GNU General Public License v3.0
Author : apicloudcom
protected static void rb_sys_fail(Ruby runtime, String message) {
    final int n = LastError.getLastError();
    IRubyObject arg = (message != null) ? runtime.newString(message) : runtime.getNil();
    RubyClreplaced instance = runtime.getErrno(n);
    if (instance == null) {
        instance = runtime.getSystemCallError();
        throw new RaiseException((RubyException) (instance.newInstance(runtime.getCurrentContext(), new IRubyObject[] { arg, runtime.newFixnum(n) }, Block.NULL_BLOCK)));
    } else {
        throw new RaiseException((RubyException) (instance.newInstance(runtime.getCurrentContext(), new IRubyObject[] { arg }, Block.NULL_BLOCK)));
    }
}

17 View Complete Implementation : SuperCallSite.java
Copyright GNU General Public License v3.0
Author : apicloudcom
protected IRubyObject cacheAndCall(IRubyObject caller, RubyClreplaced selfType, Block block, ThreadContext context, IRubyObject self, String name, IRubyObject arg1, IRubyObject arg2) {
    CacheEntry entry = selfType != null ? selfType.searchWithCache(name) : CacheEntry.NULL_CACHE;
    DynamicMethod method = entry.method;
    if (methodMissing(method, caller)) {
        return callMethodMissing(context, self, name, method, arg1, arg2, block);
    }
    cache = new SuperTuple(name, entry);
    return method.call(context, self, selfType, name, arg1, arg2, block);
}