Example usage for org.eclipse.jdt.internal.compiler.lookup TagBits BeginHierarchyCheck

List of usage examples for org.eclipse.jdt.internal.compiler.lookup TagBits BeginHierarchyCheck

Introduction

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

Prototype

long BeginHierarchyCheck

To view the source code for org.eclipse.jdt.internal.compiler.lookup TagBits BeginHierarchyCheck.

Click Source Link

Usage

From source file:org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.java

License:Open Source License

/**
 * Returns true if the type hierarchy is being connected
 *//*from   w w  w  .jav a2 s  . c  o m*/
public boolean isHierarchyBeingConnected() {
    return (this.tagBits & TagBits.EndHierarchyCheck) == 0 && (this.tagBits & TagBits.BeginHierarchyCheck) != 0;
}

From source file:org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.java

License:Open Source License

/**
 * Returns true if the type hierarchy is being connected "actively" i.e not paused momentatrily, 
 * while resolving type arguments. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=294057
 *///from w  ww  . j ava  2s .  c om
public boolean isHierarchyBeingActivelyConnected() {
    return (this.tagBits & TagBits.EndHierarchyCheck) == 0 && (this.tagBits & TagBits.BeginHierarchyCheck) != 0
            && (this.tagBits & TagBits.PauseHierarchyCheck) == 0;
}

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 ww .j  a va2  s  . c  om
    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.statemachine.copyinheritance.CopyInheritance.java

License:Open Source License

private static void loadRoFiFromType(ReferenceBinding sourceTeam, TypeReference type,
        HashSet<String> processed) {
    if (type instanceof SingleTypeReference) {
        char[] typeName = ((SingleTypeReference) type).token;
        String typeString = new String(typeName);
        if (!processed.contains(typeString)) {
            ReferenceBinding rofi = sourceTeam.getMemberType(typeName);
            while (rofi != null && !rofi.isBinaryBinding()) {
                // if a rofi actually entered the compilation process it needs
                // to have its super types connected:
                SourceTypeBinding sourceRole = (SourceTypeBinding) rofi;
                if (sourceRole.scope != null && (sourceRole.tagBits & TagBits.BeginHierarchyCheck) == 0)
                    sourceRole.scope.connectTypeHierarchyWithoutMembers();
                // do the same for the class part, too?
                if (sourceRole.isSynthInterface()) {
                    rofi = sourceRole.getRealClass();
                    if (rofi != null && rofi.isInterface())
                        // observed an infinite loop, probably caused by rofi remaining unchanged by getRealClass above. Want to see why.
                        throw new InternalCompilerError("Role has no class-part"); //$NON-NLS-1$
                } else {
                    rofi = null; // terminate loop
                }//from   www .ja v  a2s.c om
            }

            processed.add(typeString);
        }
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.CopyInheritance.java

License:Open Source License

/**
 * If a tsuper role is not overriden in the current team,
 * create a fresh new role type declaration.
 * Always copy all inheritance information to the tsub role
 * (extends, implements, playedBy)./*from  w w w.j  a  va  2s. c o  m*/
 * No difference, whether we are looking at a role class or interface.
 *
 * @param superRole
 * @param subTeamDecl this declaration is being edited.
 * @return the new or modified type declaration
 */
private static TypeDeclaration copyRole(ReferenceBinding superRole, boolean isNestedType,
        TypeDeclaration subTeamDecl, boolean isTsuperTeam) {
    subTeamDecl.getTeamModel()._isCopyingLateRole = true;
    try {
        if (superRole instanceof MissingTypeBinding)
            return null; // don't copy missing type!
        if (superRole.sourceName == null)
            return null; // local types have null name
        String name = new String(superRole.sourceName);
        if ((name.startsWith(TSUPER_OT) || CharOperation.equals(superRole.sourceName, ROFI_CACHE)))
            return null; // don't copy these special roles

        if (subTeamDecl.isRole() && superRole.roleModel.equals(subTeamDecl.getRoleModel()))
            return null; // can happen in case of a role extending its enclosing

        TypeDeclaration subRoleDecl = findMemberType(subTeamDecl, superRole.sourceName);

        ReferenceBinding subRoleBinding = subTeamDecl.binding.getMemberType(superRole.internalName());
        if (subRoleBinding != null) {
            // don't copy binary tsuper, if a binary exists already here.
            if (shouldPreserveBinaryRole(subRoleBinding, subTeamDecl.compilationResult)) {
                if (isNestedType)
                    subRoleBinding.roleModel.maybeAddLocalToEnclosing();
                // no further processing needed except for connecting tsuper and copyInheritanceSrc:
                connectBinaryNested(superRole, subTeamDecl, subRoleBinding);
                return null;
            }
            // try again, memberType lookup might have introduced a role file to subTeamDecl:
            if (subRoleDecl == null)
                subRoleDecl = findMemberType(subTeamDecl, superRole.sourceName);
            if (subRoleDecl != null && (subRoleDecl.binding.tagBits & TagBits.BeginHierarchyCheck) == 0)
                subRoleDecl.scope.connectTypeHierarchyWithoutMembers();
            if (subRoleDecl == null) // still?
                return null; // assume recompile has been scheduled
        }

        // If type doesn't exist, create now
        if (subRoleDecl == null) {
            char[] superRoleName = superRole.internalName();
            if (superRole.isLocalType()) {
                if (!superRole.isBinaryBinding())
                    ((LocalTypeBinding) superRole).computeConstantPoolName();
                int lastDollar = CharOperation.lastIndexOf('$', superRole.sourceName);
                if (lastDollar >= 0) {
                    superRoleName = CharOperation.subarray(superRole.sourceName, lastDollar + 1, -1);
                } else {
                    char[] superConstantPoolName = superRole.constantPoolName();
                    lastDollar = CharOperation.lastIndexOf('$', superConstantPoolName);
                    if (lastDollar >= 0)
                        superRoleName = CharOperation.subarray(superConstantPoolName, lastDollar + 1, -1);
                }
            }
            subRoleDecl = AstConverter.createNestedType(superRoleName, superRole.modifiers, isNestedType, true, // purely copied
                    subTeamDecl, superRole);
            if (subRoleDecl.isInterface()) {
                // purely copied interface now copies superinterfaces (not handled in connectRolesFromTeam()):
                ReferenceBinding[] tsuperSupers = superRole.superInterfaces();
                subRoleDecl.binding.superInterfaces = new ReferenceBinding[tsuperSupers.length];
                int j = 0;
                for (int i = 0; i < tsuperSupers.length; i++) {
                    char[] tsuperSuperName = tsuperSupers[i].internalName();
                    if (!CharOperation.equals(tsuperSuperName, superRoleName)) {
                        ReferenceBinding tsubRole = subTeamDecl.binding.getMemberType(tsuperSuperName);
                        if (tsubRole != null)
                            subRoleDecl.binding.superInterfaces[j++] = tsubRole;
                    }
                }
                if (j < tsuperSupers.length)
                    System.arraycopy(subRoleDecl.binding.superInterfaces, 0,
                            subRoleDecl.binding.superInterfaces = new ReferenceBinding[j], 0, j);
            }
        } else {
            if (subRoleDecl.isRegularInterface() != superRole.isRegularInterface()) {
                subRoleDecl.scope.problemReporter().roleClassIfcConflict(subRoleDecl);
                // overwrite existing type with tsuper copy:
                subRoleDecl.isGenerated = true;
                subRoleDecl.isPurelyCopied = true;
                subRoleDecl.modifiers = superRole.modifiers;
                subRoleDecl.fields = null;
                subRoleDecl.methods = null;
                subRoleDecl.superclass = null;
                subRoleDecl.superInterfaces = null;
                SourceTypeBinding roleBinding = subRoleDecl.binding;
                roleBinding.modifiers = superRole.modifiers;
                roleBinding.setFields(Binding.NO_FIELDS);
                roleBinding.setMethods(Binding.NO_METHODS);
                roleBinding.baseclass = null;
                roleBinding.superclass = subTeamDecl.scope.getJavaLangObject();
                roleBinding.superInterfaces = Binding.NO_SUPERINTERFACES;
                return subRoleDecl;
            }
            if (superRole.isTeam() && !subRoleDecl.isTeam()) {
                if (!Protections.hasClassKindProblem(subRoleDecl.binding))
                    subRoleDecl.scope.problemReporter().regularOverridesTeam(subRoleDecl, superRole);
                subRoleDecl.modifiers |= ClassFileConstants.AccTeam;
                if (subRoleBinding != null)
                    subRoleBinding.modifiers |= ClassFileConstants.AccTeam;
            }
            if (!isTsuperTeam) {
                if (CharOperation.equals(subRoleDecl.name, OTCONFINED)) {
                    subRoleDecl.scope.problemReporter().overridingConfined(subRoleDecl, "Confined"); //$NON-NLS-1$
                    return null;
                }
                if (CharOperation.equals(subRoleDecl.name, ICONFINED)) {
                    subRoleDecl.scope.problemReporter().overridingConfined(subRoleDecl, "IConfined"); //$NON-NLS-1$
                    return null;
                }
                if (superRole.isFinal()) {
                    subRoleDecl.scope.problemReporter().overridingFinalRole(subRoleDecl, superRole);
                    return null;
                }
            }
        }

        superRole.roleModel.hasBaseclassProblem(); // just trigger propagation from super-role to current
        //      if (subRoleBinding != null && subRoleBinding.isBinaryBinding())
        //         subRoleDecl.scope.problemReporter().mismatchingRoleParts(subRoleBinding, subRoleDecl);
        return subRoleDecl;
    } finally {
        subTeamDecl.getTeamModel()._isCopyingLateRole = false;
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.CopyInheritance.java

License:Open Source License

private static boolean hasHiearchyCheckBegun(ReferenceBinding type) {
    if ((type.tagBits & TagBits.BeginHierarchyCheck) != 0)
        return true;
    if (type.enclosingType() != null)
        return hasHiearchyCheckBegun(type.enclosingType());
    return false;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.CopyInheritance.java

License:Open Source License

public static TypeDeclaration internalCheckCopyLateRoleFile(SourceTypeBinding teamBinding, char[] name) {
    ReferenceBinding superTeam = (ReferenceBinding) teamBinding.superclass().original(); // FIXME(SH): tsuper teams
    if (superTeam != null && superTeam.isTeam() && !TypeAnalyzer.isOrgObjectteamsTeam(superTeam)
            && !teamBinding._teamModel._isCopyingLateRole && !OTNameUtils.isTSuperMarkerInterface(name)) {
        ReferenceBinding tsuperRole = superTeam.getMemberType(name);
        if ((tsuperRole == null
                || (!tsuperRole.isValidBinding() && tsuperRole.problemId() == ProblemReasons.NotFound))
                && superTeam instanceof SourceTypeBinding) {
            TypeDeclaration tsuperDecl = internalCheckCopyLateRoleFile(((SourceTypeBinding) superTeam), name);
            if (tsuperDecl != null)
                tsuperRole = tsuperDecl.binding;
        }/*from w ww .j  a  v a2 s .co  m*/
        if (tsuperRole != null && tsuperRole.isRole() && tsuperRole.isValidBinding()
                && !tsuperRole.isLocalType()) {
            if ((teamBinding.tagBits & TagBits.BeginHierarchyCheck) != 0)
                return copyLateRole(teamBinding._teamModel.getAst(), tsuperRole);
            else
                return copyLateRolePart(teamBinding._teamModel.getAst(), tsuperRole);
        }
    }
    return null;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.CopyInheritance.java

License:Open Source License

public static TypeDeclaration copyLateRole(TypeDeclaration teamDecl, ReferenceBinding tsuperRole) {
    TypeDeclaration roleType = null;//from   w w w . j a v  a2 s  .co m
    ReferenceBinding ifcPart = null;
    char[] tsuperName = tsuperRole.internalName();
    if (CharOperation.prefixEquals(IOTConstants.OT_DELIM_NAME, tsuperName)) {
        char[] ifcName = CharOperation.subarray(tsuperName, IOTConstants.OT_DELIM_LEN, -1);
        ifcPart = teamDecl.binding.getMemberType(ifcName);
    }
    roleType = copyLateRolePart(teamDecl, tsuperRole);
    if (ifcPart != null) {
        ReferenceBinding superTeam = tsuperRole.enclosingType();
        if ((superTeam.tagBits & TagBits.BeginHierarchyCheck) == 0)
            Dependencies.ensureBindingState(superTeam, ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY);
        if (StateHelper.hasState(tsuperRole, ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY)) {
            RoleModel subRole = roleType.getRoleModel();
            TypeLevel.connectRoleClasses(superTeam, roleType);
            setRoleState(subRole, STATE_LENV_CONNECT_TYPE_HIERARCHY);
        }
    }
    if (roleType == null)
        return null;
    Dependencies.lateRolesCatchup(teamDecl.getTeamModel());
    return roleType;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.TypeLevel.java

License:Open Source License

/**
 * Add the "implements" link that connects a sub-role-ifc to
 * its implicit super-role-ifc.//from w ww  .j a  v  a  2s.  c om
 * Also checks compatibility of visibilities.
 * @param roleInterfaceDeclaration
 * @param superrole
 */
public static void addImplicitInheritance(TypeDeclaration roleInterfaceDeclaration,
        ReferenceBinding superrole) {
    assert (roleInterfaceDeclaration.binding.tagBits
            & TagBits.BeginHierarchyCheck) != 0 : "binding should be connected"; //$NON-NLS-1$
    int modifiers = roleInterfaceDeclaration.modifiers;
    int inheritedModifiers = superrole.modifiers;
    if (!Protections.isAsVisible(modifiers, inheritedModifiers)) {
        roleInterfaceDeclaration.scope.problemReporter().reducingRoleVisibility(roleInterfaceDeclaration,
                modifiers, inheritedModifiers);
    }
    // create bindings:
    ReferenceBinding[] superInterfaces = roleInterfaceDeclaration.binding.superInterfaces;
    ReferenceBinding[] newSuperInterfaces = null;
    int len = 0;
    if (superInterfaces != null) {
        for (int i = 0; i < superInterfaces.length; i++)
            if (TypeBinding.equalsEquals(superInterfaces[i], superrole))
                return; // superinterface already present.
        len = superInterfaces.length;
        newSuperInterfaces = new ReferenceBinding[len + 1];
        System.arraycopy(superInterfaces, 0, newSuperInterfaces, 0, len);
    } else {
        newSuperInterfaces = new ReferenceBinding[1];
    }

    // this line cannot assign null, would have produced NPE above:
    newSuperInterfaces[len] = superrole;
    roleInterfaceDeclaration.scope.compilationUnitScope().recordSuperTypeReference(superrole);
    roleInterfaceDeclaration.binding.superInterfaces = newSuperInterfaces;
}

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

License:Open Source License

/**
 * Adds a new binding in the superInterfaces array of type's binding
 * @param typeDeclaration/*  w  w  w. ja v  a  2s. com*/
 * @param resolvedSuper
 */
public static void addImplementsBinding(TypeDeclaration typeDeclaration, ReferenceBinding resolvedSuper) {
    boolean bindingPresent = typeDeclaration.binding != null
            && ((typeDeclaration.binding.tagBits & TagBits.BeginHierarchyCheck) != 0);
    assert (resolvedSuper != null && bindingPresent);
    SourceTypeBinding typeBinding = typeDeclaration.binding;
    ReferenceBinding[] superInterfaces = typeBinding.superInterfaces;
    int length = 0;
    if (superInterfaces == null) {
        superInterfaces = new ReferenceBinding[1];
    } else {
        for (ReferenceBinding superIfc : superInterfaces)
            if (TypeBinding.equalsEquals(superIfc, resolvedSuper))
                return; // already present

        length = superInterfaces.length;
        System.arraycopy(superInterfaces, 0, (superInterfaces = new ReferenceBinding[length + 1]), 1, length);
    }
    superInterfaces[0] = resolvedSuper;

    typeBinding.superInterfaces = superInterfaces;
    // compatibility may have changed, clear negative cache entries:
    typeBinding.resetIncompatibleTypes();
}