Java Code Examples for org.eclipse.jdt.internal.compiler.ast.ASTNode#resolvePolyExpressionArguments()

The following examples show how to use org.eclipse.jdt.internal.compiler.ast.ASTNode#resolvePolyExpressionArguments() . 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: InferenceContext18.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void acceptPendingPolyArguments(BoundSet acceptedResult, TypeBinding[] parameterTypes, boolean isVarArgs) {
	if (acceptedResult == null || this.invocationArguments == null) return;
	Substitution substitution = getResultSubstitution(acceptedResult);
	for (int i = 0; i < this.invocationArguments.length; i++) {
		TypeBinding targetType = getParameter(parameterTypes, i, isVarArgs);
		if (!targetType.isProperType(true))
			targetType = Scope.substitute(substitution, targetType);
		Expression expression = this.invocationArguments[i];
		if (expression instanceof Invocation) {
			Invocation invocation = (Invocation) expression;
			if (!this.innerPolies.contains(invocation)) {
				MethodBinding method = invocation.binding(targetType, true, this.scope);
				if (method instanceof ParameterizedGenericMethodBinding) {
					ParameterizedGenericMethodBinding previousBinding = (ParameterizedGenericMethodBinding) method;
					InferenceContext18 innerCtx = invocation.getInferenceContext(previousBinding);
					if (innerCtx != null) {
						// we have a non-poly generic invocation, which needs inference but is not connected via innerPolis.
						// Finish that inner inference now (incl. binding updates):
						MethodBinding innerBinding = innerCtx.inferInvocationType(invocation, previousBinding);
						if (!innerBinding.isValidBinding()) {
							innerCtx.reportInvalidInvocation(invocation, innerBinding);
						}
						if (invocation.updateBindings(innerBinding, targetType)) { // only if we are actually improving anything
							ASTNode.resolvePolyExpressionArguments(invocation, innerBinding, this.scope);
						}
					}
				} else if(method instanceof ParameterizedMethodBinding){
					expression.checkAgainstFinalTargetType(targetType, this.scope);
				}
			} else {
				expression.setExpectedType(targetType);
			}
		} else {
			expression.checkAgainstFinalTargetType(targetType, this.scope);
		}
	}
}
 
Example 2
Source File: InferenceContext18.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * After inference has finished, iterate all inner poly expressions (Invocations), that
 * have been included in the inference. For each of these update some type information
 * from the inference result and perhaps trigger follow-up resolving as needed.
 * Similar for poly expressions that did not directly participate in the inference
 * but are direct arguments of the current invocation (FunctionalExpression, ConditionalExpression).
 */
public void rebindInnerPolies(BoundSet bounds, TypeBinding[] parameterTypes) {
	// This updates all remaining poly expressions that are direct arguments of the current invocation:
	// (handles FunctionalExpression & ConditionalExpression)
	boolean isVarargs = this.inferenceKind == CHECK_VARARG;
	acceptPendingPolyArguments(bounds, parameterTypes, isVarargs);
	// This loops over all poly expressions for which a sub-inference was triggered:
	// (handles generic invocations)
	int len = this.innerPolies.size();
	for (int i = 0; i < len; i++) {
		Expression inner = (Expression) this.innerPolies.get(i);
		if (inner instanceof Invocation) {
			Invocation innerMessage = (Invocation) inner;
			TypeBinding innerTargetType = inner.expectedType(); // may be set from acceptPendingPolyArguments
			if (innerTargetType != null && !innerTargetType.isProperType(true))
				innerTargetType = null;
			MethodBinding binding = innerMessage.binding(innerTargetType, innerTargetType != null, this.scope);
			if (binding == null)
				continue;
			MethodBinding original = binding.shallowOriginal();

			// apply inference results onto the allocation type of inner diamonds:
			if (original.isConstructor() && inner.isPolyExpression()) {
				ReferenceBinding declaringClass = original.declaringClass;
				TypeBinding[] arguments = getSolutions(declaringClass.typeVariables(), innerMessage, bounds);
				declaringClass = this.environment.createParameterizedType(declaringClass, arguments, declaringClass.enclosingType());
				original = ((ParameterizedTypeBinding)declaringClass).createParameterizedMethod(original);
				inner.checkAgainstFinalTargetType(innerTargetType, this.scope);	
				if (this.environment.globalOptions.isAnnotationBasedNullAnalysisEnabled)
					NullAnnotationMatching.checkForContraditions(original, innerMessage, this.scope);
			}
			
			// apply results of the combined inference onto the binding of the inner invocation:
			TypeBinding[] solutions = getSolutions(original.typeVariables(), innerMessage, bounds);
			if (solutions == null) {
				if (binding instanceof ParameterizedGenericMethodBinding) {
					InferenceContext18 innerCtx = innerMessage.getInferenceContext((ParameterizedGenericMethodBinding) binding);
					if (innerCtx != null && !binding.isValidBinding()) {
						innerCtx.reportInvalidInvocation(innerMessage, binding);
					}
				}
				continue; // inner inference not requested -> not a problem
			}
			ParameterizedGenericMethodBinding innerBinding = this.environment.createParameterizedGenericMethod(original, solutions);
			
			if (innerMessage.updateBindings(innerBinding, innerTargetType)) { // only if we are actually improving anything
				ASTNode.resolvePolyExpressionArguments(innerMessage, innerBinding, this.scope);
			}
		}
	}
	this.stepCompleted = BINDINGS_UPDATED; // we're done-done
}