Example usage for org.eclipse.jdt.internal.compiler.lookup Scope enclosingReceiverType

List of usage examples for org.eclipse.jdt.internal.compiler.lookup Scope enclosingReceiverType

Introduction

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

Prototype

public final ReferenceBinding enclosingReceiverType() 

Source Link

Usage

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

License:Open Source License

ITeamAnchor resolveAnchor(Scope scope, Reference reference) {
    ITeamAnchor prefix = null;/*from w w  w. java2 s  .  c  o m*/
    ITeamAnchor currentAnchor = null;
    char[] currentToken = null; // for lookup and creation of problem binding

    // be careful not to trigger fields() which may be where we are called from!
    if (reference instanceof SingleNameReference) {
        SingleNameReference singleAnchor = (SingleNameReference) reference;
        currentToken = singleAnchor.token;
        currentAnchor = findVariable(scope, currentToken, scope.isStatic(), singleAnchor.sourceStart,
                singleAnchor.sourceEnd);
        this.anchor.bits |= (this.bits & DepthMASK);
        // could be ProblemAnchorBinding
    } else if (reference instanceof FieldReference) {
        FieldReference fieldRef = (FieldReference) reference;
        Expression prefixExpr = fieldRef.receiver;
        if (!(prefixExpr instanceof Reference))
            throw new InternalCompilerError("Unexpected anchor prefix " + prefixExpr); //$NON-NLS-1$
        prefix = resolveAnchor(scope, (Reference) prefixExpr);
        currentToken = fieldRef.token;
        // fieldRef holds on to problem binding:
        fieldRef.binding = TypeAnalyzer.findField(((ReferenceBinding) prefix.getResolvedType()).getRealClass(),
                currentToken, false/*static*/, true/*outer*/);
        currentAnchor = checkAnchor(scope, reference, currentToken, reference.sourceStart, reference.sourceEnd,
                fieldRef.binding);
    } else if (reference instanceof QualifiedBaseReference) {
        QualifiedBaseReference baseRef = (QualifiedBaseReference) reference;
        if (scope instanceof BlockScope)
            baseRef.resolveType((BlockScope) scope);
        else
            baseRef.resolveType((ClassScope) scope);
        currentAnchor = baseRef.baseField;
    } else if (reference instanceof QualifiedThisReference) {
        QualifiedThisReference thisRef = (QualifiedThisReference) reference;
        if (scope instanceof BlockScope)
            thisRef.resolveType((BlockScope) scope);
        else
            thisRef.resolveType((ClassScope) scope);
        if (thisRef.resolvedType.isTeam())
            currentAnchor = ((ReferenceBinding) thisRef.resolvedType).getTeamModel().getTThis();
    } else {
        boolean haveReportedProblem = false;
        long currentPos = 0;

        QualifiedNameReference qualifiedAnchor = (QualifiedNameReference) reference;
        char[][] tokens = qualifiedAnchor.tokens;
        currentToken = tokens[tokens.length - 1]; // default, so we never use null name for problem binding
        // check maximal static prefix:
        Binding staticPrefix = null;
        int j;
        for (j = 1; j <= tokens.length; j++) {
            Binding current = scope.getTypeOrPackage(CharOperation.subarray(tokens, 0, j));
            if (current == null || !current.isValidBinding())
                break;
            else
                staticPrefix = current;
        }
        if (j > tokens.length) {
            scope.problemReporter().typeAnchorReferenceNotAValue(reference);
            haveReportedProblem = true;
        } else {
            // find first field:
            if (staticPrefix != null) {
                currentPos = qualifiedAnchor.sourcePositions[j - 1];
                currentToken = tokens[j - 1];
                if (staticPrefix instanceof ReferenceBinding) {
                    currentAnchor = TypeAnalyzer.findField(((ReferenceBinding) staticPrefix).getRealClass(),
                            currentToken, /*static*/true, /*outer*/true);
                } else {
                    scope.problemReporter().typeAnchorReferenceNotAnObjectRef((int) (currentPos >>> 32),
                            (int) currentPos);
                    haveReportedProblem = true;
                }
            } else {
                currentPos = qualifiedAnchor.sourcePositions[0];
                currentToken = tokens[0];
                currentAnchor = findVariable(scope, currentToken, scope.isStatic(), (int) (currentPos >>> 32),
                        (int) currentPos);
                haveReportedProblem = currentAnchor == null;
            }
            if (currentAnchor != null) {
                if (!currentAnchor.hasValidReferenceType()) {
                    if (j < tokens.length) // would need to process more tokens?
                        currentAnchor = null; // replace with problem binding below
                } else {
                    // find more fields:
                    for (int i = j; i < tokens.length; i++) {
                        TypeBinding fieldType = currentAnchor.getResolvedType().leafComponentType();
                        if (fieldType instanceof SourceTypeBinding) {
                            SourceTypeBinding stb = (SourceTypeBinding) fieldType;
                            if ((stb.scope != null)
                                    && (stb.scope.compilationUnitScope() != scope.compilationUnitScope())
                                    && (stb.tagBits & (TagBits.BeginHierarchyCheck
                                            | TagBits.EndHierarchyCheck)) == (TagBits.BeginHierarchyCheck
                                                    | TagBits.EndHierarchyCheck)
                                    && StateHelper.isReadyToProcess(stb,
                                            ITranslationStates.STATE_LENV_DONE_FIELDS_AND_METHODS))
                                Dependencies.ensureBindingState(stb,
                                        ITranslationStates.STATE_LENV_DONE_FIELDS_AND_METHODS);
                        }
                        currentPos = qualifiedAnchor.sourcePositions[i];
                        currentToken = tokens[i];
                        FieldBinding nextField = currentAnchor.getFieldOfType(currentToken, /*static*/false,
                                true);
                        if (nextField == null || !nextField.hasValidReferenceType()) {
                            currentAnchor = null; // replace with problem binding below
                            break;
                        }
                        currentAnchor = nextField.setPathPrefix(currentAnchor);
                    }
                }
            }
        }
        if (!haveReportedProblem) {
            if (currentAnchor == null) {
                scope.problemReporter().typeAnchorNotFound(currentToken, (int) (currentPos >>> 32),
                        (int) currentPos);
            } else if (!currentAnchor.hasValidReferenceType()) {
                scope.problemReporter().typeAnchorReferenceNotAnObjectRef((int) (currentPos >>> 32),
                        (int) currentPos);
            }
        }
    }
    if (currentAnchor == null) {
        currentAnchor = new ProblemFieldBinding(scope.enclosingReceiverType(), currentToken,
                ProblemReasons.NotFound);
        ((FieldBinding) currentAnchor).type = reference.resolvedType = new ProblemReferenceBinding(
                "UnresolvedType".toCharArray(), null, ProblemReasons.NotFound); //$NON-NLS-1$
    } else if (currentAnchor.isValidBinding()) {
        if (prefix != null && !(prefix instanceof TThisBinding))
            currentAnchor = currentAnchor.setPathPrefix(prefix);

        // fill anchor with resolved data:
        reference.resolvedType = currentAnchor.getResolvedType();
        reference.bits &= ~RestrictiveFlagMASK; // clear bits
        if (currentAnchor instanceof FieldBinding) {
            reference.bits |= Binding.FIELD;
            // TODO(SH): must we remember a previous anchor to set this correctly?:
            if (reference instanceof NameReference)
                ((NameReference) reference).actualReceiverType = ((FieldBinding) currentAnchor).declaringClass;
            if (reference instanceof FieldReference)
                ((FieldReference) reference).actualReceiverType = ((FieldBinding) currentAnchor).declaringClass;
        } else {
            reference.bits |= Binding.LOCAL;
        }
        reference.constant = Constant.NotAConstant;
    }
    if (reference instanceof NameReference) {
        ((NameReference) reference).binding = (Binding) currentAnchor;
        ((NameReference) reference).resolveFinished();
    } else if (reference instanceof FieldReference) {
        ((FieldReference) reference).binding = (FieldBinding) currentAnchor;
        //TODO(SH): this method doesn't exist, is the call needed?
        //((FieldReference)this.anchor).resolveFinished();
    }
    return currentAnchor;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.OTClassScope.java

License:Open Source License

/**
 * @param parent        the semantically enclosing scope
 * @param roleUnitScope if it is a role file this scope stores the imports
 * @param otType        the referenceContext of this scope
 *///from w w w .  j a va  2 s  .  c  o m
private OTClassScope(Scope parent, CompilationUnitScope roleUnitScope, TypeDeclaration otType) {
    super(parent, otType);
    this.roleUnitImportScope = roleUnitScope;
    if (this.roleUnitImportScope != null)
        this.roleUnitImportScope.recordTypeReference(parent.enclosingReceiverType());
}