当前位置: 首页>>代码示例>>Java>>正文


Java TypeBinding.isValidBinding方法代码示例

本文整理汇总了Java中org.eclipse.jdt.internal.compiler.lookup.TypeBinding.isValidBinding方法的典型用法代码示例。如果您正苦于以下问题:Java TypeBinding.isValidBinding方法的具体用法?Java TypeBinding.isValidBinding怎么用?Java TypeBinding.isValidBinding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.internal.compiler.lookup.TypeBinding的用法示例。


在下文中一共展示了TypeBinding.isValidBinding方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mergeAnnotationsIntoType

import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
private static TypeBinding mergeAnnotationsIntoType(BlockScope scope, AnnotationBinding[] se8Annotations, long se8nullBits, Annotation se8NullAnnotation,
		TypeReference typeRef, TypeBinding existingType) 
{
	if (existingType == null || !existingType.isValidBinding()) return existingType;
	TypeReference unionRef = typeRef.isUnionType() ? ((UnionTypeReference) typeRef).typeReferences[0] : null;
	
	// for arrays: @T X[] SE7 associates @T to the type, but in SE8 it affects the leaf component type
	long prevNullBits = existingType.leafComponentType().tagBits & TagBits.AnnotationNullMASK;
	if (se8nullBits != 0 && prevNullBits != se8nullBits && ((prevNullBits | se8nullBits) == TagBits.AnnotationNullMASK)) {
		scope.problemReporter().contradictoryNullAnnotations(se8NullAnnotation);
	}
	TypeBinding oldLeafType = (unionRef == null) ? existingType.leafComponentType() : unionRef.resolvedType;
	AnnotationBinding [][] goodies = new AnnotationBinding[typeRef.getAnnotatableLevels()][];
	goodies[0] = se8Annotations;  // @T X.Y.Z local; ==> @T should annotate X
	TypeBinding newLeafType = scope.environment().createAnnotatedType(oldLeafType, goodies);

	if (unionRef == null) {
		typeRef.resolvedType = existingType.isArrayType() ? scope.environment().createArrayType(newLeafType, existingType.dimensions(), existingType.getTypeAnnotations()) : newLeafType;
	} else {
		unionRef.resolvedType = newLeafType;
		unionRef.bits |= HasTypeAnnotations;
	}
	return typeRef.resolvedType;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:ASTNode.java

示例2: resolveType

import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
public TypeBinding resolveType(BlockScope scope) {
	TypeBinding binding = super.resolveType(scope);

	if (binding == null || !binding.isValidBinding())
		throw new SelectionNodeFound();
	else
		throw new SelectionNodeFound(binding);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:9,代码来源:SelectionOnQualifiedSuperReference.java

示例3: resolveType

import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
@Override
public TypeBinding resolveType(BlockScope scope) {
	
	final CompilerOptions compilerOptions = scope.compilerOptions();
	TypeBinding lhsType;
	boolean typeArgumentsHaveErrors;

	this.constant = Constant.NotAConstant;
	lhsType = this.lhs.resolveType(scope);
	if (this.typeArguments != null) {
		int length = this.typeArguments.length;
		typeArgumentsHaveErrors = compilerOptions.sourceLevel < ClassFileConstants.JDK1_5;
		this.resolvedTypeArguments = new TypeBinding[length];
		for (int i = 0; i < length; i++) {
			TypeReference typeReference = this.typeArguments[i];
			if ((this.resolvedTypeArguments[i] = typeReference.resolveType(scope, true /* check bounds*/)) == null) {
				typeArgumentsHaveErrors = true;
			}
			if (typeArgumentsHaveErrors && typeReference instanceof Wildcard) { // resolveType on wildcard always return null above, resolveTypeArgument is the real workhorse.
				scope.problemReporter().illegalUsageOfWildcard(typeReference);
			}
		}
		if (typeArgumentsHaveErrors || lhsType == null)
			throw new CompletionNodeFound();
	}
   	
	if (lhsType != null && lhsType.isValidBinding())
		throw new CompletionNodeFound(this, lhsType, scope);
	throw new CompletionNodeFound();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:31,代码来源:CompletionOnReferenceExpressionName.java

示例4: resolve

import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
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;
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:28,代码来源:CodeSnippetReturnStatement.java

示例5: internalResolveType

import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:29,代码来源:JavadocQualifiedTypeReference.java

示例6: removeCaughtExceptions

import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
private void removeCaughtExceptions(TryStatement tryStatement, boolean recordUncheckedCaughtExceptions) {
	Argument[] catchArguments = tryStatement.catchArguments;
	int length = catchArguments == null ? 0 : catchArguments.length;
	for (int i = 0; i < length; i++) {
		if (catchArguments[i].type instanceof UnionTypeReference) {
			UnionTypeReference unionTypeReference = (UnionTypeReference) catchArguments[i].type;
			TypeBinding caughtException;
			for (int j = 0; j < unionTypeReference.typeReferences.length; j++) {
				caughtException = unionTypeReference.typeReferences[j].resolvedType;
				if ((caughtException instanceof ReferenceBinding) && caughtException.isValidBinding()) {	// might be null when its the completion node
					if (recordUncheckedCaughtExceptions) {
						// is in outermost try-catch. Remove all caught exceptions, unchecked or checked
						removeCaughtException((ReferenceBinding)caughtException);
						this.caughtExceptions.add(caughtException);
					} else {
						// is in some inner try-catch. Discourage already caught checked exceptions
						// from being proposed in an outer catch.
						if (!caughtException.isUncheckedException(true)) {
							this.discouragedExceptions.add(caughtException);
						}
					}
				}
			}
		} else {
			TypeBinding exception = catchArguments[i].type.resolvedType;
			if ((exception instanceof ReferenceBinding) && exception.isValidBinding()) {
				if (recordUncheckedCaughtExceptions) {
					// is in outermost try-catch. Remove all caught exceptions, unchecked or checked
					removeCaughtException((ReferenceBinding)exception);
					this.caughtExceptions.add(exception);
				} else {
					// is in some inner try-catch. Discourage already caught checked exceptions
					// from being proposed in an outer catch
					if (!exception.isUncheckedException(true)) {
						this.discouragedExceptions.add(exception);
					}
				}
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:42,代码来源:ThrownExceptionFinder.java

示例7: getResolvedCopyForInferenceTargeting

import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
/**
 * Get a resolved copy of this lambda for use by type inference, as to avoid spilling any premature
 * type results into the original lambda.
 * 
 * @param targetType the target functional type against which inference is attempted, must be a non-null valid functional type 
 * @return a resolved copy of 'this' or null if significant errors where encountered
 */
public LambdaExpression getResolvedCopyForInferenceTargeting(TypeBinding targetType) {
	// note: this is essentially a simplified extract from isCompatibleWith(TypeBinding,Scope).
	if (this.shapeAnalysisComplete && this.binding != null)
		return this;
	
	targetType = targetType.uncapture(this.enclosingScope);
	// TODO: caching
	IErrorHandlingPolicy oldPolicy = this.enclosingScope.problemReporter().switchErrorHandlingPolicy(silentErrorHandlingPolicy);
	final CompilerOptions compilerOptions = this.enclosingScope.compilerOptions();
	boolean analyzeNPE = compilerOptions.isAnnotationBasedNullAnalysisEnabled;
	final LambdaExpression copy = copy();
	if (copy == null) {
		return null;
	}
	try {
		compilerOptions.isAnnotationBasedNullAnalysisEnabled = false;
		copy.setExpressionContext(this.expressionContext);
		copy.setExpectedType(targetType);
		this.hasIgnoredMandatoryErrors = false;
		TypeBinding type = copy.resolveType(this.enclosingScope);
		if (type == null || !type.isValidBinding())
			return null;
		if (this.body instanceof Block) {
			if (copy.returnsVoid) {
				copy.shapeAnalysisComplete = true;
			} else {
				copy.valueCompatible = this.returnsValue;
			}
		} else {
			copy.voidCompatible = ((Expression) this.body).statementExpression();
			TypeBinding resultType = ((Expression) this.body).resolvedType;
			if (resultType == null) // case of a yet-unresolved poly expression?
				copy.valueCompatible = true;
			else
				copy.valueCompatible = (resultType != TypeBinding.VOID);
			copy.shapeAnalysisComplete = true;
		}
		// Do not proceed with data/control flow analysis if resolve encountered errors.
		if (!this.hasIgnoredMandatoryErrors && !enclosingScopesHaveErrors()) {
			// value compatibility of block lambda's is the only open question.
			if (!copy.shapeAnalysisComplete)
				copy.valueCompatible = copy.doesNotCompleteNormally();
		} else {
			if (!copy.returnsVoid)
				copy.valueCompatible = true; // optimistically, TODO: is this OK??
		}
		
		copy.shapeAnalysisComplete = true;
		copy.resultExpressions = this.resultExpressions;
		this.resultExpressions = NO_EXPRESSIONS;
	} finally {
		compilerOptions.isAnnotationBasedNullAnalysisEnabled = analyzeNPE;
		this.hasIgnoredMandatoryErrors = false;
		this.enclosingScope.problemReporter().switchErrorHandlingPolicy(oldPolicy);
	}
	return copy;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:65,代码来源:LambdaExpression.java

示例8: resolveType

import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
public TypeBinding resolveType(BlockScope scope, boolean checkBounds, int location) {
	// return the lub (least upper bound of all type binding) 
	int length = this.typeReferences.length;
	TypeBinding[] allExceptionTypes = new TypeBinding[length];
	boolean hasError = false;
	for (int i = 0; i < length; i++) {
		TypeBinding exceptionType = this.typeReferences[i].resolveType(scope, checkBounds, location);
		if (exceptionType == null) {
			return null;
		}
		switch(exceptionType.kind()) {
			case Binding.PARAMETERIZED_TYPE :
				if (exceptionType.isBoundParameterizedType()) {
					hasError = true;
					scope.problemReporter().invalidParameterizedExceptionType(exceptionType, this.typeReferences[i]);
					// fall thru to create the variable - avoids additional errors because the variable is missing
				}
				break;
			case Binding.TYPE_PARAMETER :
				scope.problemReporter().invalidTypeVariableAsException(exceptionType, this.typeReferences[i]);
				hasError = true;
				// fall thru to create the variable - avoids additional errors because the variable is missing
				break;
		}
		if (exceptionType.findSuperTypeOriginatingFrom(TypeIds.T_JavaLangThrowable, true) == null
				&& exceptionType.isValidBinding()) {
			scope.problemReporter().cannotThrowType(this.typeReferences[i], exceptionType);
			hasError = true;
		}
		allExceptionTypes[i] = exceptionType;
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340486, ensure types are of union type.
		for (int j = 0; j < i; j++) {
			if (allExceptionTypes[j].isCompatibleWith(exceptionType)) {
				scope.problemReporter().wrongSequenceOfExceptionTypes(
						this.typeReferences[j],
						allExceptionTypes[j],
						exceptionType);
				hasError = true;
			} else if (exceptionType.isCompatibleWith(allExceptionTypes[j])) {
				scope.problemReporter().wrongSequenceOfExceptionTypes(
						this.typeReferences[i],
						exceptionType,
						allExceptionTypes[j]);
				hasError = true;
			}
		}
	}
	if (hasError) {
		return null;
	}
	// compute lub
	return (this.resolvedType = scope.lowerUpperBound(allExceptionTypes));
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:54,代码来源:UnionTypeReference.java

示例9: findMethodBinding

import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
/**
 * Find the method binding; 
 * if this.innersNeedUpdate allow for two attempts where the first round may stop
 * after applicability checking (18.5.1) to include more information into the final
 * invocation type inference (18.5.2).
 */
protected void findMethodBinding(BlockScope scope, TypeBinding[] argumentTypes) {
	this.binding = this.receiver.isImplicitThis()
			? scope.getImplicitMethod(this.selector, argumentTypes, this)
			: scope.getMethod(this.actualReceiverType, this.selector, argumentTypes, this);
	resolvePolyExpressionArguments(this, this.binding, argumentTypes, scope);
	
	/* There are embedded assumptions in the JLS8 type inference scheme that a successful solution of the type equations results in an
	   applicable method. This appears to be a tenuous assumption, at least one not made by the JLS7 engine or the reference compiler and 
	   there are cases where this assumption would appear invalid: See https://bugs.eclipse.org/bugs/show_bug.cgi?id=426537, where we allow 
	   certain compatibility constrains around raw types to be violated. 
       
       Here, we filter out such inapplicable methods with raw type usage that may have sneaked past overload resolution and type inference, 
       playing the devils advocate, blaming the invocations with raw arguments that should not go blameless. At this time this is in the 
       nature of a point fix and is not a general solution which needs to come later (that also includes AE, QAE and ECC)
    */
	final CompilerOptions compilerOptions = scope.compilerOptions();
	if (compilerOptions.sourceLevel >= ClassFileConstants.JDK1_8 && this.binding instanceof ParameterizedGenericMethodBinding && this.binding.isValidBinding()) {
		if (!compilerOptions.postResolutionRawTypeCompatibilityCheck)
			return;
		ParameterizedGenericMethodBinding pgmb = (ParameterizedGenericMethodBinding) this.binding;
		InferenceContext18 ctx = getInferenceContext(pgmb);
		if (ctx == null || ctx.stepCompleted < InferenceContext18.BINDINGS_UPDATED)
			return;
		int length = pgmb.typeArguments == null ? 0 : pgmb.typeArguments.length;
		boolean sawRawType = false;
		for (int i = 0;  i < length; i++) {
			/* Must check compatibility against capture free method. Formal parameters cannot have captures, but our machinery is not up to snuff to
			   construct a PGMB without captures at the moment - for one thing ITCB does not support uncapture() yet, for another, INTERSECTION_CAST_TYPE
			   does not appear fully hooked up into isCompatibleWith and isEquivalent to everywhere. At the moment, bail out if we see capture.
			*/   
			if (pgmb.typeArguments[i].isCapture())
				return;
			if (pgmb.typeArguments[i].isRawType())
				sawRawType = true;
		}
		if (!sawRawType)
			return;
		length = this.arguments == null ? 0 : this.arguments.length;
		if (length == 0)
			return;
		TypeBinding [] finalArgumentTypes = new TypeBinding[length];
		for (int i = 0; i < length; i++) {
			TypeBinding finalArgumentType = this.arguments[i].resolvedType;
			if (finalArgumentType == null || !finalArgumentType.isValidBinding())  // already sided with the devil.
				return;
			finalArgumentTypes[i] = finalArgumentType; 
		}
		if (scope.parameterCompatibilityLevel(this.binding, finalArgumentTypes, false) == Scope.NOT_COMPATIBLE)
			this.binding = new ProblemMethodBinding(this.binding.original(), this.binding.selector, finalArgumentTypes, ProblemReasons.NotFound);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:58,代码来源:MessageSend.java

示例10: resolveType

import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; //导入方法依赖的package包/类
public TypeBinding resolveType(BlockScope scope, boolean checkBounds) {
	// return the lub (least upper bound of all type binding) 
	int length = this.typeReferences.length;
	TypeBinding[] allExceptionTypes = new TypeBinding[length];
	boolean hasError = false;
	for (int i = 0; i < length; i++) {
		TypeBinding exceptionType = this.typeReferences[i].resolveType(scope, checkBounds);
		if (exceptionType == null) {
			return null;
		}
		switch(exceptionType.kind()) {
			case Binding.PARAMETERIZED_TYPE :
				if (exceptionType.isBoundParameterizedType()) {
					hasError = true;
					scope.problemReporter().invalidParameterizedExceptionType(exceptionType, this.typeReferences[i]);
					// fall thru to create the variable - avoids additional errors because the variable is missing
				}
				break;
			case Binding.TYPE_PARAMETER :
				scope.problemReporter().invalidTypeVariableAsException(exceptionType, this.typeReferences[i]);
				hasError = true;
				// fall thru to create the variable - avoids additional errors because the variable is missing
				break;
		}
		if (exceptionType.findSuperTypeOriginatingFrom(TypeIds.T_JavaLangThrowable, true) == null
				&& exceptionType.isValidBinding()) {
			scope.problemReporter().cannotThrowType(this.typeReferences[i], exceptionType);
			hasError = true;
		}
		allExceptionTypes[i] = exceptionType;
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340486, ensure types are of union type.
		for (int j = 0; j < i; j++) {
			if (allExceptionTypes[j].isCompatibleWith(exceptionType)) {
				scope.problemReporter().wrongSequenceOfExceptionTypes(
						this.typeReferences[j],
						allExceptionTypes[j],
						exceptionType);
				hasError = true;
			} else if (exceptionType.isCompatibleWith(allExceptionTypes[j])) {
				scope.problemReporter().wrongSequenceOfExceptionTypes(
						this.typeReferences[i],
						exceptionType,
						allExceptionTypes[j]);
				hasError = true;
			}
		}
	}
	if (hasError) {
		return null;
	}
	// compute lub
	return (this.resolvedType = scope.lowerUpperBound(allExceptionTypes));
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:54,代码来源:UnionTypeReference.java


注:本文中的org.eclipse.jdt.internal.compiler.lookup.TypeBinding.isValidBinding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。