Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jruby.ext.ffi;
 
 import org.jruby.Ruby;
 
 import java.util.Map;
public final class TypeResolver {
    private final FFI ffi;
    private volatile Map<RubySymbolTypesymbolTypeCache = Collections.emptyMap();
    TypeResolver(FFI ffi) {
        this. = ffi;
    }
    public final Type findType(Ruby runtimeIRubyObject name) {
        if (name instanceof Type) {
            return (Typename;
        } else if (name instanceof RubySymbol) {
            return findType(runtime, (RubySymbolname);
        } else {
            return lookupType(runtimename);
        }
    }
    public final Type findType(Ruby runtimeRubySymbol name) {
        Object obj = name.getFFIHandle();
        if (obj instanceof Type) {
            return ((Typeobj);
        }
        Type type = .get(name);
        if (type != null) {
            return type;
        }
        return lookupAndCacheType(runtimename);
    }
    
    private synchronized Type lookupAndCacheType(Ruby runtimeRubySymbol name) {
        Type type = lookupType(runtimename);
        Map<RubySymbolTypemap = new IdentityHashMap<RubySymbolType>();
        map.put(nametype);
         = map;
        name.setFFIHandle(type);
        return type;
    }
    private Type lookupType(Ruby runtimeIRubyObject name) {
        IRubyObject type = ..fastARef(name);
        if (type instanceof Type) {
            return (Typetype;
        }
        if ((type = ..callMethod(runtime.getCurrentContext(), "find_type"name)) instanceof Type) {
            return (Typetype;
        }
        throw runtime.newTypeError("cannot resolve type " + name);
    }
New to GrepCode? Check out our FAQ X