Java Code Examples for org.eclipse.jdt.internal.compiler.impl.Constant#NotAConstant
The following examples show how to use
org.eclipse.jdt.internal.compiler.impl.Constant#NotAConstant .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultBindingResolver.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
Object resolveConstantExpressionValue(Expression expression) { org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression); if (node instanceof org.eclipse.jdt.internal.compiler.ast.Expression) { org.eclipse.jdt.internal.compiler.ast.Expression compilerExpression = (org.eclipse.jdt.internal.compiler.ast.Expression) node; Constant constant = compilerExpression.constant; if (constant != null && constant != Constant.NotAConstant) { switch (constant.typeID()) { case TypeIds.T_int : return new Integer(constant.intValue()); case TypeIds.T_byte : return new Byte(constant.byteValue()); case TypeIds.T_short : return new Short(constant.shortValue()); case TypeIds.T_char : return new Character(constant.charValue()); case TypeIds.T_float : return new Float(constant.floatValue()); case TypeIds.T_double : return new Double(constant.doubleValue()); case TypeIds.T_boolean : return constant.booleanValue() ? Boolean.TRUE : Boolean.FALSE; case TypeIds.T_long : return new Long(constant.longValue()); case TypeIds.T_JavaLangString : return constant.stringValue(); } return null; } } return null; }
Example 2
Source File: ArrayReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public TypeBinding resolveType(BlockScope scope) { this.constant = Constant.NotAConstant; if (this.receiver instanceof CastExpression // no cast check for ((type[])null)[0] && ((CastExpression)this.receiver).innermostCastedExpression() instanceof NullLiteral) { this.receiver.bits |= ASTNode.DisableUnnecessaryCastCheck; // will check later on } TypeBinding arrayType = this.receiver.resolveType(scope); if (arrayType != null) { this.receiver.computeConversion(scope, arrayType, arrayType); if (arrayType.isArrayType()) { TypeBinding elementType = ((ArrayBinding) arrayType).elementsType(); this.resolvedType = ((this.bits & ASTNode.IsStrictlyAssigned) == 0) ? elementType.capture(scope, this.sourceEnd) : elementType; } else { scope.problemReporter().referenceMustBeArrayTypeAt(arrayType, this); } } TypeBinding positionType = this.position.resolveTypeExpecting(scope, TypeBinding.INT); if (positionType != null) { this.position.computeConversion(scope, TypeBinding.INT, positionType); } return this.resolvedType; }
Example 3
Source File: InstanceOfExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public TypeBinding resolveType(BlockScope scope) { this.constant = Constant.NotAConstant; TypeBinding expressionType = this.expression.resolveType(scope); TypeBinding checkedType = this.type.resolveType(scope, true /* check bounds*/); if (expressionType != null && checkedType != null && checkedType.hasNullTypeAnnotations()) { // don't complain if the entire operation is redundant anyway if (!expressionType.isCompatibleWith(checkedType) || NullAnnotationMatching.analyse(checkedType, expressionType, -1).isAnyMismatch()) scope.problemReporter().nullAnnotationUnsupportedLocation(this.type); } if (expressionType == null || checkedType == null) return null; if (!checkedType.isReifiable()) { scope.problemReporter().illegalInstanceOfGenericType(checkedType, this); } else if (checkedType.isValidBinding()) { // if not a valid binding, an error has already been reported for unresolved type if ((expressionType != TypeBinding.NULL && expressionType.isBaseType()) // disallow autoboxing || !checkCastTypesCompatibility(scope, checkedType, expressionType, null)) { scope.problemReporter().notCompatibleTypesError(this, expressionType, checkedType); } } return this.resolvedType = TypeBinding.BOOLEAN; }
Example 4
Source File: CodeSnippetSingleNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo, boolean isReadAccess) { if (this.delegateThis == null) { super.manageSyntheticAccessIfNecessary(currentScope, flowInfo, isReadAccess); return; } if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0) return; //If inlinable field, forget the access emulation, the code gen will directly target it if (this.constant != Constant.NotAConstant) return; // if field from parameterized type got found, use the original field at codegen time if (this.binding instanceof ParameterizedFieldBinding) { ParameterizedFieldBinding parameterizedField = (ParameterizedFieldBinding) this.binding; FieldBinding codegenField = parameterizedField.originalField; // extra cast needed if field type was type variable if ((codegenField.type.tagBits & TagBits.HasTypeVariable) != 0) { this.genericCast = codegenField.type.genericCast(currentScope.boxing(parameterizedField.type)); // runtimeType could be base type in boxing case } } }
Example 5
Source File: FieldReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public Constant optimizedBooleanConstant() { switch (this.resolvedType.id) { case T_boolean : case T_JavaLangBoolean : return this.constant != Constant.NotAConstant ? this.constant : this.binding.constant(); default : return Constant.NotAConstant; } }
Example 6
Source File: UnconditionalFlowInfo.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
final public boolean isDefinitelyNonNull(LocalVariableBinding local) { // do not want to complain in unreachable code if ((this.tagBits & UNREACHABLE) != 0 || (this.tagBits & NULL_FLAG_MASK) == 0) { return false; } if ((local.type.tagBits & TagBits.IsBaseType) != 0 || local.constant() != Constant.NotAConstant) { // String instances return true; } int position = local.id + this.maxFieldCount; if (position < BitCacheSize) { // use bits return ((this.nullBit1 & this.nullBit3 & (~this.nullBit2 | this.nullBit4)) & (1L << position)) != 0; } // use extra vector if (this.extra == null) { return false; // if vector not yet allocated, then not initialized } int vectorIndex; if ((vectorIndex = (position / BitCacheSize) - 1) >= this.extra[2].length) { return false; // if not enough room in vector, then not initialized } return ((this.extra[2][vectorIndex] & this.extra[4][vectorIndex] & (~this.extra[3][vectorIndex] | this.extra[5][vectorIndex])) & (1L << (position % BitCacheSize))) != 0; }
Example 7
Source File: Expression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public boolean isConstantValueOfTypeAssignableToType(TypeBinding constantType, TypeBinding targetType) { if (this.constant == Constant.NotAConstant) return false; if (TypeBinding.equalsEquals(constantType, targetType)) return true; //No free assignment conversion from anything but to integral ones. if (BaseTypeBinding.isWidening(TypeIds.T_int, constantType.id) && (BaseTypeBinding.isNarrowing(targetType.id, TypeIds.T_int))) { //use current explicit conversion in order to get some new value to compare with current one return isConstantValueRepresentable(this.constant, constantType.id, targetType.id); } return false; }
Example 8
Source File: SuperReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public TypeBinding resolveType(BlockScope scope) { this.constant = Constant.NotAConstant; ReferenceBinding enclosingReceiverType = scope.enclosingReceiverType(); if (!checkAccess(scope, enclosingReceiverType)) return null; if (enclosingReceiverType.id == T_JavaLangObject) { scope.problemReporter().cannotUseSuperInJavaLangObject(this); return null; } return this.resolvedType = enclosingReceiverType.superclass(); }
Example 9
Source File: CastExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Cast expression code generation * * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream * @param valueRequired boolean */ public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { int pc = codeStream.position; boolean annotatedCast = (this.type.bits & ASTNode.HasTypeAnnotations) != 0; boolean needRuntimeCheckcast = (this.bits & ASTNode.GenerateCheckcast) != 0; if (this.constant != Constant.NotAConstant) { if (valueRequired || needRuntimeCheckcast || annotatedCast) { // Added for: 1F1W9IG: IVJCOM:WINNT - Compiler omits casting check codeStream.generateConstant(this.constant, this.implicitConversion); if (needRuntimeCheckcast || annotatedCast) { codeStream.checkcast(this.type, this.resolvedType); } if (!valueRequired) { // the resolveType cannot be double or long codeStream.pop(); } } codeStream.recordPositionsFrom(pc, this.sourceStart); return; } this.expression.generateCode(currentScope, codeStream, annotatedCast || valueRequired || needRuntimeCheckcast); if (annotatedCast || (needRuntimeCheckcast && TypeBinding.notEquals(this.expression.postConversionType(currentScope), this.resolvedType.erasure()))) { // no need to issue a checkcast if already done as genericCast codeStream.checkcast(this.type, this.resolvedType); } if (valueRequired) { codeStream.generateImplicitConversion(this.implicitConversion); } else if (needRuntimeCheckcast) { boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0; switch (isUnboxing ? postConversionType(currentScope).id : this.resolvedType.id) { case T_long : case T_double : codeStream.pop2(); break; default : codeStream.pop(); break; } } codeStream.recordPositionsFrom(pc, this.sourceStart); }
Example 10
Source File: Expression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void generateOptimizedStringConcatenationCreation(BlockScope blockScope, CodeStream codeStream, int typeID) { codeStream.newStringContatenation(); codeStream.dup(); switch (typeID) { case T_JavaLangObject : case T_undefined : // in the case the runtime value of valueOf(Object) returns null, we have to use append(Object) instead of directly valueOf(Object) // append(Object) returns append(valueOf(Object)), which means that the null case is handled by the next case. codeStream.invokeStringConcatenationDefaultConstructor(); generateCode(blockScope, codeStream, true); codeStream.invokeStringConcatenationAppendForType(TypeIds.T_JavaLangObject); return; case T_JavaLangString : case T_null : if (this.constant != Constant.NotAConstant) { String stringValue = this.constant.stringValue(); if (stringValue.length() == 0) { // optimize ""+<str> codeStream.invokeStringConcatenationDefaultConstructor(); return; } codeStream.ldc(stringValue); } else { // null case is not a constant generateCode(blockScope, codeStream, true); codeStream.invokeStringValueOf(TypeIds.T_JavaLangObject); } break; default : generateCode(blockScope, codeStream, true); codeStream.invokeStringValueOf(typeID); } codeStream.invokeStringConcatenationStringConstructor(); }
Example 11
Source File: Expression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns an object which can be used to identify identical JSR sequence targets * (see TryStatement subroutine codegen) * or <code>null</null> if not reusable */ public Object reusableJSRTarget() { if (this.constant != Constant.NotAConstant && (this.implicitConversion & TypeIds.BOXING) == 0) { return this.constant; } return null; }
Example 12
Source File: FieldBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public Constant constant() { Constant fieldConstant = this.constant; if (fieldConstant == null) { if (isFinal()) { //The field has not been yet type checked. //It also means that the field is not coming from a class that //has already been compiled. It can only be from a class within //compilation units to process. Thus the field is NOT from a BinaryTypeBinbing FieldBinding originalField = original(); if (originalField.declaringClass instanceof SourceTypeBinding) { SourceTypeBinding sourceType = (SourceTypeBinding) originalField.declaringClass; if (sourceType.scope != null) { TypeDeclaration typeDecl = sourceType.scope.referenceContext; FieldDeclaration fieldDecl = typeDecl.declarationOf(originalField); MethodScope initScope = originalField.isStatic() ? typeDecl.staticInitializerScope : typeDecl.initializerScope; boolean old = initScope.insideTypeAnnotation; try { initScope.insideTypeAnnotation = false; fieldDecl.resolve(initScope); //side effect on binding } finally { initScope.insideTypeAnnotation = old; } fieldConstant = originalField.constant == null ? Constant.NotAConstant : originalField.constant; } else { fieldConstant = Constant.NotAConstant; // shouldn't occur per construction (paranoid null check) } } else { fieldConstant = Constant.NotAConstant; // shouldn't occur per construction (paranoid null check) } } else { fieldConstant = Constant.NotAConstant; } this.constant = fieldConstant; } return fieldConstant; }
Example 13
Source File: QualifiedNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { int pc = codeStream.position; if (this.constant != Constant.NotAConstant) { if (valueRequired) { codeStream.generateConstant(this.constant, this.implicitConversion); } } else { FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream); if (lastFieldBinding != null) { boolean isStatic = lastFieldBinding.isStatic(); Constant fieldConstant = lastFieldBinding.constant(); if (fieldConstant != Constant.NotAConstant) { if (!isStatic){ codeStream.invokeObjectGetClass(); codeStream.pop(); } if (valueRequired) { // inline the last field constant codeStream.generateConstant(fieldConstant, this.implicitConversion); } } else { boolean isFirst = lastFieldBinding == this.binding && (this.indexOfFirstFieldBinding == 1 || TypeBinding.equalsEquals(lastFieldBinding.declaringClass, currentScope.enclosingReceiverType())) && this.otherBindings == null; // could be dup: next.next.next TypeBinding requiredGenericCast = getGenericCast(this.otherBindings == null ? 0 : this.otherBindings.length); if (valueRequired || (!isFirst && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) || ((this.implicitConversion & TypeIds.UNBOXING) != 0) || requiredGenericCast != null) { int lastFieldPc = codeStream.position; if (lastFieldBinding.declaringClass == null) { // array length codeStream.arraylength(); if (valueRequired) { codeStream.generateImplicitConversion(this.implicitConversion); } else { // could occur if !valueRequired but compliance >= 1.4 codeStream.pop(); } } else { SyntheticMethodBinding accessor = this.syntheticReadAccessors == null ? null : this.syntheticReadAccessors[this.syntheticReadAccessors.length - 1]; if (accessor == null) { TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, lastFieldBinding, getFinalReceiverType(), isFirst); if (isStatic) { codeStream.fieldAccess(Opcodes.OPC_getstatic, lastFieldBinding, constantPoolDeclaringClass); } else { codeStream.fieldAccess(Opcodes.OPC_getfield, lastFieldBinding, constantPoolDeclaringClass); } } else { codeStream.invoke(Opcodes.OPC_invokestatic, accessor, null /* default declaringClass */); } if (requiredGenericCast != null) codeStream.checkcast(requiredGenericCast); if (valueRequired) { codeStream.generateImplicitConversion(this.implicitConversion); } else { boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0; // conversion only generated if unboxing if (isUnboxing) codeStream.generateImplicitConversion(this.implicitConversion); switch (isUnboxing ? postConversionType(currentScope).id : lastFieldBinding.type.id) { case T_long : case T_double : codeStream.pop2(); break; default : codeStream.pop(); break; } } } int fieldPosition = (int) (this.sourcePositions[this.sourcePositions.length - 1] >>> 32); codeStream.recordPositionsFrom(lastFieldPc, fieldPosition); } else { if (!isStatic){ codeStream.invokeObjectGetClass(); // perform null check codeStream.pop(); } } } } } codeStream.recordPositionsFrom(pc, this.sourceStart); }
Example 14
Source File: CodeSnippetFieldReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public TypeBinding resolveType(BlockScope scope) { // Answer the signature type of the field. // constants are propaged when the field is final // and initialized with a (compile time) constant // regular receiver reference this.actualReceiverType = this.receiver.resolveType(scope); if (this.actualReceiverType == null){ this.constant = Constant.NotAConstant; return null; } // the case receiverType.isArrayType and token = 'length' is handled by the scope API this.binding = scope.getField(this.actualReceiverType, this.token, this); FieldBinding firstAttempt = this.binding; boolean isNotVisible = false; if (!this.binding.isValidBinding()) { if (this.binding instanceof ProblemFieldBinding && ((ProblemFieldBinding) this.binding).problemId() == NotVisible) { isNotVisible = true; if (this.evaluationContext.declaringTypeName != null) { this.delegateThis = scope.getField(scope.enclosingSourceType(), DELEGATE_THIS, this); if (this.delegateThis == null){ // if not found then internal error, field should have been found this.constant = Constant.NotAConstant; scope.problemReporter().invalidField(this, this.actualReceiverType); return null; } this.actualReceiverType = this.delegateThis.type; } else { this.constant = Constant.NotAConstant; scope.problemReporter().invalidField(this, this.actualReceiverType); return null; } CodeSnippetScope localScope = new CodeSnippetScope(scope); this.binding = localScope.getFieldForCodeSnippet(this.delegateThis.type, this.token, this); } } if (!this.binding.isValidBinding()) { this.constant = Constant.NotAConstant; if (isNotVisible) { this.binding = firstAttempt; } scope.problemReporter().invalidField(this, this.actualReceiverType); return null; } if (isFieldUseDeprecated(this.binding, scope, this.bits)) { scope.problemReporter().deprecatedField(this.binding, this); } // check for this.x in static is done in the resolution of the receiver this.constant = this.receiver.isImplicitThis() ? this.binding.constant() : Constant.NotAConstant; if (!this.receiver.isThis()) { // TODO need to check if shouldn't be isImplicitThis check (and then removed) this.constant = Constant.NotAConstant; } return this.resolvedType = this.binding.type; }
Example 15
Source File: CastExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public TypeBinding resolveType(BlockScope scope) { // compute a new constant if the cast is effective this.constant = Constant.NotAConstant; this.implicitConversion = TypeIds.T_undefined; boolean exprContainCast = false; TypeBinding castType = this.resolvedType = this.type.resolveType(scope); if (scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8) { this.expression.setExpressionContext(CASTING_CONTEXT); if (this.expression instanceof FunctionalExpression) { this.expression.setExpectedType(this.resolvedType); this.bits |= ASTNode.DisableUnnecessaryCastCheck; } } if (this.expression instanceof CastExpression) { this.expression.bits |= ASTNode.DisableUnnecessaryCastCheck; exprContainCast = true; } TypeBinding expressionType = this.expression.resolveType(scope); if (this.expression instanceof MessageSend) { MessageSend messageSend = (MessageSend) this.expression; MethodBinding methodBinding = messageSend.binding; if (methodBinding != null && methodBinding.isPolymorphic()) { messageSend.binding = scope.environment().updatePolymorphicMethodReturnType((PolymorphicMethodBinding) methodBinding, castType); if (TypeBinding.notEquals(expressionType, castType)) { expressionType = castType; this.bits |= ASTNode.DisableUnnecessaryCastCheck; } } } if (castType != null) { if (expressionType != null) { boolean nullAnnotationMismatch = scope.compilerOptions().isAnnotationBasedNullAnalysisEnabled && NullAnnotationMatching.analyse(castType, expressionType, -1).isAnyMismatch(); boolean isLegal = checkCastTypesCompatibility(scope, castType, expressionType, this.expression); if (isLegal) { this.expression.computeConversion(scope, castType, expressionType); if ((this.bits & ASTNode.UnsafeCast) != 0) { // unsafe cast if (scope.compilerOptions().reportUnavoidableGenericTypeProblems || !(expressionType.isRawType() && this.expression.forcedToBeRaw(scope.referenceContext()))) { scope.problemReporter().unsafeCast(this, scope); } } else if (nullAnnotationMismatch) { // report null annotation issue at medium priority scope.problemReporter().unsafeNullnessCast(this, scope); } else { if (castType.isRawType() && scope.compilerOptions().getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore){ scope.problemReporter().rawTypeReference(this.type, castType); } if ((this.bits & (ASTNode.UnnecessaryCast|ASTNode.DisableUnnecessaryCastCheck)) == ASTNode.UnnecessaryCast) { // unnecessary cast if (!isIndirectlyUsed()) // used for generic type inference or boxing ? scope.problemReporter().unnecessaryCast(this); } } } else { // illegal cast if ((castType.tagBits & TagBits.HasMissingType) == 0) { // no complaint if secondary error scope.problemReporter().typeCastError(this, castType, expressionType); } this.bits |= ASTNode.DisableUnnecessaryCastCheck; // disable further secondary diagnosis } } this.resolvedType = castType.capture(scope, this.sourceEnd); if (exprContainCast) { checkNeedForCastCast(scope, this); } } return this.resolvedType; }
Example 16
Source File: LocalVariableBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public LocalVariableBinding(char[] name, TypeBinding type, int modifiers, boolean isArgument) { super(name, type, modifiers, isArgument ? Constant.NotAConstant : null); if (isArgument) this.tagBits |= TagBits.IsArgument; this.tagBits |= TagBits.IsEffectivelyFinal; }
Example 17
Source File: Assignment.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public TypeBinding resolveType(BlockScope scope) { // due to syntax lhs may be only a NameReference, a FieldReference or an ArrayReference this.constant = Constant.NotAConstant; if (!(this.lhs instanceof Reference) || this.lhs.isThis()) { scope.problemReporter().expressionShouldBeAVariable(this.lhs); return null; } TypeBinding lhsType = this.lhs.resolveType(scope); this.expression.setExpressionContext(ASSIGNMENT_CONTEXT); this.expression.setExpectedType(lhsType); // needed in case of generic method invocation if (lhsType != null) { this.resolvedType = lhsType.capture(scope, this.sourceEnd); } LocalVariableBinding localVariableBinding = this.lhs.localVariableBinding(); if (localVariableBinding != null && (localVariableBinding.isCatchParameter() || localVariableBinding.isParameter())) { localVariableBinding.tagBits &= ~TagBits.IsEffectivelyFinal; // as it is already definitely assigned, we can conclude already. Also note: catch parameter cannot be compound assigned. } TypeBinding rhsType = this.expression.resolveType(scope); if (lhsType == null || rhsType == null) { return null; } // check for assignment with no effect Binding left = getDirectBinding(this.lhs); if (left != null && !left.isVolatile() && left == getDirectBinding(this.expression)) { scope.problemReporter().assignmentHasNoEffect(this, left.shortReadableName()); } // Compile-time conversion of base-types : implicit narrowing integer into byte/short/character // may require to widen the rhs expression at runtime if (TypeBinding.notEquals(lhsType, rhsType)) { // must call before computeConversion() and typeMismatchError() scope.compilationUnitScope().recordTypeConversion(lhsType, rhsType); } if (this.expression.isConstantValueOfTypeAssignableToType(rhsType, lhsType) || rhsType.isCompatibleWith(lhsType, scope)) { this.expression.computeConversion(scope, lhsType, rhsType); checkAssignment(scope, lhsType, rhsType); if (this.expression instanceof CastExpression && (this.expression.bits & ASTNode.UnnecessaryCast) == 0) { CastExpression.checkNeedForAssignedCast(scope, lhsType, (CastExpression) this.expression); } return this.resolvedType; } else if (isBoxingCompatible(rhsType, lhsType, this.expression, scope)) { this.expression.computeConversion(scope, lhsType, rhsType); if (this.expression instanceof CastExpression && (this.expression.bits & ASTNode.UnnecessaryCast) == 0) { CastExpression.checkNeedForAssignedCast(scope, lhsType, (CastExpression) this.expression); } return this.resolvedType; } scope.problemReporter().typeMismatchError(rhsType, lhsType, this.expression, this.lhs); return lhsType; }
Example 18
Source File: Expression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Base types need that the widening is explicitly done by the compiler using some bytecode like i2f. * Also check unsafe type operations. */ public void computeConversion(Scope scope, TypeBinding runtimeType, TypeBinding compileTimeType) { if (runtimeType == null || compileTimeType == null) return; if (this.implicitConversion != 0) return; // already set independently // it is possible for a Byte to be unboxed to a byte & then converted to an int // but it is not possible for a byte to become Byte & then assigned to an Integer, // or to become an int before boxed into an Integer if (runtimeType != TypeBinding.NULL && runtimeType.isBaseType()) { if (!compileTimeType.isBaseType()) { TypeBinding unboxedType = scope.environment().computeBoxingType(compileTimeType); this.implicitConversion = TypeIds.UNBOXING; scope.problemReporter().autoboxing(this, compileTimeType, runtimeType); compileTimeType = unboxedType; } } else if (compileTimeType != TypeBinding.NULL && compileTimeType.isBaseType()) { TypeBinding boxedType = scope.environment().computeBoxingType(runtimeType); if (TypeBinding.equalsEquals(boxedType, runtimeType)) // Object o = 12; boxedType = compileTimeType; this.implicitConversion = TypeIds.BOXING | (boxedType.id << 4) + compileTimeType.id; scope.problemReporter().autoboxing(this, compileTimeType, scope.environment().computeBoxingType(boxedType)); return; } else if (this.constant != Constant.NotAConstant && this.constant.typeID() != TypeIds.T_JavaLangString) { this.implicitConversion = TypeIds.BOXING; return; } int compileTimeTypeID, runtimeTypeID; if ((compileTimeTypeID = compileTimeType.id) >= TypeIds.T_LastWellKnownTypeId) { // e.g. ? extends String ==> String (103227); >= TypeIds.T_LastWellKnownTypeId implies TypeIds.NoId compileTimeTypeID = compileTimeType.erasure().id == TypeIds.T_JavaLangString ? TypeIds.T_JavaLangString : TypeIds.T_JavaLangObject; } else if (runtimeType.isPrimitiveType() && compileTimeType instanceof ReferenceBinding && !compileTimeType.isBoxedPrimitiveType()) { compileTimeTypeID = TypeIds.T_JavaLangObject; // treatment is the same as for jlO. } switch (runtimeTypeID = runtimeType.id) { case T_byte : case T_short : case T_char : if (compileTimeTypeID == TypeIds.T_JavaLangObject) { this.implicitConversion |= (runtimeTypeID << 4) + compileTimeTypeID; } else { this.implicitConversion |= (TypeIds.T_int << 4) + compileTimeTypeID; } break; case T_JavaLangString : case T_float : case T_boolean : case T_double : case T_int : //implicitConversion may result in i2i which will result in NO code gen case T_long : this.implicitConversion |= (runtimeTypeID << 4) + compileTimeTypeID; break; default : // regular object ref // if (compileTimeType.isRawType() && runtimeTimeType.isBoundParameterizedType()) { // scope.problemReporter().unsafeRawExpression(this, compileTimeType, runtimeTimeType); // } } }
Example 19
Source File: SourceTypeBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public FieldBinding addSyntheticFieldForAssert(BlockScope blockScope) { if (!isPrototype()) throw new IllegalStateException(); if (this.synthetics == null) this.synthetics = new HashMap[MAX_SYNTHETICS]; if (this.synthetics[SourceTypeBinding.FIELD_EMUL] == null) this.synthetics[SourceTypeBinding.FIELD_EMUL] = new HashMap(5); FieldBinding synthField = (FieldBinding) this.synthetics[SourceTypeBinding.FIELD_EMUL].get("assertionEmulation"); //$NON-NLS-1$ if (synthField == null) { synthField = new SyntheticFieldBinding( TypeConstants.SYNTHETIC_ASSERT_DISABLED, TypeBinding.BOOLEAN, (isInterface() ? ClassFileConstants.AccPublic : ClassFileConstants.AccDefault) | ClassFileConstants.AccStatic | ClassFileConstants.AccSynthetic | ClassFileConstants.AccFinal, this, Constant.NotAConstant, this.synthetics[SourceTypeBinding.FIELD_EMUL].size()); this.synthetics[SourceTypeBinding.FIELD_EMUL].put("assertionEmulation", synthField); //$NON-NLS-1$ } // ensure there is not already such a field defined by the user // ensure there is not already such a field defined by the user boolean needRecheck; int index = 0; do { needRecheck = false; FieldBinding existingField; if ((existingField = getField(synthField.name, true /*resolve*/)) != null) { TypeDeclaration typeDecl = this.scope.referenceContext; int max = (typeDecl.fields == null) ? 0 : typeDecl.fields.length; for (int i = 0; i < max; i++) { FieldDeclaration fieldDecl = typeDecl.fields[i]; if (fieldDecl.binding == existingField) { synthField.name = CharOperation.concat( TypeConstants.SYNTHETIC_ASSERT_DISABLED, ("_" + String.valueOf(index++)).toCharArray()); //$NON-NLS-1$ needRecheck = true; break; } } } } while (needRecheck); return synthField; }
Example 20
Source File: NullLiteral.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 2 votes |
public void computeConstant() { this.constant = Constant.NotAConstant; }