List of usage examples for org.eclipse.jdt.internal.compiler.lookup BaseTypeBinding isWidening
public static final boolean isWidening(int left, int right)
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.PotentialTranslationExpression.java
License:Open Source License
/** * Check whether rawType is already compatible perhaps using basic type conversion * @param scope//from ww w .ja v a 2 s . com * @param rawType * @return the compatible type */ protected TypeBinding compatibleType(BlockScope scope, TypeBinding rawType) { // save and reset flags: Config oldConfig = Config.createOrResetConfig(this); try { if (areTypesCompatible(rawType, this.expectedType)) { if (!Config.requireTypeAdjustment()) { // TODO (SH) is conversion of arrays of base type allowed? TypeBinding resultType = this.resolvedType; // default if (this.resolvedType.isBaseType()) { if (TypeBinding.notEquals(rawType, this.expectedType)) { this.rawExpression = this.expression; this.rawExpression.computeConversion(scope, rawType, rawType); // null conversion. this.expression = new CastExpression(this.expression, TypeReference.baseTypeReference(this.expectedType.id, 0, null)); this.expression.constant = Constant.NotAConstant; ((CastExpression) this.expression).checkCastTypesCompatibility(scope, this.expectedType, rawType, this.expression); this.operator = "(convert to " + new String(this.expectedType.readableName()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ resultType = this.expectedType; } } if (BaseTypeBinding.isWidening(this.expectedType.id, rawType.id) && this.expression.constant != Constant.NotAConstant) this.expression.computeConversion(scope, this.expectedType, rawType); return resultType; } } } finally { // restore on any exit: Config.removeOrRestore(oldConfig, this); } return null; }