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

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

Introduction

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

Prototype

long ClearPrivateModifier

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

Click Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.FieldModel.java

License:Open Source License

public void setBinding(FieldBinding fieldBinding) {
    if (this._binding != null)
        assert this._binding == fieldBinding;
    this._binding = fieldBinding;
    fieldBinding.model = this;

    if (this._clearPrivateModifier)
        fieldBinding.tagBits |= TagBits.ClearPrivateModifier;

}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel.java

License:Open Source License

public void storeModifiers(int modifiers) {
    addAttribute(WordValueAttribute//ww  w .ja va  2s .c o m
            .roleClassMethodModifiersAttribute(modifiers & MethodModel.AccIfcMethodModiferMASK));
    this._clearPrivateModifier = true;
    if (this._binding != null)
        this._binding.tagBits |= TagBits.ClearPrivateModifier;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.RoleSplitter.java

License:Open Source License

/**
 * After bindings have been created the synthetic interface is setup
 * to mirror the extends of the role class.
 * This method only treats the case of regular superclasses:
 *   + copy signatures for all methods that are directly or inderictly
 *     inherited (not including java.lang.Object).
 * (role superclasses are treated in linkSuperAndBaseInIfc()).
 *
 * @param teamDecl//w  w w .  j a  v a 2 s . com
 * @param roleClass
 * @param roleIfcDecl
 */
public static void setupInterfaceForExtends(TypeDeclaration teamDecl, TypeDeclaration roleClass,
        TypeDeclaration roleIfcDecl) {
    ReferenceBinding superClass = roleClass.binding.superclass();
    if (superClass == null)
        return; // current must be Confined
    if (superClass.isDirectRole()
            && !CharOperation.equals(superClass.internalName(), IOTConstants.OTCONFINED)) {
        return; // already processed in linkSuperAndBaseInIfc()
    }
    ReferenceBinding[] tsupers = roleClass.getRoleModel().getTSuperRoleBindings();
    for (ReferenceBinding tsuperRole : tsupers)
        if (TypeBinding.equalsEquals(tsuperRole.superclass(), superClass))
            return; // already included via tsuper.

    // workaround for mixed binary/source roles (cause for this situation unknown):
    if (roleIfcDecl == null)
        return;

    ReferenceBinding ifcBinding = roleIfcDecl.binding;
    ReferenceBinding javaLangObject = teamDecl.scope.getJavaLangObject();

    AstGenerator gen;
    if (roleClass.superclass != null)
        gen = new AstGenerator(roleClass.superclass.sourceStart, roleClass.superclass.sourceEnd);
    else
        gen = new AstGenerator(roleClass.sourceStart, roleClass.sourceEnd);

    while (superClass != null && TypeBinding.notEquals(superClass, javaLangObject)) {
        MethodBinding[] methods = superClass.methods();
        methodLoop: for (int i = 0; i < methods.length; i++) {
            MethodBinding m = methods[i];
            if (m.isConstructor())
                continue; // not inherited
            if (m.isPrivate())
                continue; // not inherited
            if (m.isStatic())
                continue; // not applicable in roles
            if (!m.isPublic()) { // not visible via interface
                MethodBinding existingMethod = TypeAnalyzer.findMethod(roleIfcDecl.scope, ifcBinding,
                        m.selector, m.parameters);
                if (existingMethod != null && existingMethod.isValidBinding())
                    continue;
                ProblemMethodBinding problemMethod = new ProblemMethodBinding(m, m.selector, m.parameters,
                        ProblemReasons.NotVisible);
                problemMethod.modifiers = m.modifiers;
                problemMethod.modifiers |= AccAbstract | AccSemicolonBody; // don't confuse the MethodVerifier with class method in ifc
                problemMethod.thrownExceptions = m.thrownExceptions;
                problemMethod.returnType = m.returnType;
                MethodModel.getModel(problemMethod).problemDetail = ProblemDetail.RoleInheritsNonPublic;
                ifcBinding.addMethod(problemMethod); // adding binding only as to support error reporting without generating new code
                continue;
            }

            for (int j = 0; j < IOTConstants.OT_KEYWORDS.length; j++) {
                if (CharOperation.equals(m.selector, IOTConstants.OT_KEYWORDS[j])) {
                    roleClass.scope.problemReporter().inheritedNameIsOTKeyword(m, gen.sourceStart,
                            gen.sourceEnd);
                    continue methodLoop;
                }
            }
            MethodBinding declaredMethod = TypeAnalyzer.findCompatibleMethod(ifcBinding, m);

            if (declaredMethod == null) {
                MethodDeclaration newmethod = AstConverter.genIfcMethodFromBinding(teamDecl, m, gen);

                // the following also creates bindings, which helps to avoid
                // entering the same signature twice
                // (next time findCompatibleMethod() above will also find the new method).
                boolean wasSynthetic = false;
                if ((newmethod.modifiers & AccSynthetic) != 0) {
                    wasSynthetic = true;
                    newmethod.modifiers &= ~AccSynthetic;
                }
                AstEdit.addMethod(roleIfcDecl, newmethod, wasSynthetic, false, null/*copyInheritanceSrc*/);
                if (newmethod.binding != null) {
                    newmethod.binding.tagBits |= TagBits.ClearPrivateModifier;
                    newmethod.binding.copyInheritanceSrc = m;
                }
            } else {
                if (!Protections.isAsVisible(declaredMethod.modifiers, m.modifiers))
                    roleClass.scope.problemReporter().visibilityConflict(declaredMethod, m);
            }
        }
        superClass = superClass.superclass();
    }

}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.StandardElementGenerator.java

License:Open Source License

/**
 * Retreive (or create) a team level method used for casting an expression to a role.
 * After casting also check the containingInstance against the current team.
 * @param teamModel//from w ww  . j ava2 s . c  o  m
 * @param roleType
 * @param scope (used only for lookup of j.l.Object)
 * @param searchSuper  should super classes of teamClass be search, too?
 * @param sourceStart
 * @param sourceEnd
 * @return the method
 */
public static MethodBinding getCastMethod(TeamModel teamModel, ReferenceBinding roleType, Scope scope,
        int dimensions, boolean searchSuper, int sourceStart, int sourceEnd) {
    /*
     * protected <role> _OT$castTo$<role> (Object _OT$arg1) {
     *    if (_OT$arg1 == null) return null;
     *      __OT__<role> role = (__OT__<role>) _OT$arg1;
     *    if (role._OT$getTeam() != this)
     *         throw new RuntimeException();
     *    return role;
     * }
     *OR FOR ARRAY:
     * protected <role>[].. _OT$castTo$<role>$<dims> (Object[].. _OT$arg1) {
     *    if (_OT$arg1 == null) return null;
     *      <role>[].. role = (<role>[]..) _OT$arg1;
     *    if (role.length > 0 && ((__OT__<role>)role[0])._OT$getTeam() != this) // TODO(SH): extract through several dims
     *         throw new RuntimeException();
     *    return role;
     * }
     * NOTE(SH): it suffices to check team equivalence for one element, since at this point it
     *           must already be a role-array, which cannot mix roles from different teams ;-)
     */
    boolean shouldWeaken = (teamModel.getState() >= ITranslationStates.STATE_TYPES_ADJUSTED); // weakening for other methods already done?
    MethodBinding superMethod = null;

    roleType = roleType.getRealType();
    char[] methodName = CharOperation.concat(CAST_PREFIX, roleType.sourceName());
    if (dimensions > 0)
        methodName = CharOperation.concat(methodName, String.valueOf(dimensions).toCharArray(), '$');
    ReferenceBinding teamBinding = teamModel.getBinding();
    while (teamBinding != null) {
        MethodBinding[] methods = teamBinding.getMethods(methodName);
        if (methods != null && methods.length == 1) {
            if (TypeBinding.equalsEquals(methods[0].declaringClass, teamModel.getBinding()) || searchSuper)
                return methods[0];
            // go ahead and generate a new method, but use superMethod for weakening after generating:
            superMethod = methods[0];
            break;
        }
        if (!searchSuper && !shouldWeaken)
            break;
        teamBinding = teamBinding.superclass();
    }

    TypeDeclaration teamClass = teamModel.getAst();
    if (teamClass == null) {
        if (true) {// FIXME(SH): team has error?
            MethodBinding castMethod = new MethodBinding(AccPublic, methodName, roleType,
                    new TypeBinding[] { scope.getJavaLangObject() }, null, teamModel.getBinding());
            teamModel.getBinding().addMethod(castMethod);
            return castMethod;
        }
        throw new InternalCompilerError("Required cast method not found."); //$NON-NLS-1$
    }

    AstGenerator gen = new AstGenerator(sourceStart, sourceEnd);

    // --- method header ---
    int modifiers = 0;
    boolean clearPrivateModifier = false;
    if (roleType.isPublic()) {
        modifiers = AccPublic;
    } else {
        // this weird combination allows to return a non-public role and will
        // grant access across packages in the byte code.
        modifiers = AccProtected;
        clearPrivateModifier = true;
        // See also BinaryTypeBinding.resolveTypesFor(MethodBinding) where the Protected flag is restored.
    }
    // args
    char[] argName = OT_DOLLAR_ARG.toCharArray();

    // find the appropriate top-level-super-type:
    ReferenceBinding exprType = teamClass.scope.getJavaLangObject();
    //      if (!roleType.isStrictlyCompatibleWith(exprType)) {
    //         exprType = (ReferenceBinding)teamClass.scope.getType(ORG_OBJECTTEAMS_ICONFINED, 3);
    //         if (!roleType.isCompatibleWith(exprType))
    //            exprType = (ReferenceBinding)teamClass.scope.getType(
    //                  ORG_OBJECTTEAMS_TEAM_DOT_CONFINED,
    //                  4);
    //      }
    TypeReference exprTypeRef = gen.typeReference(exprType);

    MethodDeclaration castMethod = gen.method(teamClass.compilationResult(), modifiers,
            gen.createArrayTypeReference(roleType, dimensions), methodName,
            new Argument[] { gen.argument(argName, exprTypeRef) });
    // see org.eclipse.objectteams.otdt.tests.otjld.regression.ReportedBugs.testB11_sh15():
    // pre-set return type to prevent problems with resolving lateron
    TypeBinding returnType = dimensions == 0 ? roleType
            : scope.environment().createArrayType(roleType, dimensions);
    castMethod.returnType.resolvedType = RoleTypeCreator.maybeWrapUnqualifiedRoleType(returnType, teamBinding);

    // <role> role = (<role>)_OT$arg;
    TypeReference arrayCastType = gen.createArrayTypeReference(roleType, dimensions);
    LocalDeclaration castedLocalVar = gen.localVariable(ROLE, arrayCastType,
            gen.castExpression(gen.singleNameReference(argName), arrayCastType, CastExpression.RAW));

    //STATEMENTS:
    // if (_OT$arg1 == null) return null;
    //AND
    //   if (role._OT$getTeam() != this)
    //      throw new RuntimeException();
    //  OR
    //   if (role.length > 0 && ((<roleClass>)role[0])._OT$getTeam() != this)
    //      throw new RuntimeException();

    Statement nullCheck = gen.ifStatement(gen.nullCheck(gen.singleNameReference(argName)),
            gen.returnStatement(gen.nullLiteral()));

    Expression teamCheckCondition;
    teamCheckCondition = genTeamCheck(gen, OperatorIds.NOT_EQUAL, gen.singleNameReference(ROLE),
            gen.thisReference(), dimensions);

    if (dimensions > 0)
        teamCheckCondition = gen
                .setPos(new AND_AND_Expression(
                        gen.equalExpression(gen.qualifiedNameReference(new char[][] { ROLE, LENGTH }),
                                gen.intLiteral(0), OperatorIds.GREATER),
                        teamCheckCondition, OperatorIds.AND_AND));

    // here we go:
    castMethod.setStatements(new Statement[] { nullCheck, castedLocalVar, gen.ifStatement(teamCheckCondition,
            gen.throwStatement(
                    gen.allocation(gen.qualifiedTypeReference(ROLE_CAST_EXCEPTION), new Expression[0]))),
            // return role;
            gen.returnStatement(gen.singleNameReference(ROLE)) });
    castMethod.isGenerated = true;
    AstEdit.addGeneratedMethod(teamClass, castMethod);
    if (clearPrivateModifier)
        castMethod.binding.tagBits = TagBits.ClearPrivateModifier;

    if (superMethod != null)
        CopyInheritance.weakenSignature(castMethod, superMethod);
    return castMethod.binding;
}

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

License:Open Source License

/**
 * add a field to TypeDeclaration//from  w  w  w  .  j ava 2s.c om
 * @param decl
 * @param field
 * @param createBinding should FieldBinding be created?
 * @param hasTypeProblem
 * @param addToFront  should the field be inserted at the front of the array?
 */
public static void addField(TypeDeclaration decl, FieldDeclaration field, boolean createBinding,
        boolean hasTypeProblem, boolean addToFront) {
    if (field.declarationSourceStart <= 0 || field.declarationSourceEnd <= 0 || field.declarationEnd <= 0
            || field.sourceStart <= 0 || field.sourceEnd <= 0) {
        //throw new InternalCompilerError("Generated field is missing some source range information.");
        //System.err.println("Generated field is missing some source range information: " + String.valueOf(field.name));
    }

    int length;
    FieldDeclaration[] fields;
    if ((fields = decl.fields) == null) {
        length = 0;
        fields = new FieldDeclaration[1];
    } else {
        length = fields.length;
        System.arraycopy(fields, 0, (fields = new FieldDeclaration[length + 1]), addToFront ? 1 : 0, length);
    }

    if (addToFront)
        fields[0] = field;
    else
        fields[length] = field;

    decl.fields = fields;
    boolean modifiersAdjusted = FieldModel.checkCreateModifiersAttribute(decl, field);
    if (decl.binding != null && createBinding) {
        FieldBinding binding = decl.scope.addGeneratedField(field, hasTypeProblem);
        if (modifiersAdjusted)
            binding.tagBits |= TagBits.ClearPrivateModifier;
    }
}

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

License:Open Source License

/**
 * Adds a new Method to TypeDeclaration and resolve its types.
 *
    * @param classTypeDeclaration/*from  w  w  w  .j a  va  2  s . c o  m*/
 * @param methodDeclaration
 * @param wasSynthetic was the method copied from a synthetic method?
 * @param addToFront should the method be added to the front of 'methods'?
 * @param copyInheritanceSrc tsuper method from which this method is copied
  */
public static void addMethod(TypeDeclaration classTypeDeclaration, AbstractMethodDeclaration methodDeclaration,
        boolean wasSynthetic, boolean addToFront, MethodBinding copyInheritanceSrc) {
    boolean modifiersAdjusted = addMethodDeclOnly(classTypeDeclaration, methodDeclaration, addToFront);
    if (classTypeDeclaration.binding != null) {
        classTypeDeclaration.binding.resolveGeneratedMethod(methodDeclaration, wasSynthetic,
                copyInheritanceSrc);
        if (modifiersAdjusted)
            methodDeclaration.binding.tagBits |= TagBits.ClearPrivateModifier;
    }
}