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

boolean org::codehaus::janino::UnitCompiler::isNarrowingReferenceConvertible ( IClass  sourceType,
IClass  targetType 
) throws CompileException [inline, private]

Check whether "narrowing reference conversion" (JLS 5.1.5) is possible.

Definition at line 7400 of file UnitCompiler.java.

References org::codehaus::janino::IClass::getComponentType(), org::codehaus::janino::IClass::isArray(), org::codehaus::janino::IClass::isAssignableFrom(), org::codehaus::janino::IClass::isFinal(), org::codehaus::janino::IClass::isInterface(), and org::codehaus::janino::IClass::isPrimitive().

                              {
        if (sourceType.isPrimitive()) return false;
        if (sourceType == targetType) return false;

        // 5.1.5.1
        if (sourceType.isAssignableFrom(targetType)) return true;

        // 5.1.5.2
        if (
            targetType.isInterface() &&
            !sourceType.isFinal() &&
            !targetType.isAssignableFrom(sourceType)
        ) return true;

        // 5.1.5.3
        if (
            sourceType == this.iClassLoader.OBJECT &&
            targetType.isArray()
        ) return true;

        // 5.1.5.4
        if (
            sourceType == this.iClassLoader.OBJECT &&
            targetType.isInterface()
        ) return true;

        // 5.1.5.5
        if (
            sourceType.isInterface() &&
            !targetType.isFinal()
        ) return true;

        // 5.1.5.6
        if (
            sourceType.isInterface() &&
            targetType.isFinal() &&
            sourceType.isAssignableFrom(targetType)
        ) return true;

        // 5.1.5.7
        // TODO: Check for redefinition of methods with same signature but different return type.
        if (
            sourceType.isInterface() &&
            targetType.isInterface() &&
            !targetType.isAssignableFrom(sourceType)
        ) return true;

        // 5.1.5.8
        if (sourceType.isArray() && targetType.isArray()) {
            IClass st = sourceType.getComponentType();
            IClass tt = targetType.getComponentType();
            if (
                this.isNarrowingPrimitiveConvertible(st, tt) ||
                this.isNarrowingReferenceConvertible(st, tt)
            ) return true;
        }

        return false;
    }


Generated by  Doxygen 1.6.0   Back to index