Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jruby.java.proxies;
 
 import org.jruby.Ruby;
A shim class created when constructing primitive arrays from proxied Java classes. In the following code: Java::byte[50].new The [50] call produces an instance of ArrayJavaProxyCreator. The [] method can be called with any number of integer arguments to create a multi-dimensional array creator, or calls to [] can be chained for the same effect. The eventual call to new is against the ArrayJavaProxyCreator instance, and the result is a wrapped Java array of the specified dimensions and element type of the original receiver (the byte class, above).
public class ArrayJavaProxyCreator extends RubyObject {
    private static final int[] EMPTY = new int[0];
    /* final */ Class<?> elementType;
    int[] dimensions = ;
    public static RubyClass createArrayJavaProxyCreator(ThreadContext context) {
        Ruby runtime = context.runtime;
        RubyClass arrayJavaProxyCreator = runtime.defineClass("ArrayJavaProxyCreator"runtime.getObject(), .);
        arrayJavaProxyCreator.defineAnnotatedMethods(ArrayJavaProxyCreator.class);
        return arrayJavaProxyCreator;
    }
    @Deprecated
    public ArrayJavaProxyCreator(final Ruby runtime) {
        super(runtimeruntime.getJavaSupport().getArrayJavaProxyCreatorClass());
    }
    ArrayJavaProxyCreator(final ThreadContext contextJavaClass elementTypefinal IRubyObject[] sizes) {
        this(context.runtime);
        this. = elementType.javaClass();
        assert sizes.length > 0;
        aggregateDimensions(sizes);
    }
    @Deprecated // no longer used
    public void setup(ThreadContext contextIRubyObject javaClassIRubyObject[] sizes) {
         = (ClassjavaClass.toJava(Class.class);
        aggregateDimensions(sizes);
    }
    @JRubyMethod(name = "[]", required = 1, rest = true)
    public IRubyObject op_aref(ThreadContext contextIRubyObject[] sizes) {
        Arity.checkArgumentCount(context.runtimesizes, 1, -1);
        aggregateDimensions(sizes);
        return this;
    }
    @JRubyMethod(name = { "new""new_instance" })
    public final ArrayJavaProxy new_instance(ThreadContext context) {
        return ArrayJavaProxy.newArray(context.runtime);
    }
    private void aggregateDimensions(final IRubyObject[] sizes) {
        final int slen = sizes.lengthif ( slen == 0 ) return;
        final int dlen = .;
        final int[] newDimensions = new intdlen + slen ];
        if ( dlen == 1 ) newDimensions[0] = [0];
        else {
            System.arraycopy(, 0, newDimensions, 0, dlen);
        }
        for ( int i = 0; i < sleni++ ) {
            int size = (intsizes[i].convertToInteger().getLongValue();
            newDimensionsi + dlen ] = size;
        }
         = newDimensions;
    }
New to GrepCode? Check out our FAQ X