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

boolean org::codehaus::janino::UnitCompiler::tryConstantAssignmentConversion ( Locatable  l,
Object  constantValue,
IClass  targetType 
) throws CompileException [inline, private]

Check if "constant assignment conversion" (JLS 5.2, paragraph 1) is possible.

Parameters:
constantValue The constant value that is to be converted
targetType The type to convert to

Definition at line 7352 of file UnitCompiler.java.

References org::codehaus::janino::IClassLoader::BYTE, org::codehaus::janino::IClass::BYTE, org::codehaus::janino::IClass::CHAR, org::codehaus::janino::IClassLoader::CHARACTER, org::codehaus::janino::IClassLoader::SHORT, and org::codehaus::janino::IClass::SHORT.

                              {
        if (UnitCompiler.DEBUG) System.out.println("isConstantPrimitiveAssignmentConvertible(" + constantValue + ", " + targetType + ")");

        int cv;
        if (constantValue instanceof Byte) {
            cv = ((Byte) constantValue).byteValue();
        } else
        if (constantValue instanceof Short) {
            cv = ((Short) constantValue).shortValue();
        } else
        if (constantValue instanceof Integer) {
            cv = ((Integer) constantValue).intValue();
        } else
        if (constantValue instanceof Character) {
            cv = ((Character) constantValue).charValue();
        } else
        {
            return false;
        }

        if (targetType == IClass.BYTE ) return cv >= Byte.MIN_VALUE && cv <= Byte.MAX_VALUE;
        if (targetType == IClass.SHORT) return cv >= Short.MIN_VALUE && cv <= Short.MAX_VALUE;
        if (targetType == IClass.CHAR ) return cv >= Character.MIN_VALUE && cv <= Character.MAX_VALUE;

        IClassLoader icl = this.iClassLoader;
        if (targetType == icl.BYTE && cv >= Byte.MIN_VALUE && cv <= Byte.MAX_VALUE) {
            this.boxingConversion(l, IClass.BYTE, targetType);
            return true;
        }
        if (targetType == icl.SHORT && cv >= Short.MIN_VALUE && cv <= Short.MAX_VALUE) {
            this.boxingConversion(l, IClass.SHORT, targetType);
            return true;
        }
        if (targetType == icl.CHARACTER && cv >= Character.MIN_VALUE && cv <= Character.MAX_VALUE) {
            this.boxingConversion(l, IClass.CHAR, targetType);
            return true;
        }

        return false;
    }


Generated by  Doxygen 1.6.0   Back to index