Logo Search packages:      
Sourcecode: janino version File versions  Download package

IClass org::codehaus::janino::UnitCompiler::newArray ( Locatable  l,
int  dimExprCount,
int  dims,
IClass  componentType 
) [inline, private]

Expects "dimExprCount" values of type "integer" on the operand stack. Creates an array of "dimExprCount" + "dims" dimensions of "componentType".

Returns:
The type of the created array

Definition at line 8076 of file UnitCompiler.java.

References org::codehaus::janino::IClass::BOOLEAN, org::codehaus::janino::IClass::BYTE, org::codehaus::janino::IClass::CHAR, org::codehaus::janino::IClass::DOUBLE, org::codehaus::janino::IClass::FLOAT, org::codehaus::janino::IClass::getArrayIClass(), org::codehaus::janino::IClass::getDescriptor(), org::codehaus::janino::IClass::INT, org::codehaus::janino::IClass::isPrimitive(), org::codehaus::janino::IClass::LONG, and org::codehaus::janino::IClass::SHORT.

      {
        if (dimExprCount == 1 && dims == 0 && componentType.isPrimitive()) {

            // "new <primitive>[<n>]"
            this.writeOpcode(l, Opcode.NEWARRAY);
            this.writeByte((
                componentType == IClass.BOOLEAN ? 4 :
                componentType == IClass.CHAR    ? 5 :
                componentType == IClass.FLOAT   ? 6 :
                componentType == IClass.DOUBLE  ? 7 :
                componentType == IClass.BYTE    ? 8 :
                componentType == IClass.SHORT   ? 9 :
                componentType == IClass.INT     ? 10 :
                componentType == IClass.LONG    ? 11 : -1
            ));
            return componentType.getArrayIClass(this.iClassLoader.OBJECT);
        }

        if (dimExprCount == 1) {
            IClass at = componentType.getArrayIClass(dims, this.iClassLoader.OBJECT);

            // "new <class-or-interface>[<n>]"
            // "new <anything>[<n>][]..."
            this.writeOpcode(l, Opcode.ANEWARRAY);
            this.writeConstantClassInfo(at.getDescriptor());
            return at.getArrayIClass(this.iClassLoader.OBJECT);
        } else {
            IClass at = componentType.getArrayIClass(dimExprCount + dims, this.iClassLoader.OBJECT);

            // "new <anything>[]..."
            // "new <anything>[<n>][<m>]..."
            // "new <anything>[<n>][<m>]...[]..."
            this.writeOpcode(l, Opcode.MULTIANEWARRAY);
            this.writeConstantClassInfo(at.getDescriptor());
            this.writeByte(dimExprCount);
            return at;
        }
    }


Generated by  Doxygen 1.6.0   Back to index