Example usage for org.eclipse.jdt.internal.compiler.lookup ExtraCompilerModifiers AccLocallyUsed

List of usage examples for org.eclipse.jdt.internal.compiler.lookup ExtraCompilerModifiers AccLocallyUsed

Introduction

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

Prototype

int AccLocallyUsed

To view the source code for org.eclipse.jdt.internal.compiler.lookup ExtraCompilerModifiers AccLocallyUsed.

Click Source Link

Usage

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

License:Open Source License

void checkMethods() {
    boolean mustImplementAbstractMethods = mustImplementAbstractMethods();
    boolean skipInheritedMethods = mustImplementAbstractMethods && canSkipInheritedMethods(); // have a single concrete superclass so only check overridden methods
    boolean isOrEnclosedByPrivateType = this.type.isOrEnclosedByPrivateType();
    char[][] methodSelectors = this.inheritedMethods.keyTable;
    nextSelector: for (int s = methodSelectors.length; --s >= 0;) {
        if (methodSelectors[s] == null)
            continue nextSelector;

        MethodBinding[] current = (MethodBinding[]) this.currentMethods.get(methodSelectors[s]);
        MethodBinding[] inherited = (MethodBinding[]) this.inheritedMethods.valueTable[s];

        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660, if current type is exposed,
        // inherited methods of super classes are too. current != null case handled below.
        if (current == null && !isOrEnclosedByPrivateType) {
            int length = inherited.length;
            for (int i = 0; i < length; i++) {
                inherited[i].original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
            }//from w w  w  . j a v  a2s .c  o  m
        }
        if (current == null && this.type.isPublic()) {
            int length = inherited.length;
            for (int i = 0; i < length; i++) {
                MethodBinding inheritedMethod = inherited[i];
                if (inheritedMethod.isPublic() && !inheritedMethod.declaringClass.isPublic())
                    this.type.addSyntheticBridgeMethod(inheritedMethod.original());
            }
        }

        if (current == null && skipInheritedMethods)
            continue nextSelector;

        if (inherited.length == 1 && current == null) { // handle the common case
            if (mustImplementAbstractMethods && inherited[0].isAbstract())
                checkAbstractMethod(inherited[0]);
            continue nextSelector;
        }

        int index = -1;
        int inheritedLength = inherited.length;
        MethodBinding[] matchingInherited = new MethodBinding[inheritedLength];
        MethodBinding[] foundMatch = new MethodBinding[inheritedLength]; // null is no match, otherwise value is matching currentMethod
        if (current != null) {
            for (int i = 0, length1 = current.length; i < length1; i++) {
                MethodBinding currentMethod = current[i];
                MethodBinding[] nonMatchingInherited = null;
                for (int j = 0; j < inheritedLength; j++) {
                    MethodBinding inheritedMethod = computeSubstituteMethod(inherited[j], currentMethod);
                    if (inheritedMethod != null) {
                        if (foundMatch[j] == null
                                && isSubstituteParameterSubsignature(currentMethod, inheritedMethod)) {
                            matchingInherited[++index] = inheritedMethod;
                            foundMatch[j] = currentMethod;
                        } else {
                            // best place to check each currentMethod against each non-matching inheritedMethod
                            checkForNameClash(currentMethod, inheritedMethod);
                            if (inheritedLength > 1) {
                                if (nonMatchingInherited == null)
                                    nonMatchingInherited = new MethodBinding[inheritedLength];
                                nonMatchingInherited[j] = inheritedMethod;
                            }
                        }
                    }
                }
                if (index >= 0) {
                    // see addtional comments in https://bugs.eclipse.org/bugs/show_bug.cgi?id=122881
                    // if (index > 0 && currentMethod.declaringClass.isInterface()) // only check when inherited methods are from interfaces
                    //   checkInheritedReturnTypes(matchingInherited, index + 1);
                    checkAgainstInheritedMethods(currentMethod, matchingInherited, index + 1,
                            nonMatchingInherited); // pass in the length of matching
                    while (index >= 0)
                        matchingInherited[index--] = null; // clear the contents of the matching methods
                }
            }
        }

        // skip tracks which inherited methods have matched other inherited methods
        // either because they match the same currentMethod or match each other
        boolean[] skip = new boolean[inheritedLength];
        for (int i = 0; i < inheritedLength; i++) {
            MethodBinding matchMethod = foundMatch[i];
            if (matchMethod == null && current != null && this.type.isPublic()) { // current == null case handled already.
                MethodBinding inheritedMethod = inherited[i];
                if (inheritedMethod.isPublic() && !inheritedMethod.declaringClass.isPublic()) {
                    this.type.addSyntheticBridgeMethod(inheritedMethod.original());
                }
            }
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660, if current type is exposed,
            // inherited methods of super classes are too. current == null case handled already.
            if (!isOrEnclosedByPrivateType && matchMethod == null && current != null) {
                inherited[i].original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
            }
            if (skip[i])
                continue;
            MethodBinding inheritedMethod = inherited[i];
            if (matchMethod == null)
                matchingInherited[++index] = inheritedMethod;
            for (int j = i + 1; j < inheritedLength; j++) {
                MethodBinding otherInheritedMethod = inherited[j];
                if (matchMethod == foundMatch[j] && matchMethod != null)
                    continue; // both inherited methods matched the same currentMethod
                if (canSkipInheritedMethods(inheritedMethod, otherInheritedMethod))
                    continue;
                // Skip the otherInheritedMethod if it is completely replaced by inheritedMethod
                // This elimination used to happen rather eagerly in computeInheritedMethods step
                // itself earlier. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358)
                if (inheritedMethod.declaringClass != otherInheritedMethod.declaringClass) {
                    if (otherInheritedMethod.declaringClass.isInterface()) {
                        if (isInterfaceMethodImplemented(otherInheritedMethod, inheritedMethod,
                                otherInheritedMethod.declaringClass)) {
                            skip[j] = true;
                            continue;
                        }
                    } else if (areMethodsCompatible(inheritedMethod, otherInheritedMethod)) {
                        skip[j] = true;
                        continue;
                    }
                }
                otherInheritedMethod = computeSubstituteMethod(otherInheritedMethod, inheritedMethod);
                if (otherInheritedMethod != null) {
                    if (isSubstituteParameterSubsignature(inheritedMethod, otherInheritedMethod)) {
                        if (index == -1)
                            matchingInherited[++index] = inheritedMethod;
                        if (foundMatch[j] == null)
                            matchingInherited[++index] = otherInheritedMethod;
                        skip[j] = true;
                    } else if (matchMethod == null && foundMatch[j] == null) {
                        checkInheritedMethods(inheritedMethod, otherInheritedMethod);
                    }
                }
            }
            if (index == -1)
                continue;

            if (index > 0)
                checkInheritedMethods(matchingInherited, index + 1); // pass in the length of matching
            else if (mustImplementAbstractMethods && matchingInherited[0].isAbstract() && matchMethod == null)
                checkAbstractMethod(matchingInherited[0]);
            while (index >= 0)
                matchingInherited[index--] = null; // clear the previous contents of the matching methods
        }
    }
}

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

License:Open Source License

/**
 * Answer true if the receiver has private visibility and is used locally
 *///from  w  w  w  .  j a  v  a2  s . c o  m
public final boolean isUsed() {
    return (this.modifiers & ExtraCompilerModifiers.AccLocallyUsed) != 0;
}

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

License:Open Source License

public void tagIndirectlyAccessibleMembers() {
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=328281
    for (int i = 0; i < this.fields.length; i++) {
        if (!this.fields[i].isPrivate())
            this.fields[i].modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
    }//from www. ja v a2 s  .c om
    for (int i = 0; i < this.memberTypes.length; i++) {
        if (!this.memberTypes[i].isPrivate())
            this.memberTypes[i].modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
    }
    if (this.superclass.isPrivate())
        if (this.superclass instanceof SourceTypeBinding) // should always be true because private super type can only be accessed in same CU
            ((SourceTypeBinding) this.superclass).tagIndirectlyAccessibleMembers();
}

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

License:Open Source License

public void analyseCode(ClassScope classScope, InitializationFlowContext initializationContext, FlowInfo info) {
    if (this.statements != null) {
        if (this.binding != null)
            this.binding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; // avoid unused-warning
        super.analyseCode(classScope, initializationContext, info);
    }/*from   w  w w .  j  a va 2 s.  c  o  m*/
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.LiftingEnvironment.java

License:Open Source License

/**
 * Create a method that initializes all caches introduced in a given team.
 * Only create method declaration, no statements yet.
 * (see fillGeneratedMethods())./*from  w  ww . jav a 2 s  . c o m*/
 *
 * @param teamType the type to add the method to.
 * @return the _OT$initCaches method
 */
private static MethodDeclaration generateInitCaches(TypeDeclaration teamType) {
    MethodDeclaration initMethod = AstConverter.findAndAdjustCopiedMethod(teamType, IOTConstants.OT_INIT_CACHES,
            null);
    if (initMethod == null) {
        AstGenerator gen = new AstGenerator(teamType.sourceStart, teamType.sourceEnd);
        gen.shiftPosition(); // don't let @SuppressWarnings interfere with non-generated code.

        initMethod = gen.method(teamType.compilationResult, ClassFileConstants.AccPrivate, // no overriding!!
                TypeBinding.BOOLEAN, IOTConstants.OT_INIT_CACHES, null);
        initMethod.statements = new Statement[0]; // to be filled by fillInitCaches()
        initMethod.annotations = new Annotation[] { // in case base type is a raw type
                gen.singleStringsMemberAnnotation(TypeConstants.JAVA_LANG_SUPPRESSWARNINGS,
                        new char[][] { "all".toCharArray() }) //$NON-NLS-1$   
        };
        AstEdit.addMethod(teamType, initMethod);
        initMethod.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; // prevent 'unused' warning

        if (teamType.isRole()) {
            TypeDeclaration ifcPart = teamType.getRoleModel().getInterfaceAst();
            if (ifcPart != teamType) {
                AbstractMethodDeclaration methodIfcPart = TypeAnalyzer.findMethodDecl(ifcPart,
                        IOTConstants.OT_INIT_CACHES, 0);
                if (methodIfcPart == null) {
                    methodIfcPart = AstConverter.genRoleIfcMethod(teamType.enclosingType, initMethod);
                    AstEdit.addMethod(ifcPart, methodIfcPart);
                }
            }
        }

        // Serialization: generate restore methods to initialize caches/register roles:
        SerializationGenerator.generateRestoreMethods(teamType, gen);
    }

    return initMethod;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.LiftingEnvironment.java

License:Open Source License

private static void fillInitCaches(TypeDeclaration teamType, FieldDeclaration[] caches) {
    /*/* ww w  . j ava 2  s.co  m*/
     * generate:
     * {
     *       // for each cache declared in this team:
     *       if (_OT$cache<x> == null) {
     *          _OT$cache<c> = new WeakHashMap<Bx,Rx>();
     *      }
     *      // Note: no super call, super team's ctor is already responsible for invoking its (private) initCaches
     * }
     */
    AbstractMethodDeclaration initMethod = TypeAnalyzer.findMethodDecl(teamType, IOTConstants.OT_INIT_CACHES,
            0);
    if (initMethod == null) {
        // not yet generated? (maybe no bound roles/caches at that time).
        if (teamType.getTeamModel().caches.length == 0)
            return;
        initMethod = generateInitCaches(teamType);
    }
    AstGenerator gen = new AstGenerator(initMethod); // re-use position
    Statement[] statements = new Statement[caches.length + 1];
    for (int i = 0; i < caches.length; i++) {
        // FIXME(SH): unclear if needed after allowing generated qualified role type referneces:
        TypeReference cacheTypeRef = caches[i].type; // robustness, but with wrong source position
        if (caches[i].type.resolvedType instanceof ParameterizedTypeBinding) {
            // reconstruct a type reference from the resolved cache type
            ParameterizedTypeBinding oldBinding = (ParameterizedTypeBinding) cacheTypeRef.resolvedType;
            if (oldBinding.arguments.length == 2) {
                ReferenceBinding roleBinding = (ReferenceBinding) oldBinding.arguments[1];
                // respect different status for base/role types (scope, decapsulation).
                cacheTypeRef = gen.getCacheTypeReference(teamType.scope, roleBinding.roleModel);
            }
        }
        statements[i] = gen.ifStatement(
                new EqualExpression(gen.singleNameReference(caches[i].name), gen.nullLiteral(),
                        OperatorIds.EQUAL_EQUAL),
                gen.block(new Statement[] { gen.assignment(gen.singleNameReference(caches[i].name),
                        gen.allocation(cacheTypeRef, new Expression[0])) }));

    }
    statements[caches.length] = gen.returnStatement(gen.booleanLiteral(true));
    initMethod.setStatements(statements);
    // Serialization:
    SerializationGenerator.fillRestoreRole(teamType, caches);

    // ===== also add the field that triggers invocation of this method from all constructors: =====

    //save source positions from AstGenerator (ike)
    SourcePosition savePos = gen.getSourcePosition();
    try {
        //set STEP_OVER source positions (ike)
        gen.setSourcePosition(new StepOverSourcePosition());

        ThisReference thisReference = gen.thisReference();
        thisReference.resolvedType = teamType.binding.getRealClass(); // avoid wrapping of nested team
        thisReference.constant = Constant.NotAConstant;

        FieldDeclaration trigger = gen.field(ClassFileConstants.AccPrivate | ClassFileConstants.AccSynthetic,
                gen.singleTypeReference("boolean".toCharArray()), //$NON-NLS-1$
                IOTConstants.CACHE_INIT_TRIGGERER,
                gen.messageSend(thisReference, IOTConstants.OT_INIT_CACHES, new Expression[0]));
        AstEdit.addField(teamType, trigger, true, false/*typeProblem*/, true/*addToFront*/); // ensure this field's init is generated first into the constructor
        trigger.binding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; //  prevent 'unused' warning;

        // resolve them both:
        if (StateMemento.hasMethodResolveStarted(teamType.binding)) {
            initMethod.resolve(teamType.scope);
            trigger.resolve(teamType.initializerScope);
        }

    } finally {
        //restore source postions (ike)
        gen.setSourcePosition(savePos);
    }
}

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

License:Open Source License

void initializeDependentType(ITeamAnchor anchor, int valueParamPosition) {
    // don't store baseclass, will be initialized by baseclass()

    this._valueParamPosition = valueParamPosition;
    SyntheticArgumentBinding[] valParams = this.type.valueParamSynthArgs();
    if (valueParamPosition > -1) // subtypes don't set paramPosition/matchingField
        if (valueParamPosition < valParams.length) // defensive
            this._matchingVariable = valParams[valueParamPosition].matchingField;

    this._teamAnchor = anchor;
    if (anchor instanceof LocalVariableBinding)
        ((LocalVariableBinding) anchor).useFlag = LocalVariableBinding.USED;
    else if (anchor instanceof FieldBinding)
        ((FieldBinding) anchor).modifiers |= ExtraCompilerModifiers.AccLocallyUsed; // avoid unused-warning
}

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

License:Open Source License

/**
 * Copy a given method to the tsub-role.
 * Adds the new method to AST and performs initial creation of bindings.
 * @param method  method to copy/*from w w w . j a  v  a 2  s .  c o m*/
 * @param targetRoleDecl target role class
 */
private static void copyMethod(MethodBinding method, TypeDeclaration targetRoleDecl) {
    boolean wasSynthetic = false;
    ReferenceBinding site = null;

    if ((method.modifiers & AccSynthetic) != 0) {
        wasSynthetic = true;
        // some, but not all, synthetics shall be generated with strong signatures as indicated by 'site':
        if (!SyntheticBaseCallSurrogate.isBaseCallSurrogateName(method.selector))
            site = targetRoleDecl.binding;
        if (SyntheticRoleBridgeMethodBinding.isPrivateBridgeSelector(method.selector))
            return; // will be generated anew
    }

    if (TypeContainerMethod.isTypeContainer(method))
        return; // don't copy these dummy methods

    if (isCreator(method) || CharOperation.equals(IOTConstants._OT_GETBASE, method.selector)
            || CharOperation.prefixEquals(IOTConstants.CAST_PREFIX, method.selector)
            || CharOperation.prefixEquals(IOTConstants.GET_CLASS_PREFIX, method.selector))
        return; // create/getBase/cast/getClass-methods are generated anew in each team.
    // (can only happen in a team that is a role of an outer team.)
    // Note: we don't use AccSynthetic on creators, because
    // Synthetic methods are not read from byte code.
    // FIXME(SH): this last note is not true any more.

    if (targetRoleDecl.isTeam() && (ReflectionGenerator.isReflectionMethod(method)
            || SerializationGenerator.isSerializationMethod(method)))
        return;
    if (MethodModel.isFakedMethod(method))
        return; // will be generated anew (basecall-surrogate, rolefield-bridge)

    if (CharOperation.equals(IOTConstants.MIGRATE_TO_TEAM, method.selector))
        return; // can only be used from the exact team

    // avoid copying twice (see copyGeneratedFeatures()):
    targetRoleDecl.getRoleModel().recordCopiedFeature(method);

    // some useful objects:
    ReferenceBinding srcRole = method.declaringClass;
    TypeDeclaration targetTeamDecl = targetRoleDecl.enclosingType;
    ReferenceBinding srcTeam = TeamModel.getEnclosingTeam(srcRole);
    ReferenceBinding tgtTeam = targetTeamDecl.binding;

    MethodBinding origin = (method.copyInheritanceSrc != null) ? method.copyInheritanceSrc : method;

    AbstractMethodDeclaration methodFound = findMethod(srcTeam, method, tgtTeam, targetRoleDecl);

    if (method.isConstructor()) {
        if (CharOperation.equals(srcRole.compoundName, IOTConstants.ORG_OBJECTTEAMS_TEAM_OTCONFINED)) {
            // must add default constructor explicitly,
            // since if we would copy the one from Team.__OT__Confined,
            // it would invoke the wrong super().
            ConstructorDeclaration ctor = targetRoleDecl.createDefaultConstructor(true, true);
            targetRoleDecl.binding.resolveGeneratedMethod(ctor, false, origin);
            return;
        } else if (targetRoleDecl.getRoleModel()._refinesExtends) {
            // even if we can't copy the ctor, we need to mark
            // the current ctor as overriding the tsuper version.
            if (methodFound != null)
                methodFound.binding.addOverriddenTSuper(method);
            return; // extends is covariantly redefined, don't copy ctor!
            // attempts to invoke this tsuper ctor are caught in ExplicitConstructorCall.resolve().
        }
    }

    // If method already exists in subteam,
    // + adjust method in subteam to the more general signature (here)
    // + extend copy with marker arg (below).
    // else give an exact copy.
    boolean reuseFoundMethod = false;
    if (methodFound != null) {
        // do not touch broken methods:
        // (methodFound might have no binding,
        //  e.g., due to a missing import of return-type)
        if (methodFound.binding == null)
            return;

        if (methodFound.binding.copyInheritanceSrc == origin)
            return; // diamond inheritance: copying the same method from two different sources

        // tsuper method trumps previously inferred callout:
        if (methodFound.isMappingWrapper == WrapperKind.CALLOUT) {
            MethodModel model = methodFound.model;
            if (model != null && model._inferredCallout != null) {
                // reset callout related stuff:
                methodFound.isMappingWrapper = WrapperKind.NONE;
                model._inferredCallout = null;
                methodFound.statements = null;
                // setup as a copied method:
                methodFound.isCopied = true;
                methodFound.binding.copyInheritanceSrc = method;
                methodFound.sourceMethodBinding = method;
                reuseFoundMethod = true;
            }
        }

        // do this in any case so that ConstantPoolObjectMapper won't fail:
        methodFound.binding.addOverriddenTSuper(method);

        // abstract methods have no byte code to copy;
        // new method silently replaces abstract version:
        if (method.isAbstract()) {
            weakenSignature(methodFound, method);
            return;
        }

        if (method.isFinal()) {
            methodFound.scope.problemReporter().finalMethodCannotBeOverridden(methodFound.binding, method);
            return;
        }
        weakenSignature(methodFound, method);
        MethodBinding foundSrc = methodFound.binding.copyInheritanceSrc;
        if (foundSrc != null && foundSrc != origin) {
            // found a copied method which has a different origin, choose the more specific:
            // if incommensurable prefer the new copy (assuming it comes from *implicit* super team)
            if (!TeamModel.isMoreSpecificThan(foundSrc.declaringClass, origin.declaringClass)) {
                // more specific method overwrites previous linkage:
                methodFound.binding.setCopyInheritanceSrc(origin);
                methodFound.sourceMethodBinding = origin;
                methodFound.isTSuper = TSuperHelper.isTSuper(method);
                // TODO(SH): also update CopyInheritanceSrc-Attribute!
                if (!method.isAbstract()) {
                    // not abstract any more, joining abstract and implemented methods:
                    methodFound.modifiers &= ~(AccAbstract | AccSemicolonBody);
                    methodFound.binding.modifiers &= ~(AccAbstract | AccSemicolonBody);
                    // TODO(SH): might need multiple copyInheritanceSrc!
                    // TODO(SH) need to adjust copiedInContext?
                }
            }
            return;
        }
    }
    AstGenerator gen = new AstGenerator(targetRoleDecl.sourceStart, targetRoleDecl.sourceEnd);
    gen.replaceableEnclosingClass = tgtTeam;
    final AbstractMethodDeclaration newMethodDecl;
    if (methodFound != null && reuseFoundMethod) {
        newMethodDecl = methodFound;
    } else {
        newMethodDecl = AstConverter.createMethod(method, site, targetRoleDecl.compilationResult,
                DecapsulationState.REPORTED, gen);

        if (methodFound != null)
            TSuperHelper.addMarkerArg(newMethodDecl, srcTeam);

        if (newMethodDecl.isConstructor()) {
            // comments (SH):
            // other phases may depend on this field (constructorCall) being set,
            // although it carries no real information.
            ConstructorDeclaration cd = (ConstructorDeclaration) newMethodDecl;
            cd.constructorCall = SuperReference.implicitSuperConstructorCall();

            if (Lifting.isLiftingCtor(method) && method.parameters[0].isRole()) {
                // if baseclass is implicitely redefined use the strong type:
                ReferenceBinding newBase = targetRoleDecl.binding.baseclass();
                if (TypeBinding.notEquals(newBase, method.parameters[0]))
                    newMethodDecl.arguments[0].type = gen.baseclassReference(newBase);
            }
        }

        AstEdit.addMethod(targetRoleDecl, newMethodDecl, wasSynthetic, false/*addToFront*/, origin);
    }
    if (method.isPrivate()) {
        newMethodDecl.binding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; // don't warn unused copied method
    }

    newMethodDecl.binding.copiedInContext = tgtTeam.enclosingType();
    MethodModel newModel = MethodModel.getModel(newMethodDecl);
    newModel.addAttribute(CopyInheritanceSourceAttribute.copyInherSrcAttribute(origin, newModel));
    if (wasSynthetic)
        targetRoleDecl.getRoleModel().addSyntheticMethodMapping(method, newMethodDecl.binding);

    if (method.isAnyCallin() && !method.isCallin()) // callin wrapper
        newMethodDecl.isMappingWrapper = WrapperKind.CALLIN;

    if (methodFound == null) {
        // copy down some more properties:
        if (TSuperHelper.isTSuper(method))
            newMethodDecl.isTSuper = true;
        if (method.model != null && method.model.callinFlags != 0)
            MethodModel.addCallinFlag(newMethodDecl, method.model.callinFlags);
        if (method.isAnyCallin()) {
            TypeBinding inheritedSrcReturn = MethodModel.getReturnType(method);
            if (inheritedSrcReturn.isRole())
                inheritedSrcReturn = RoleTypeCreator.maybeWrapUnqualifiedRoleType(inheritedSrcReturn,
                        targetRoleDecl.binding);
            MethodModel.saveReturnType(newMethodDecl.binding, inheritedSrcReturn);
        } else {
            if (!method.isPublic() // non-public source-level class method?
                    && !method.isConstructor() && !targetRoleDecl.isInterface()
                    && !CharOperation.prefixEquals(IOTConstants.OT_DOLLAR_NAME, method.selector)) {
                MethodModel.getModel(newMethodDecl).storeModifiers(newMethodDecl.modifiers);
            }
        }
        // more checking: abstract method in non-abstract class?
        if (newMethodDecl.isAbstract() && (targetRoleDecl.modifiers & ClassFileConstants.AccAbstract) == 0) {
            targetRoleDecl.scope.problemReporter().setRechecker(new IProblemRechecker() {
                public boolean shouldBeReported(IrritantSet[] foundIrritants) {
                    if (newMethodDecl.isAbstract()) // implemented by callout?
                        return true;
                    return false; // false alarm
                }
            }).abstractMethodMustBeImplemented(targetRoleDecl.binding, newMethodDecl.binding);
        }
    }
}

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

License:Open Source License

/**
 * Nothing exciting here, just create a new field declaration.
 * @param field/* w ww.  j a  v  a 2 s .  c  o  m*/
 * @param roleDeclaration
 */
private static void copyField(FieldBinding field, TypeDeclaration roleDeclaration) {
    // avoid copying twice (see copyGeneratedFeatures()):
    roleDeclaration.getRoleModel().recordCopiedFeature(field);

    if ((field.modifiers & AccSynthetic) != 0) {
        roleDeclaration.binding.addCopiedSyntheticFied(field);
        return;
    }
    if ((field.tagBits & TagBits.IsFakedField) != 0)
        return; // don't copy fakes.

    if (roleDeclaration.fields != null) {
        for (int i = 0; i < roleDeclaration.fields.length; i++) {
            FieldDeclaration currentField = roleDeclaration.fields[i];
            if (CharOperation.equals(currentField.name, field.name)) {
                if (currentField.binding != null && currentField.binding.copyInheritanceSrc != null
                        && currentField.binding.copyInheritanceSrc == field.copyInheritanceSrc)
                    return; // not a problem: repeated inheritance of the same field!

                ProblemReporter problemReporter = currentField.isStatic()
                        ? roleDeclaration.staticInitializerScope.problemReporter()
                        : roleDeclaration.initializerScope.problemReporter();
                problemReporter.implicitlyHideField(currentField);
                return;
            }
        }
    }
    AstGenerator gen = new AstGenerator(roleDeclaration.sourceStart, roleDeclaration.sourceEnd);
    gen.replaceableEnclosingClass = roleDeclaration.binding.enclosingType();
    FieldDeclaration fieldDeclaration = AstConverter.createField(field, roleDeclaration, gen);
    AstEdit.addField(roleDeclaration, fieldDeclaration, true, false/*typeProblem*/, false);
    if (fieldDeclaration.binding != null) {
        fieldDeclaration.binding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
        fieldDeclaration.binding.modifiers |= (field.modifiers & ExtraCompilerModifiers.AccBlankFinal); // BlankFinal was omitted on the fieldDecl
    }

}

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

License:Open Source License

void addPrivateField(TypeDeclaration teamDecl, AstGenerator gen, TypeReference type, char[] name,
        Expression init) {/*from   w ww  .ja  v a 2 s  . c o  m*/
    FieldDeclaration field = gen.field(AccPrivate, type, name, init);
    AstEdit.addField(teamDecl, field, true, false, false);
    field.binding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
}