Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.TypeBinding#getSingleAbstractMethod()

The following examples show how to use org.eclipse.jdt.internal.compiler.lookup.TypeBinding#getSingleAbstractMethod() . 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: LambdaExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public TypeBinding[] getMarkerInterfaces() {
	if (this.expectedType instanceof IntersectionCastTypeBinding) {
		Set markerBindings = new LinkedHashSet();
		TypeBinding[] intersectionTypes = ((IntersectionCastTypeBinding)this.expectedType).intersectingTypes;
		for (int i = 0,max = intersectionTypes.length; i < max; i++) {
			TypeBinding typeBinding = intersectionTypes[i];
			MethodBinding methodBinding = typeBinding.getSingleAbstractMethod(this.scope, true);
			// Why doesn't getSingleAbstractMethod do as the javadoc says, and return null
			// when it is not a SAM type
			if (!(methodBinding instanceof ProblemMethodBinding && ((ProblemMethodBinding)methodBinding).problemId()==ProblemReasons.NoSuchSingleAbstractMethod)) {
				continue;
			}
			if (typeBinding.id == TypeIds.T_JavaIoSerializable) {
				// Serializable is captured as a bitflag
				continue;
			}
			markerBindings.add(typeBinding);
		}
		if (markerBindings.size() > 0) {
			return (TypeBinding[])markerBindings.toArray(new TypeBinding[markerBindings.size()]);
		}
	}
	return null;
}
 
Example 2
Source File: ReferenceExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean isCompatibleWith(TypeBinding left, Scope scope) {
	if (this.binding != null && this.binding.isValidBinding() // binding indicates if full resolution has already happened
			&& this.resolvedType != null && this.resolvedType.isValidBinding()) {
		return this.resolvedType.isCompatibleWith(left, scope);
	}
	// 15.28.2
	left = left.uncapture(this.enclosingScope);
	final MethodBinding sam = left.getSingleAbstractMethod(this.enclosingScope, true);
	if (sam == null || !sam.isValidBinding())
		return false;
	boolean isCompatible;
	setExpectedType(left);
	IErrorHandlingPolicy oldPolicy = this.enclosingScope.problemReporter().switchErrorHandlingPolicy(silentErrorHandlingPolicy);
	try {
		this.binding = null;
		this.trialResolution = true;
		resolveType(this.enclosingScope);
	} finally {
		this.enclosingScope.problemReporter().switchErrorHandlingPolicy(oldPolicy);
		isCompatible = this.binding != null && this.binding.isValidBinding();
		this.binding = null;
		setExpectedType(null);
		this.trialResolution = false;
	}
	return isCompatible;
}
 
Example 3
Source File: ReferenceExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean sIsMoreSpecific(TypeBinding s, TypeBinding t, Scope scope) {
	
	if (super.sIsMoreSpecific(s, t, scope))
		return true;
	
	if (this.exactMethodBinding == null || t.findSuperTypeOriginatingFrom(s) != null)
		return false;
	
	s = s.capture(this.enclosingScope, this.sourceEnd);
	MethodBinding sSam = s.getSingleAbstractMethod(this.enclosingScope, true);
	if (sSam == null || !sSam.isValidBinding())
		return false;
	TypeBinding r1 = sSam.returnType;
	
	MethodBinding tSam = t.getSingleAbstractMethod(this.enclosingScope, true);
	if (tSam == null || !tSam.isValidBinding())
		return false;
	TypeBinding r2 = tSam.returnType;
	
	if (r2.id == TypeIds.T_void)
		return true;
	
	if (r1.id == TypeIds.T_void)
		return false;
	
	// r1 <: r2
	if (r1.isCompatibleWith(r2, scope))
		return true;
	
	return r1.isBaseType() != r2.isBaseType() && r1.isBaseType() == this.exactMethodBinding.returnType.isBaseType();
}
 
Example 4
Source File: LambdaExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean sIsMoreSpecific(TypeBinding s, TypeBinding t, Scope skope) {
	
	// 15.12.2.5 
	
	if (super.sIsMoreSpecific(s, t, skope))
		return true;
	
	if (argumentsTypeElided() || t.findSuperTypeOriginatingFrom(s) != null)
		return false;
	
	s = s.capture(this.enclosingScope, this.sourceEnd);
	MethodBinding sSam = s.getSingleAbstractMethod(this.enclosingScope, true);
	if (sSam == null || !sSam.isValidBinding())
		return false;
	TypeBinding r1 = sSam.returnType;
	MethodBinding tSam = t.getSingleAbstractMethod(this.enclosingScope, true);
	if (tSam == null || !tSam.isValidBinding())
		return false;
	TypeBinding r2 = tSam.returnType;
	
	if (r2.id == TypeIds.T_void)
		return true;
	
	if (r1.id == TypeIds.T_void)
		return false;
	
	// r1 <: r2
	if (r1.isCompatibleWith(r2, skope))
		return true;
	
	Expression [] returnExpressions = this.resultExpressions;
	int returnExpressionsLength = returnExpressions == null ? 0 : returnExpressions.length;
	
	int i;
	// r1 is a primitive type, r2 is a reference type, and each result expression is a standalone expression (15.2) of a primitive type
	if (r1.isBaseType() && !r2.isBaseType()) {
		for (i = 0; i < returnExpressionsLength; i++) {
			if (returnExpressions[i].isPolyExpression() || !returnExpressions[i].resolvedType.isBaseType())
				break;
		}
		if (i == returnExpressionsLength)
			return true;
	}
	if (!r1.isBaseType() && r2.isBaseType()) {
		for (i = 0; i < returnExpressionsLength; i++) {
			if (returnExpressions[i].resolvedType.isBaseType())
				break;
		}
		if (i == returnExpressionsLength)
			return true;
	}
	if (r1.isFunctionalInterface(this.enclosingScope) && r2.isFunctionalInterface(this.enclosingScope)) {
		for (i = 0; i < returnExpressionsLength; i++) {
			Expression resultExpression = returnExpressions[i];
			if (!resultExpression.sIsMoreSpecific(r1, r2, skope))
				break;
		}
		if (i == returnExpressionsLength)
			return true;
	}
	return false;
}