Example usage for org.eclipse.jdt.internal.compiler.lookup TypeBinding needsUncheckedConversion

List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding needsUncheckedConversion

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup TypeBinding needsUncheckedConversion.

Prototype

public boolean needsUncheckedConversion(TypeBinding targetType) 

Source Link

Document

Meant to be invoked on compatible types, to figure if unchecked conversion is necessary

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.CalloutMappingDeclaration.java

License:Open Source License

/**
 * Only one check needs to be performed for callout-to-field:
 * @param fieldSpec// www  . j  av  a2  s . co m
 */
protected void checkTypeCompatibility(FieldAccessSpec fieldSpec) {
    // make sure roleMethodSpec has a returnType, because that is going to be updated below:
    if (this.roleMethodSpec.returnType == null) {
        AstGenerator gen = new AstGenerator(this.roleMethodSpec.sourceStart, this.roleMethodSpec.sourceEnd);
        this.roleMethodSpec.returnType = gen.typeReference(this.roleMethodSpec.resolvedType());
    }

    TypeBinding requiredType = null;
    TypeBinding providedType = null;

    if (fieldSpec.calloutModifier == TokenNameget) {
        requiredType = this.roleMethodSpec.resolvedType();
        providedType = fieldSpec.resolvedType();
        if (providedType.isCompatibleWith(requiredType)) {
            if (this.roleMethodSpec.returnType.resolvedType == null)
                this.roleMethodSpec.returnType.resolvedType = requiredType; // need a valid type here
            if (providedType.needsUncheckedConversion(requiredType))
                this.scope.problemReporter().unsafeTypeConversion(fieldSpec, providedType, requiredType);
            return; // OK => done
        } else {
            TypeBinding roleToLiftTo = TeamModel.getRoleToLiftTo(this.scope, providedType, requiredType, false,
                    fieldSpec);
            if (roleToLiftTo != null) {
                // success by translation
                this.roleMethodSpec.returnNeedsTranslation = true;
                this.roleMethodSpec.returnType.resolvedType = roleToLiftTo; // instantiated.
                return; // OK => done.
            }
            if (requiredType == TypeBinding.VOID) {
                this.scope.problemReporter().fieldAccessHasNoEffect(this.roleMethodSpec, fieldSpec);
                this.roleMethodSpec.returnType.resolvedType = requiredType; // keep going..
                return; // warned
            }
            if (this.roleMethodSpec.returnType.resolvedType == null) {
                // https://bugs.eclipse.org/387236
                // if returnType was added late (above) and if type mismatch exists, we still need a resolved type here:
                this.roleMethodSpec.returnType.resolve(this.scope);
            }
        }
    } else { // 'set'
        if (this.roleMethodSpec.resolvedMethod.returnType != TypeBinding.VOID) {
            this.scope.problemReporter().calloutSetCantReturn(this.roleMethodSpec);
            this.binding.tagBits |= TagBits.HasMappingIncompatibility;
        }
        this.roleMethodSpec.returnType.resolvedType = TypeBinding.VOID;
        TypeBinding[] params = this.roleMethodSpec.resolvedMethod.parameters;
        if (params == null || params.length == 0) {
            this.scope.problemReporter().calloutToFieldMissingParameter(this.roleMethodSpec, fieldSpec);
            this.binding.tagBits |= TagBits.HasMappingIncompatibility;
            return; // don't report more problems
        }
        providedType = params[0];
        requiredType = fieldSpec.resolvedType();
        if (providedType.isCompatibleWith(requiredType)) {
            if (providedType.needsUncheckedConversion(requiredType))
                this.scope.problemReporter().unsafeTypeConversion(this.roleMethodSpec, providedType,
                        requiredType);
            return;
        }
    }
    // fall through in any case of incompatibility:
    this.scope.problemReporter().calloutIncompatibleFieldType(this.roleMethodSpec, fieldSpec, requiredType,
            providedType);
    this.binding.tagBits |= TagBits.HasMappingIncompatibility;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.PotentialTranslationExpression.java

License:Open Source License

protected void checkOtherConversions(BlockScope scope, TypeBinding requiredType, TypeBinding providedType) {
    // copied and adjusted from ReturnStatement.resolve()
    this.expression.computeConversion(scope, requiredType, providedType);
    if (providedType.needsUncheckedConversion(requiredType)) {
        scope.problemReporter().unsafeTypeConversion(this.expression, requiredType, providedType);
    }//from ww w.  j  a  va 2  s . co  m
    if (this.expression instanceof CastExpression
            && (this.expression.bits & (ASTNode.UnnecessaryCast | ASTNode.DisableUnnecessaryCastCheck)) == 0) {
        CastExpression.checkNeedForAssignedCast(scope, providedType, (CastExpression) this.expression);
    }
}