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

void org::codehaus::janino::UnitCompiler::assignmentConversion ( Locatable  l,
IClass  sourceType,
IClass  targetType,
Object  optionalConstantValue 
) throws CompileException [inline, private]

Implements "assignment conversion" (JLS2 5.2).

Definition at line 6824 of file UnitCompiler.java.

                              {
        if (UnitCompiler.DEBUG) System.out.println("assignmentConversion(" + sourceType + ", " + targetType + ", " + optionalConstantValue + ")");

        // JLS2 5.1.1 Identity conversion.
        if (this.tryIdentityConversion(sourceType, targetType)) return;

        // JLS2 5.1.2 Widening primitive conversion.
        if (this.tryWideningPrimitiveConversion(l, sourceType, targetType)) return;

        // JLS2 5.1.4 Widening reference conversion.
        if (this.isWideningReferenceConvertible(sourceType, targetType)) return;

        // A boxing conversion (JLS3 5.1.7) optionally followed by a widening reference conversion.
        {
            IClass boxedType = this.isBoxingConvertible(sourceType);
            if (boxedType != null) {
                if (this.tryIdentityConversion(boxedType, targetType)) {
                    this.boxingConversion(l, sourceType, boxedType);
                    return;
                } else
                if (this.isWideningReferenceConvertible(boxedType, targetType)) {
                    this.boxingConversion(l, sourceType, boxedType);
                    return;
                }
            }
        }

        // An unboxing conversion (JLS3 5.1.8) optionally followed by a widening primitive conversion.
        {
            IClass unboxedType = this.isUnboxingConvertible(sourceType);
            if (unboxedType != null) {
                if (this.tryIdentityConversion(unboxedType, targetType)) {
                    this.unboxingConversion(l, sourceType, unboxedType);
                    return;
                } else
                if (this.isWideningPrimitiveConvertible(unboxedType, targetType)) {
                    this.unboxingConversion(l, sourceType, unboxedType);
                    this.tryWideningPrimitiveConversion(l, unboxedType, targetType);
                    return;
                }
            }
        }

        // 5.2 Special narrowing primitive conversion.
        if (optionalConstantValue != null) {
            if (this.tryConstantAssignmentConversion(
                l,
                optionalConstantValue, // constantValue
                targetType             // targetType
            )) return;
        }

        this.compileError("Assignment conversion not possible from type \"" + sourceType + "\" to type \"" + targetType + "\"", l.getLocation());
    }


Generated by  Doxygen 1.6.0   Back to index