Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.MethodBinding#isValidBinding()

The following examples show how to use org.eclipse.jdt.internal.compiler.lookup.MethodBinding#isValidBinding() . 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: CodeSnippetScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public MethodBinding findMethodForArray(ArrayBinding receiverType, char[] selector, TypeBinding[] argumentTypes, InvocationSite invocationSite) {
	ReferenceBinding object = getJavaLangObject();
	MethodBinding methodBinding = object.getExactMethod(selector, argumentTypes, null);
	if (methodBinding != null) {
		// handle the method clone() specially... cannot be protected or throw exceptions
		if (argumentTypes == Binding.NO_PARAMETERS && CharOperation.equals(selector, TypeConstants.CLONE))
			return new MethodBinding((methodBinding.modifiers & ~ClassFileConstants.AccProtected) | ClassFileConstants.AccPublic, TypeConstants.CLONE, methodBinding.returnType, argumentTypes, null, object);
		if (canBeSeenByForCodeSnippet(methodBinding, receiverType, invocationSite, this))
			return methodBinding;
	}

	// answers closest approximation, may not check argumentTypes or visibility
	methodBinding = findMethod(object, selector, argumentTypes, invocationSite, false);
	if (methodBinding == null)
		return new ProblemMethodBinding(selector, argumentTypes, ProblemReasons.NotFound);
	if (methodBinding.isValidBinding()) {
	    MethodBinding compatibleMethod = computeCompatibleMethod(methodBinding, argumentTypes, invocationSite, Scope.FULL_INFERENCE);
	    if (compatibleMethod == null)
			return new ProblemMethodBinding(methodBinding, selector, argumentTypes, ProblemReasons.NotFound);
	    methodBinding = compatibleMethod;
		if (!canBeSeenByForCodeSnippet(methodBinding, receiverType, invocationSite, this))
			return new ProblemMethodBinding(methodBinding, selector, methodBinding.parameters, ProblemReasons.NotVisible);
	}
	return methodBinding;
}
 
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: FunctionalExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public TypeBinding resolveType(BlockScope blockScope) {
	this.constant = Constant.NotAConstant;
	this.enclosingScope = blockScope;
	MethodBinding sam = this.expectedType == null ? null : this.expectedType.getSingleAbstractMethod(blockScope, argumentsTypeElided());
	if (sam == null) {
		blockScope.problemReporter().targetTypeIsNotAFunctionalInterface(this);
		return null;
	}
	if (!sam.isValidBinding()) {
		return reportSamProblem(blockScope, sam);
	}
	
	this.descriptor = sam;
	if (kosherDescriptor(blockScope, sam, true)) {
		return this.resolvedType = this.expectedType;		
	}
	
	return this.resolvedType = null;
}
 
Example 4
Source File: SelectionOnReferenceExpressionName.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public TypeBinding resolveType(BlockScope scope) {
	TypeBinding type = super.resolveType(scope);
	if (type instanceof PolyTypeBinding)
		return type;
	MethodBinding method = getMethodBinding();
	if (method != null && method.isValidBinding() && !method.isSynthetic())
		throw new SelectionNodeFound(this.actualMethodBinding);
	throw new SelectionNodeFound();
}
 
Example 5
Source File: CodeSnippetScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public MethodBinding findMethod(ReferenceBinding receiverType, char[] selector, TypeBinding[] argumentTypes, InvocationSite invocationSite, boolean inStaticContext) {
	MethodBinding methodBinding = super.findMethod(receiverType, selector, argumentTypes, invocationSite, inStaticContext);
	if (methodBinding != null && methodBinding.isValidBinding())
		if (!canBeSeenByForCodeSnippet(methodBinding, receiverType, invocationSite, this))
			return new ProblemMethodBinding(methodBinding, selector, argumentTypes, ProblemReasons.NotVisible);
	return methodBinding;
}
 
Example 6
Source File: CodeSnippetScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public MethodBinding getImplicitMethod(ReferenceBinding receiverType, char[] selector, TypeBinding[] argumentTypes, InvocationSite invocationSite) {
	// retrieve an exact visible match (if possible)
	MethodBinding methodBinding = findExactMethod(receiverType, selector, argumentTypes, invocationSite);
	if (methodBinding == null)
		methodBinding = findMethod(receiverType, selector, argumentTypes, invocationSite, false);
	if (methodBinding != null) { // skip it if we did not find anything
		if (methodBinding.isValidBinding())
		    if (!canBeSeenByForCodeSnippet(methodBinding, receiverType, invocationSite, this))
				return new ProblemMethodBinding(methodBinding, selector, argumentTypes, ProblemReasons.NotVisible);
		return methodBinding;
	}
	return new ProblemMethodBinding(selector, argumentTypes, ProblemReasons.NotFound);
}
 
Example 7
Source File: TypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IMethodBinding getFunctionalInterfaceMethod() {
	Scope scope = this.resolver.scope();
	if (this.binding == null || scope == null)
		return null;
	MethodBinding sam = this.binding.getSingleAbstractMethod(scope, true);
	if (sam == null || !sam.isValidBinding())
		return null;
	return this.resolver.getMethodBinding(sam);
}
 
Example 8
Source File: ReferenceExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/** During inference: Try to find an applicable method binding without causing undesired side-effects. */
public MethodBinding findCompileTimeMethodTargeting(TypeBinding targetType, Scope scope) {
	MethodBinding targetMethod = internalResolveTentatively(targetType, scope);
	if (targetMethod == null || !targetMethod.isValidBinding())
		return null;
	return targetMethod;
}
 
Example 9
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 10
Source File: FakedTrackingVariable.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isBlacklistedMethod(Expression expression) {
	if (expression instanceof MessageSend) {
		MethodBinding method = ((MessageSend) expression).binding;
		if (method != null && method.isValidBinding())
			// for all methods in java.nio.file.Files that return a resource (Stream) it really needs closing
			return CharOperation.equals(method.declaringClass.compoundName, TypeConstants.JAVA_NIO_FILE_FILES);
	}
	return false;
}
 
Example 11
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;
}