org.eclipse.jdt.internal.compiler.impl.Constant Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.impl.Constant. 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: Util.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static Object getNegativeAnnotationMemberValue(MemberValuePair memberValuePair, Constant constant) {
	if (constant == null) {
		memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
		return null;
	}
	switch (constant.typeID()) {
		case TypeIds.T_int :
			memberValuePair.valueKind = IMemberValuePair.K_INT;
			return new Integer(constant.intValue() * -1);
		case TypeIds.T_float :
			memberValuePair.valueKind = IMemberValuePair.K_FLOAT;
			return new Float(constant.floatValue() * -1.0f);
		case TypeIds.T_double :
			memberValuePair.valueKind = IMemberValuePair.K_DOUBLE;
			return new Double(constant.doubleValue() * -1.0);
		case TypeIds.T_long :
			memberValuePair.valueKind = IMemberValuePair.K_LONG;
			return new Long(constant.longValue() * -1L);
		default:
			memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
			return null;
	}
}
 
Example #2
Source File: SingleNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo, boolean isReadAccess) {
	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 ((this.bits & Binding.FIELD) != 0) {
		FieldBinding fieldBinding = (FieldBinding) this.binding;
		FieldBinding codegenField = fieldBinding.original();
		if (((this.bits & ASTNode.DepthMASK) != 0)
			&& (codegenField.isPrivate() // private access
				|| (codegenField.isProtected() // implicit protected access
						&& codegenField.declaringClass.getPackage() != currentScope.enclosingSourceType().getPackage()))) {
			if (this.syntheticAccessors == null)
				this.syntheticAccessors = new MethodBinding[2];
			this.syntheticAccessors[isReadAccess ? SingleNameReference.READ : SingleNameReference.WRITE] =
			    ((SourceTypeBinding)currentScope.enclosingSourceType().
					enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT)).addSyntheticMethod(codegenField, isReadAccess, false /*not super access*/);
			currentScope.problemReporter().needToEmulateFieldAccess(codegenField, this, isReadAccess);
			return;
		}
	}
}
 
Example #3
Source File: MessageSend.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/** Variant of isPolyExpression() to be used during type inference, when a resolution candidate exists. */
public boolean isPolyExpression(MethodBinding resolutionCandidate) {
	if (this.expressionContext != ASSIGNMENT_CONTEXT && this.expressionContext != INVOCATION_CONTEXT)
		return false;
	
	if (this.typeArguments != null && this.typeArguments.length > 0)
		return false;
	
	if (this.constant != Constant.NotAConstant)
		throw new UnsupportedOperationException("Unresolved MessageSend can't be queried if it is a polyexpression"); //$NON-NLS-1$
	
	if (resolutionCandidate != null) {
		if (resolutionCandidate instanceof ParameterizedGenericMethodBinding) {
			ParameterizedGenericMethodBinding pgmb = (ParameterizedGenericMethodBinding) resolutionCandidate;
			if (pgmb.inferredReturnType)
				return true; // if already determined
		} 
		if (resolutionCandidate.returnType != null) {
			// resolution may have prematurely instantiated the generic method, we need the original, though:
			MethodBinding candidateOriginal = resolutionCandidate.original();
			return candidateOriginal.returnType.mentionsAny(candidateOriginal.typeVariables(), -1);
		}
	}
	
	return false;
}
 
Example #4
Source File: CodeSnippetThisReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public TypeBinding resolveType(BlockScope scope) {
	// implicit this
	this.constant = Constant.NotAConstant;
	ReferenceBinding snippetType = scope.enclosingSourceType();
	MethodScope methodScope = scope.methodScope();
	if (!this.isImplicit && !checkAccess(scope, snippetType)) {
		return null;
	}

	this.delegateThis = scope.getField(snippetType, DELEGATE_THIS, this);
	if (this.delegateThis == null || !this.delegateThis.isValidBinding()) {
		// should not happen
		// if this happen we should report illegal access to this in a static context
		methodScope.problemReporter().errorThisSuperInStatic(this);
		return null;
	}
	return this.resolvedType = this.delegateThis.type;
}
 
Example #5
Source File: ThisReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public TypeBinding resolveType(BlockScope scope) {

		this.constant = Constant.NotAConstant;
		
		ReferenceBinding enclosingReceiverType = scope.enclosingReceiverType();
		if (!isImplicitThis() &&!checkAccess(scope, enclosingReceiverType)) {
			return null;
		}
		this.resolvedType = enclosingReceiverType;
		MethodScope methodScope = scope.namedMethodScope();
		if (methodScope != null) {
			MethodBinding method = methodScope.referenceMethodBinding();
			if (method != null && method.receiver != null && TypeBinding.equalsEquals(method.receiver, this.resolvedType))
				this.resolvedType = method.receiver;
		}
		return this.resolvedType;
	}
 
Example #6
Source File: SingleNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void manageEnclosingInstanceAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) {
	//If inlinable field, forget the access emulation, the code gen will directly target it
	if (((this.bits & ASTNode.DepthMASK) == 0 && (this.bits & ASTNode.IsCapturedOuterLocal) == 0) || (this.constant != Constant.NotAConstant)) {
		return;
	}
	if ((this.bits & ASTNode.RestrictiveFlagMASK) == Binding.LOCAL) {
		LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding;
		if (localVariableBinding != null) {
			if ((localVariableBinding.tagBits & TagBits.NotInitialized) != 0) {
				// local was tagged as uninitialized
				return;
			}
			switch(localVariableBinding.useFlag) {
				case LocalVariableBinding.FAKE_USED :
				case LocalVariableBinding.USED :
					currentScope.emulateOuterAccess(localVariableBinding);
			}
		}
	}
}
 
Example #7
Source File: QualifiedNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public Constant optimizedBooleanConstant() {
	switch (this.resolvedType.id) {
		case T_boolean :
		case T_JavaLangBoolean :
			if (this.constant != Constant.NotAConstant) return this.constant;
			switch (this.bits & ASTNode.RestrictiveFlagMASK) {
				case Binding.FIELD : // reading a field
					if (this.otherBindings == null)
						return ((FieldBinding)this.binding).constant();
					//$FALL-THROUGH$
				case Binding.LOCAL : // reading a local variable
					return this.otherBindings[this.otherBindings.length-1].constant();
		}
	}
	return Constant.NotAConstant;
}
 
Example #8
Source File: QualifiedNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void manageEnclosingInstanceAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) {
	//If inlinable field, forget the access emulation, the code gen will directly target it
	if (((this.bits & ASTNode.DepthMASK) == 0 && (this.bits & ASTNode.IsCapturedOuterLocal) == 0) || (this.constant != Constant.NotAConstant)) {
		return;
	}
	if ((this.bits & ASTNode.RestrictiveFlagMASK) == Binding.LOCAL) {
		LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding;
		if (localVariableBinding != null) {
			if ((localVariableBinding.tagBits & TagBits.NotInitialized) != 0) {
				// local was tagged as uninitialized
				return;
			}
			switch(localVariableBinding.useFlag) {
				case LocalVariableBinding.FAKE_USED :
				case LocalVariableBinding.USED :
					currentScope.emulateOuterAccess(localVariableBinding);
			}
		}
	}
}
 
Example #9
Source File: DefaultBindingResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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 #10
Source File: InstanceOfExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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 #11
Source File: ArrayReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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 #12
Source File: CompletionOnMessageSend.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public TypeBinding resolveType(BlockScope scope) {
	this.constant = Constant.NotAConstant;
	if (this.arguments != null) {
		int argsLength = this.arguments.length;
		for (int a = argsLength; --a >= 0;)
			this.arguments[a].resolveType(scope);
	}

	if (this.receiver.isImplicitThis())
		throw new CompletionNodeFound(this, null, scope);

	this.actualReceiverType = this.receiver.resolveType(scope);
	if (this.actualReceiverType == null || this.actualReceiverType.isBaseType())
		throw new CompletionNodeFound();

	if (this.actualReceiverType.isArrayType())
		this.actualReceiverType = scope.getJavaLangObject();
	throw new CompletionNodeFound(this, this.actualReceiverType, scope);
}
 
Example #13
Source File: ClassfileDigester.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
private void updateAnnotationValue(Object object) {
  // @see org.eclipse.jdt.internal.compiler.env.IBinaryElementValuePair.getValue()
  // @see org.eclipse.jdt.internal.compiler.classfmt.AnnotationInfo.decodeDefaultValue()
  if (object instanceof ClassSignature) {
    updateChars(((ClassSignature) object).getTypeName());
  } else if (object instanceof Constant) {
    updateConstant((Constant) object);
  } else if (object instanceof EnumConstantSignature) {
    updateChars(((EnumConstantSignature) object).getTypeName());
    updateChars(((EnumConstantSignature) object).getEnumConstantName());
  } else if (object instanceof IBinaryAnnotation) {
    updateAnnotation((IBinaryAnnotation) object);
  } else {
    throw new IllegalArgumentException("Unsupported annotation value " + object.toString());
  }
}
 
Example #14
Source File: Expression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 #15
Source File: ClassfileDigester.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
private void updateConstant(Constant constant) {
  updateInt(constant.typeID());
  updateString(constant.getClass().getName());
  switch (constant.typeID()) {
    case TypeIds.T_int:
      updateInt(constant.intValue());
      break;
    case TypeIds.T_byte:
      updateByte(constant.byteValue());
      break;
    case TypeIds.T_short:
      updateShort(constant.shortValue());
      break;
    case TypeIds.T_char:
      updateChar(constant.charValue());
      break;
    case TypeIds.T_long:
      updateLong(constant.longValue());
      break;
    case TypeIds.T_float:
      updateFloat(constant.floatValue());
      break;
    case TypeIds.T_double:
      updateDouble(constant.doubleValue());
      break;
    case TypeIds.T_boolean:
      updateBoolean(constant.booleanValue());
      break;
    case TypeIds.T_JavaLangString:
      updateString(constant.stringValue());
      break;
    default:
      throw new IllegalArgumentException("Unexpected constant typeID=" + constant.typeID());
  }
}
 
Example #16
Source File: UnconditionalFlowInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 #17
Source File: SourceTypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public FieldBinding addSyntheticFieldForClassLiteral(TypeBinding targetType, BlockScope blockScope) {
	
	if (!isPrototype()) throw new IllegalStateException();
	
	if (this.synthetics == null)
		this.synthetics = new HashMap[MAX_SYNTHETICS];
	if (this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL] == null)
		this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL] = new HashMap(5);

	// use a different table than FIELDS, given there might be a collision between emulation of X.this$0 and X.class.
	FieldBinding synthField = (FieldBinding) this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL].get(targetType);
	if (synthField == null) {
		synthField = new SyntheticFieldBinding(
			CharOperation.concat(
				TypeConstants.SYNTHETIC_CLASS,
				String.valueOf(this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL].size()).toCharArray()),
			blockScope.getJavaLangClass(),
			ClassFileConstants.AccDefault | ClassFileConstants.AccStatic | ClassFileConstants.AccSynthetic,
			this,
			Constant.NotAConstant,
			this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL].size());
		this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL].put(targetType, synthField);
	}
	// ensure there is not already such a field defined by the user
	FieldBinding existingField;
	if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
		TypeDeclaration typeDecl = blockScope.referenceType();
		FieldDeclaration[] typeDeclarationFields = typeDecl.fields;
		int max = typeDeclarationFields == null ? 0 : typeDeclarationFields.length;
		for (int i = 0; i < max; i++) {
			FieldDeclaration fieldDecl = typeDeclarationFields[i];
			if (fieldDecl.binding == existingField) {
				blockScope.problemReporter().duplicateFieldInType(this, fieldDecl);
				break;
			}
		}
	}
	return synthField;
}
 
Example #18
Source File: Expression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 #19
Source File: VariableElementImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object getConstantValue() {
	VariableBinding variableBinding = (VariableBinding) _binding;
	Constant constant = variableBinding.constant();
	if (constant == null || constant == Constant.NotAConstant) return null;
	TypeBinding type = variableBinding.type;
	switch (type.id) {
		case TypeIds.T_boolean:
			return constant.booleanValue();
		case TypeIds.T_byte:
			return constant.byteValue();
		case TypeIds.T_char:
			return constant.charValue();
		case TypeIds.T_double:
			return constant.doubleValue();
		case TypeIds.T_float:
			return constant.floatValue();
		case TypeIds.T_int:
			return constant.intValue();
		case TypeIds.T_JavaLangString:
			return constant.stringValue();
		case TypeIds.T_long:
			return constant.longValue();
		case TypeIds.T_short:
			return constant.shortValue();
	}
	return null;
}
 
Example #20
Source File: CodeSnippetReturnStatement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void resolve(BlockScope scope) {
	if (this.expression != null) {
		if (this.expression.resolveType(scope) != null) {
			TypeBinding javaLangClass = scope.getJavaLangClass();
			if (!javaLangClass.isValidBinding()) {
				scope.problemReporter().codeSnippetMissingClass("java.lang.Class", this.sourceStart, this.sourceEnd); //$NON-NLS-1$
				return;
			}
			TypeBinding javaLangObject = scope.getJavaLangObject();
			if (!javaLangObject.isValidBinding()) {
				scope.problemReporter().codeSnippetMissingClass("java.lang.Object", this.sourceStart, this.sourceEnd); //$NON-NLS-1$
				return;
			}
			TypeBinding[] argumentTypes = new TypeBinding[] {javaLangObject, javaLangClass};
			this.setResultMethod = scope.getImplicitMethod(SETRESULT_SELECTOR, argumentTypes, this);
			if (!this.setResultMethod.isValidBinding()) {
				scope.problemReporter().codeSnippetMissingMethod(ROOT_FULL_CLASS_NAME, new String(SETRESULT_SELECTOR), new String(SETRESULT_ARGUMENTS), this.sourceStart, this.sourceEnd);
				return;
			}
			// in constant case, the implicit conversion cannot be left uninitialized
			if (this.expression.constant != Constant.NotAConstant) {
				// fake 'no implicit conversion' (the return type is always void)
				this.expression.implicitConversion = this.expression.constant.typeID() << 4;
			}
		}
	}
}
 
Example #21
Source File: UnconditionalFlowInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
final public boolean isPotentiallyAssigned(LocalVariableBinding local) {
	// final constants are inlined, and thus considered as always initialized
	if (local.constant() != Constant.NotAConstant) {
		return true;
	}
	return isPotentiallyAssigned(local.id + this.maxFieldCount);
}
 
Example #22
Source File: VariableBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public VariableBinding(char[] name, TypeBinding type, int modifiers, Constant constant) {
	this.name = name;
	this.type = type;
	this.modifiers = modifiers;
	this.constant = constant;
	if (type != null) {
		this.tagBits |= (type.tagBits & TagBits.HasMissingType);
	}
}
 
Example #23
Source File: SynchronizedStatement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void resolve(BlockScope upperScope) {
	// special scope for secret locals optimization.
	this.scope = new BlockScope(upperScope);
	TypeBinding type = this.expression.resolveType(this.scope);
	if (type == null)
		return;
	switch (type.id) {
		case T_boolean :
		case T_char :
		case T_float :
		case T_double :
		case T_byte :
		case T_short :
		case T_int :
		case T_long :
			this.scope.problemReporter().invalidTypeToSynchronize(this.expression, type);
			break;
		case T_void :
			this.scope.problemReporter().illegalVoidExpression(this.expression);
			break;
		case T_null :
			this.scope.problemReporter().invalidNullToSynchronize(this.expression);
			break;
	}
	//continue even on errors in order to have the TC done into the statements
	this.synchroVariable = new LocalVariableBinding(SecretLocalDeclarationName, type, ClassFileConstants.AccDefault, false);
	this.scope.addLocalVariable(this.synchroVariable);
	this.synchroVariable.setConstant(Constant.NotAConstant); // not inlinable
	this.expression.computeConversion(this.scope, type, type);
	this.block.resolveUsing(this.scope);
}
 
Example #24
Source File: JavadocQualifiedTypeReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private TypeBinding internalResolveType(Scope scope, boolean checkBounds) {
	// handle the error here
	this.constant = Constant.NotAConstant;
	if (this.resolvedType != null) // is a shared type reference which was already resolved
		return this.resolvedType.isValidBinding() ? this.resolvedType : this.resolvedType.closestMatch(); // already reported error

	TypeBinding type = this.resolvedType = getTypeBinding(scope);
	// End resolution when getTypeBinding(scope) returns null. This may happen in
	// certain circumstances, typically when an illegal access is done on a type
	// variable (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=204749)
	if (type == null) return null;
	if (!type.isValidBinding()) {
		Binding binding = scope.getTypeOrPackage(this.tokens);
		if (binding instanceof PackageBinding) {
			this.packageBinding = (PackageBinding) binding;
			// Valid package references are allowed in Javadoc (https://bugs.eclipse.org/bugs/show_bug.cgi?id=281609)
		} else {
			reportInvalidType(scope);
		}
		return null;
	}
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=209936
	// raw convert all enclosing types when dealing with Javadoc references
	if (type.isGenericType() || type.isParameterizedType()) {
		this.resolvedType = scope.environment().convertToRawType(type, true /*force the conversion of enclosing types*/);
	}
	return this.resolvedType;
}
 
Example #25
Source File: FieldBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 #26
Source File: FieldReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 #27
Source File: SuperReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 #28
Source File: CastExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 #29
Source File: CastExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.jdt.internal.compiler.ast.Expression#optimizedBooleanConstant()
 */
public Constant optimizedBooleanConstant() {
	switch(this.resolvedType.id) {
		case T_boolean :
		case T_JavaLangBoolean :
			return this.expression.optimizedBooleanConstant();
	}
	return Constant.NotAConstant;
}
 
Example #30
Source File: FakedTrackingVariable.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void resolve (BlockScope scope) {
	// only need the binding, which is used as reference in FlowInfo methods.
	this.binding = new LocalVariableBinding(
			this.name,
			scope.getJavaLangObject(),  // dummy, just needs to be a reference type
			0,
			false);
	this.binding.closeTracker = this;
	this.binding.declaringScope = scope;
	this.binding.setConstant(Constant.NotAConstant);
	this.binding.useFlag = LocalVariableBinding.USED;
	// use a free slot without assigning it:
	this.binding.id = scope.registerTrackingVariable(this);
}