Example usage for org.eclipse.jdt.internal.compiler.lookup VariableBinding isValidBinding

List of usage examples for org.eclipse.jdt.internal.compiler.lookup VariableBinding isValidBinding

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup VariableBinding isValidBinding.

Prototype

public final boolean isValidBinding() 

Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.TypeAnchorReference.java

License:Open Source License

/**
 * Create a DependentTypeBinding from a type reference and a TypeAnchorReference.
 * Performs the following checks:/*from w  w w  .  j ava2  s  . co m*/
 * - does the type denoted by typeReference have a value parameter?
 * - does this anchor reference match the declared type of the corresponding value parameter?
 *
 * PRE: this.anchor and typeReference have already been resolved,
 *      however, resolving of typeReference has not yet considered any parameters.
 *
 * @param scope
 * @param typeReference     the type reference decorated with this type anchor.
 * @param typeParamPosition position within the type parameter list of the generic type
 * @return a DependentTypeBinding, or and array thereof or null;
 */
public TypeBinding createDependentTypeBinding(Scope scope, TypeReference typeReference, int typeParamPosition) {
    TypeBinding type = typeReference.resolvedType;
    ITeamAnchor anchorBinding = null;
    if (this.anchor instanceof NameReference)
        anchorBinding = (ITeamAnchor) ((NameReference) this.anchor).binding;
    else if (this.anchor instanceof FieldReference)
        anchorBinding = ((FieldReference) this.anchor).binding;
    if (anchorBinding != null && type instanceof ReferenceBinding && type.isValidBinding()) {
        ReferenceBinding refBinding = (ReferenceBinding) type;
        VariableBinding currentParam = refBinding.valueParamSynthArgAt(typeParamPosition);
        if (currentParam == null) {
            scope.problemReporter().typeHasNoValueParamAt(typeReference, refBinding, typeParamPosition);
            return null;
        }
        if (currentParam.type instanceof UnresolvedReferenceBinding) {
            currentParam.type = ((UnresolvedReferenceBinding) currentParam.type).resolve(scope.environment(),
                    false);
        }
        if (currentParam.isValidBinding()
                && !anchorBinding.isTypeCompatibleWith((ReferenceBinding) currentParam.type)) {
            scope.problemReporter().incompatibleValueParameter(this, currentParam);
            return null;
        }
        TypeBinding[] typeArguments = refBinding.isParameterizedType()
                ? ((ParameterizedTypeBinding) refBinding).arguments
                : null;
        return anchorBinding.getDependentTypeBinding(refBinding, typeParamPosition, typeArguments,
                typeReference.dimensions());
    } else {
        scope.problemReporter().invalidType(typeReference,
                new ProblemReferenceBinding(typeReference.getTypeName(), null, ProblemReasons.NotFound));
        return null;
    }
}