All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.jdt.internal.compiler.lookup.InferenceContext Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2000, 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.internal.compiler.lookup;

/**
 * Context used during type inference for a generic method invocation
 */
public class InferenceContext {

	private TypeBinding[][][] collectedSubstitutes;
	MethodBinding genericMethod;
	int depth;
	int status;
	TypeBinding expectedType;
	boolean hasExplicitExpectedType; // indicates whether the expectedType (if set) was explicit in code, or set by default
    public boolean isUnchecked;
	TypeBinding[] substitutes;
	final static int FAILED = 1;

public InferenceContext(MethodBinding genericMethod) {
	this.genericMethod = genericMethod;
	TypeVariableBinding[] typeVariables = genericMethod.typeVariables;
	int varLength = typeVariables.length;
	this.collectedSubstitutes = new TypeBinding[varLength][3][];
	this.substitutes = new TypeBinding[varLength];
}

public TypeBinding[] getSubstitutes(TypeVariableBinding typeVariable, int constraint) {
	return this.collectedSubstitutes[typeVariable.rank][constraint];
}

/**
 * Returns true if any unresolved variable is detected, i.e. any variable is substituted with itself
 */
public boolean hasUnresolvedTypeArgument() {
	for (int i = 0, varLength = this.substitutes.length; i :"); //$NON-NLS-1$
							break;
					}
					if (constraintCollected[k] != null) {
						buffer.append(constraintCollected[k].shortReadableName());
					}
				}
			}
		}
	}
	buffer.append("}]");//$NON-NLS-1$
	buffer.append("\n\t[inferred=");//$NON-NLS-1$
	int count = 0;
	for (int i = 0, length = this.substitutes == null ? 0 : this.substitutes.length; i < length; i++) {
		if (this.substitutes[i] == null) continue;
		count++;
		buffer.append('{').append(this.genericMethod.typeVariables[i].sourceName);
		buffer.append("=").append(this.substitutes[i].shortReadableName()).append('}'); //$NON-NLS-1$
	}
	if (count == 0) buffer.append("{}"); //$NON-NLS-1$
	buffer.append(']');
	return buffer.toString();
}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy