Example usage for org.eclipse.jdt.internal.compiler.ast Argument bind

List of usage examples for org.eclipse.jdt.internal.compiler.ast Argument bind

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast Argument bind.

Prototype

public TypeBinding bind(MethodScope scope, TypeBinding typeBinding, boolean used) 

Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementor.java

License:Open Source License

/**
 * Record that the base argument is equivalent to the base field.
 * @param newMethod/*from  w ww  .  j  a  v a2s.c  o  m*/
 */
private void setBaseArgBestName(MethodDeclaration newMethod, Argument baseArg) {
    // base arg is always first, so binding cannot disturb argument order.
    baseArg.bind(newMethod.scope, baseArg.type.resolvedType, false);
    ITeamAnchor baseArgBinding = newMethod.arguments[0].binding;
    // lookup _OT$base:
    ReferenceBinding roleBinding = this._role.getBinding();
    if (!roleBinding.isHierarchyInconsistent() && !this._role.hasBaseclassProblem()) // CLOVER: never false in jacks suite
    {
        // have no base field if hierarchy is inconsistent (see TPX-214).
        ITeamAnchor baseField = TypeAnalyzer.findField(roleBinding, IOTConstants._OT_BASE, /*static*/false,
                /*outer*/true, ITranslationStates.STATE_ROLE_HIERARCHY_ANALYZED);
        // link both vars:
        if (baseField != null) {
            baseArgBinding.shareBestName(baseField);
        } else if (roleBinding.isRegularInterface()) {
            // OK!?
        } else {
            // Notes: Observed this while preparing the NODe-tutorial.
            //        Reoccurred as TPX-491, fixed by v14499.
            throw new InternalCompilerError(
                    "Role has no base field: " + new String(roleBinding.readableName())); //$NON-NLS-1$
        }
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator.java

License:Open Source License

/**
 * Try to resolve an argument or return type as an anchored type.
 *
 * PRE: Regular type resolution has already failed.
 *
 * Currently only handles references of two components: anchor and Type.
 * (for parameters this is probably OK?)
 * NO: TODO(SH): arguments could also be anchored to arbitrary expressions/paths!
 *
  * @param type type reference to be analyzed (resolvedType is null or invalid)
 * @param arguments the arguments of the current method
 * @param index position of the argument to be analyzed
  *        == arguments.length means: analyzing return type.
 * @param scope scope of the current method.
 * @return a RoleTypeBinding or null (after reporting error)
 *//* w w w  .  ja  v  a 2s .  c o m*/
public static TypeBinding getTypeAnchoredToParameter(TypeReference type, Argument[] arguments, int index,
        MethodScope scope, CheckPoint cp) {
    // we only handle QualifiedTypeReferences of length 2, or QualifiedArrayTypeReferences.
    if (!(type instanceof QualifiedTypeReference)) {
        return null; // not better than before
    }
    QualifiedTypeReference argType = (QualifiedTypeReference) type;

    // look for anchor in argument list:
    VariableBinding anchor = null;
    char[] anchorName = argType.tokens[0];
    int argPos;
    for (argPos = 0; argPos < index; argPos++) {
        Argument argument = arguments[argPos];
        // ensure arguments are bound, which must happen in correct order.
        argument.bind(scope, argument.type.resolvedType, /*used*/false);
        if (CharOperation.equals(argument.name, anchorName)) // compare possible anchor
        {
            argument.binding.useFlag = LocalVariableBinding.USED; // used as anchor
            anchor = argument.binding;
            if (scope.classScope().referenceContext.isConverted)
                anchor.modifiers |= ClassFileConstants.AccFinal; // lost during conversion.
            break;
        }
    }
    if (anchor == null) {
        argPos = -1; // mark as not found in argument list
        anchor = findAnchorInScope(scope, anchorName);
    }
    if (anchor == null)
        return null; // not better than before.

    if (!anchor.isFinal()) {
        char[][] typeName = type.getTypeName();
        scope.problemReporter().anchorPathNotFinal(argType, anchor, typeName[typeName.length - 1]);
        return null;
    }

    // defensive programming:
    if (anchor.type == null)
        return null;
    // anchor must be a team:
    if (!anchor.type.isTeam()) {
        if (!anchor.type.isValidBinding())
            return null; //can't decide whether this is a valid team or not.
        reportAnchorIsNotATeam(scope, argType);
        return null;
    }

    // delegate for role type lookup:
    TypeBinding anchoredType = resolveOtherPathElements(scope, type, anchor, argType.tokens, 1,
            argType.dimensions());

    if (anchoredType != null) {
        if (!anchoredType.isValidBinding()) {
            scope.problemReporter().invalidType(type, anchoredType);
            return null;
        }
        if (anchoredType.leafComponentType().isRoleType()) {
            // prepare for creating an AnchorListAttribute
            RoleTypeBinding leafRoleType = (RoleTypeBinding) anchoredType.leafComponentType();
            leafRoleType._argumentPosition = argPos;
            final AbstractMethodDeclaration methodDecl = scope.referenceMethod();
            leafRoleType._declaringMethod = new DependentTypeBinding.IMethodProvider() {
                public MethodBinding getMethod() {
                    return methodDecl.binding;
                }
            };
        }
        scope.referenceContext.compilationResult().rollBack(cp);
        scope.problemReporter().deprecatedPathSyntax(type);
    }
    return anchoredType;
}