Example usage for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding isBinaryBinding

List of usage examples for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding isBinaryBinding

Introduction

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

Prototype

public final boolean isBinaryBinding() 

Source Link

Usage

From source file:com.redhat.ceylon.eclipse.core.model.mirror.UnknownClassMirror.java

License:Open Source License

public JDTClass(ReferenceBinding klass, IType type) {
    this.type = type;
    bindingRef = new WeakReference<ReferenceBinding>(klass);
    pkg = new JDTPackage(klass.getPackage());
    simpleName = new String(klass.sourceName());
    qualifiedName = JDTUtils.getFullyQualifiedName(klass);
    isPublic = klass.isPublic();/* w w  w  .  java  2  s  .co m*/
    isInterface = klass.isInterface();
    isAbstract = klass.isAbstract();
    isProtected = klass.isProtected();
    isDefaultAccess = klass.isDefault();
    isLocalType = klass.isLocalType();
    isStatic = (klass.modifiers & ClassFileConstants.AccStatic) != 0;
    isFinal = klass.isFinal();
    isEnum = klass.isEnum();
    isBinary = klass.isBinaryBinding();
    isAnonymous = klass.isAnonymousType();
    isJavaSource = (klass instanceof SourceTypeBinding)
            && new String(((SourceTypeBinding) klass).getFileName()).endsWith(".java");
    isAnnotationType = klass.isAnnotationType();
    bindingKey = klass.computeUniqueKey();

    char[] bindingFileName = klass.getFileName();
    int start = CharOperation.lastIndexOf('/', bindingFileName) + 1;
    if (start == 0 || start < CharOperation.lastIndexOf('\\', bindingFileName))
        start = CharOperation.lastIndexOf('\\', bindingFileName) + 1;
    fileName = new String(CharOperation.subarray(bindingFileName, start, -1));

    int jarFileEntrySeparatorIndex = CharOperation.indexOf(IDependent.JAR_FILE_ENTRY_SEPARATOR,
            bindingFileName);
    if (jarFileEntrySeparatorIndex > 0) {
        char[] jarPart = CharOperation.subarray(bindingFileName, 0, jarFileEntrySeparatorIndex);
        IJavaElement jarPackageFragmentRoot = JavaCore.create(new String(jarPart));
        String jarPath = jarPackageFragmentRoot.getPath().toOSString();
        char[] entryPart = CharOperation.subarray(bindingFileName, jarFileEntrySeparatorIndex + 1,
                bindingFileName.length);
        fullPath = new StringBuilder(jarPath).append("!/").append(entryPart).toString();
    } else {
        fullPath = new String(bindingFileName);
    }

    ReferenceBinding sourceOrClass = klass;
    if (!klass.isBinaryBinding()) {
        sourceOrClass = klass.outermostEnclosingType();
    }
    char[] classFullName = new char[0];
    for (char[] part : sourceOrClass.compoundName) {
        classFullName = CharOperation.concat(classFullName, part, '/');
    }
    char[][] temp = CharOperation.splitOn('.', sourceOrClass.getFileName());
    String extension = temp.length > 1 ? "." + new String(temp[temp.length - 1]) : "";
    javaModelPath = new String(classFullName) + extension;

    if (type == null) {
        annotations = new HashMap<>();
        methods = Collections.emptyList();
        interfaces = Collections.emptyList();
        typeParams = Collections.emptyList();
        fields = Collections.emptyList();
        innerClasses = Collections.emptyList();
    }
}

From source file:io.gige.compiler.internal.HookedJavaFileObject.java

License:Open Source License

protected void closed() {
    if (!_closed) {
        _closed = true;//from  w  w w .ja  v a2s  .co m
        // TODO: support encoding
        switch (this.getKind()) {
        case SOURCE:
            CompilationUnit unit = new CompilationUnit(null, _fileName, null /* encoding */);
            _filer.addNewUnit(unit);
            break;
        case CLASS:
            IBinaryType binaryType = null;
            try {
                binaryType = ClassFileReader.read(_fileName);
            } catch (ClassFormatException e) {
                /*
                 * When the annotation processor produces garbage, javac
                 * seems to show some resilience, by hooking the source
                 * type, which since is resolved can answer annotations
                 * during discovery - Not sure if this sanctioned by the
                 * spec, to be taken up with Oracle. Here we mimic the bug,
                 * see that addNewClassFile is simply collecting
                 * ReferenceBinding's, so adding a SourceTypeBinding works
                 * just fine.
                 */
                ReferenceBinding type = this._filer._env.getCompiler().lookupEnvironment
                        .getType(CharOperation.splitOn('.', _typeName.toCharArray()));
                if (type != null)
                    _filer.addNewClassFile(type);
            } catch (IOException e) {
                // ignore
            }
            if (binaryType != null) {
                char[] name = binaryType.getName();
                ReferenceBinding type = this._filer._env.getCompiler().lookupEnvironment
                        .getType(CharOperation.splitOn('/', name));
                if (type != null && type.isValidBinding()) {
                    if (type.isBinaryBinding()) {
                        _filer.addNewClassFile(type);
                    } else {
                        BinaryTypeBinding binaryBinding = new BinaryTypeBinding(type.getPackage(), binaryType,
                                this._filer._env.getCompiler().lookupEnvironment, true);
                        if (binaryBinding != null)
                            _filer.addNewClassFile(binaryBinding);
                    }
                }
            }
            break;
        case HTML:
        case OTHER:
            break;
        }
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectReader.java

License:Open Source License

private MethodBinding doFindMethodBinding(ReferenceBinding class_rb, char[] name, char[] descriptor) {
    MethodBinding[] mbs = class_rb.getMethods(name);

    if (mbs != Binding.NO_METHODS) {
        for (int i = 0; i < mbs.length; i++) {
            MethodBinding binding = mbs[i];
            if (binding != null) {
                if (isEqual(binding, name, descriptor))
                    return binding;
            }//from   ww  w  .  j a  va  2  s . co m
        }
        // TODO(SH): currently this may happen, if a role file is not recompiled which
        // required e.g., a getter access$n, while a setter access$n is being generated.
        if (isSynthMethodName(name))
            throw new InternalCompilerError(
                    "synthetic method " + new String(name) + " has unexpected signature"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    if (isSynthMethodName(name) || SyntheticBaseCallSurrogate.isBaseCallSurrogateName(name)) {
        // for normal access methods class_rb should not be a BinaryTypeBinding, 
        // because in that case the above loop should have found the method
        // (access$n are stored like normal methods).
        if (class_rb.isBinaryBinding()) {
            if (SyntheticBaseCallSurrogate.isBaseCallSurrogateName(name)) { // surrogate might be inherited
                ReferenceBinding current = class_rb;
                while ((current = current.superclass()) != null) {
                    MethodBinding candidate = doFindMethodBinding(current, name, descriptor);
                    if (candidate != null)
                        return candidate;
                }
            }
            // TODO(SH): but when T has been compiled only with T.R1 while T.R2
            //           requires a synth.method, than this method will be missing!
        } else {
            SourceTypeBinding stb = (SourceTypeBinding) class_rb.erasure();
            SyntheticMethodBinding[] accessMethods = stb.syntheticMethods();
            if (accessMethods != null) {
                for (int i = 0; i < accessMethods.length; i++) {
                    if (CharOperation.equals(accessMethods[i].selector, name))
                        return accessMethods[i];
                }
            }
        }
    }
    if (SyntheticRoleFieldAccess.isRoleFieldAccess(AccSynthetic, name)) {
        if (class_rb.isBinaryBinding())
            return null; // should have been found within methods
        SourceTypeBinding sourceType = (SourceTypeBinding) class_rb.erasure();
        SyntheticMethodBinding[] synthetics = sourceType.syntheticMethods();
        if (synthetics == null)
            return null;
        for (SyntheticMethodBinding methodBinding : synthetics) {
            if (CharOperation.equals(methodBinding.selector, name))
                return methodBinding;
        }
    }
    int modifiers = isFakedOTREMethod(name);
    if (modifiers != 0) {
        // These methods will be generated by the OTRE,
        // may safely be faked during compilation:
        MethodBinding fakedMethod = createMethodFromSignature(class_rb, modifiers, name, descriptor);
        class_rb.addMethod(fakedMethod);
        return fakedMethod;
    }
    // since Eclipse 3.0 and for JDK >= 1.2 the declaring class is changed to the
    // declared receiver (see SourceTypeBinding.getUpdatedMethodBinding()).
    // need to search super class/interfaces to really find the method.
    ReferenceBinding currentType = class_rb.superclass();
    if (currentType != null) {
        MethodBinding mb = findMethodBinding(currentType, name, descriptor);
        if (mb != null)
            return mb;
    }
    ReferenceBinding[] superIfcs = class_rb.superInterfaces();
    if (superIfcs != null) {
        for (int i = 0; i < class_rb.superInterfaces().length; i++) {
            MethodBinding mb = findMethodBinding(superIfcs[i], name, descriptor);
            if (mb != null) {
                if (!class_rb.isInterface())
                    return new MethodBinding(mb, class_rb); // need a class method!
                return mb;
            }
        }
    }
    return null;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.CopyInheritanceSourceAttribute.java

License:Open Source License

public void evaluateLateAttribute(ReferenceBinding roleBinding, int state) {
    switch (state) {
    case ITranslationStates.STATE_ROLE_FEATURES_COPIED:
        break; // go aheady and evaluate
    case ITranslationStates.STATE_LATE_ATTRIBUTES_EVALUATED:
        if (this.method == null)
            return; // can't work
        if (this.method.copyInheritanceSrc != null)
            return; // have already worked
        break;//w  w  w  .ja  v  a  2  s  .c o  m
    default:
        return; // only in above to states
    }

    // will need a method binding from a tsuper role:
    ReferenceBinding teamBinding = this.method.declaringClass.enclosingType();
    if (teamBinding != null && teamBinding.superclass() != null)
        Dependencies.ensureBindingState(teamBinding.superclass(),
                ITranslationStates.STATE_LENV_DONE_FIELDS_AND_METHODS);
    else
        assert this.method.declaringClass.isLocalType(); // enclosing type not set for these.

    int dotPos = CharOperation.indexOf('.', this.sourceMethodDesignator);
    int lparPos = CharOperation.indexOf('(', this.sourceMethodDesignator);
    char[] selector = CharOperation.subarray(this.sourceMethodDesignator, dotPos + 1, lparPos);
    char[] signature = CharOperation.subarray(this.sourceMethodDesignator, lparPos, -1);
    ReferenceBinding type = this.environment.getTypeFromConstantPoolName(this.sourceMethodDesignator, 0, dotPos,
            false, null); // FIXME(GENERIC): determine last params!
    if (type == null)
        return;
    if (type instanceof UnresolvedReferenceBinding)
        type = resolveReferenceType(this.environment, (UnresolvedReferenceBinding) type);
    if (type instanceof MissingTypeBinding) {
        ProblemReporter problemReporter = this.environment.problemReporter;
        ReferenceBinding current = roleBinding;
        // search a source type to report against:
        while (current != null && current.isBinaryBinding())
            current = current.enclosingType();
        if (current != null) {
            Scope scope = ((SourceTypeBinding) current).scope;
            if (scope != null)
                problemReporter = scope.problemReporter();
        }
        problemReporter.staleTSuperRole(roleBinding, type,
                new String(CharOperation.concat(selector, signature)));
        return;
    }
    if (roleBinding.roleModel.hasTSuperRole(type)) {
        Dependencies.ensureBindingState(type, ITranslationStates.STATE_LATE_ATTRIBUTES_EVALUATED);

        if (this.method.isAnyCallin())
            signature = MethodSignatureEnhancer.generalizeReturnInSignature(signature);
        MethodBinding[] methods = type.getMethods(selector);
        for (int i = 0; i < methods.length; i++) {
            if (CharOperation.equals(methods[i].signature(), signature)) {
                MethodBinding origin = methods[i].copyInheritanceSrc;
                if (origin == null)
                    origin = methods[i];
                this.method.setCopyInheritanceSrc(origin);
                return;
            }
        }
    } else {
        if (roleBinding.isBinaryBinding())
            return; // silently ignore ;-)
    }
    this.environment.problemReporter.staleTSuperRole(roleBinding, type,
            new String(CharOperation.concat(selector, signature)));
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies.java

License:Open Source License

/**
 * @param model//  w ww .j  a  v a 2 s  .  c o m
 */
public static boolean ensureTeamState(TeamModel model, int state) {
    boolean success = true;

    ReferenceBinding teamBinding = model.getBinding();
    TypeDeclaration teamDeclaration = model.getAst();
    if (teamDeclaration != null) {
        if ((teamDeclaration.binding == null) && (model.getState() > STATE_ROLES_SPLIT)) {
            if (teamDeclaration.ignoreFurtherInvestigation)
                return false; // irrecoverable
            throw new InternalCompilerError("binding needed"); //$NON-NLS-1$
        }
    }
    while (model.getState() < state) {
        int numMemberTypes = model.getNumRoles();

        int oldState = model.getState();
        int nextState = oldState + 1;

        if (model.isIgnoreFurtherInvestigation() && !StateHelper.isRequiredState(nextState)) // KEEPGOING
        {
            StateHelper.setStateRecursive(model.getAst(), nextState, true);
            continue;
        }

        final int NONE = 0;
        final int ROLES = 1;
        final int NESTED_TEAMS = 2;
        int done = NONE;

        if (StateHelper.isCUDState(nextState, new int[] { STATE_METHODS_PARSED })) {
            // special case team-as-role:
            if (model.isRole() && model.getRoleModelOfThis().getState() >= nextState) {
                // already processed.
                model.setState(nextState);
                continue;
            }
        }

        if (!model._state.isReadyToProcess(nextState))
            return false;
        model._state.startProcessing(nextState);

        switch (nextState) // what should be done next?
        {
        case STATE_ROLES_SPLIT:
            fixEnclosingType(model);
            success = establishRolesSplit(model);
            done = NESTED_TEAMS;
            break;
        case STATE_ROLE_HIERARCHY_ANALYZED:
            success = establishRoleHierarchy(model);
            done = ROLES;
            break;
        case STATE_FULL_LIFTING:
            success = establishFullLifting(model);
            done = ROLES;
            break;
        case STATE_TYPES_ADJUSTED:
            success = establishTypesAdjusted(model);
            done = NONE; // also process roles!
            break;
        case STATE_STATEMENTS_TRANSFORMED:
            success = establishStatementsTransformed(model);
            done = NESTED_TEAMS;
            break;
        case STATE_CALLINS_TRANSFORMED:
            success = establishCallinsTransformed(model);
            done = NONE;
            break;
        case STATE_LATE_ELEMENTS_COPIED:
            success = establishLateElementsCopied(model);
            done = NONE;
            break;
        case STATE_FAULT_IN_TYPES:
            success = establishFaultInTypes(model);
            done = NESTED_TEAMS;
            break;
        case STATE_ROLE_INIT_METHODS:
            if (teamBinding.isRole())
                ensureRoleState(teamBinding.roleModel, nextState);
            done = NONE;
            break;
        case STATE_METHODS_CREATED:
            success = establishMethodsCreated(model);
            done = NONE;
            break;
        // Delegate up:
        case STATE_METHODS_PARSED:
            // special case: delegate up to unit and also seek role units:

            // Note(SH): don't use ensureUnitState which needs to recurse into ensureAstState,
            //           and then we can't easily decide how much processing has already happened.
            CompilationUnitDeclaration unit = getCUD(model);
            if (unit != null && unit.parseMethodBodies)
                Config.delegateGetMethodBodies(unit);

            // redundantly mark: we still need to traverse members:
            done = NONE;
            break;
        case STATE_LATE_ATTRIBUTES_EVALUATED:
            // more attributes after fields and methods are in place:
            // (notably precedence must be evaluated before resolving)
            model.evaluateLateAttributes(STATE_LATE_ATTRIBUTES_EVALUATED);
            done = NONE;
            break;
        // ==== CUD-states except STATE_METHODS_PARSED:
        case STATE_LENV_CONNECT_TYPE_HIERARCHY:
            if (teamBinding.isBinaryBinding()) {
                CopyInheritance.connectBinaryTSupers(model);
                done = ROLES;
                break;
            }
            //$FALL-THROUGH$ (for source types)
        case STATE_RESOLVED:
        case STATE_ROLE_FILES_LINKED:
        case STATE_BINDINGS_BUILT:
        case STATE_LENV_BUILD_TYPE_HIERARCHY:
        case STATE_LENV_CHECK_AND_SET_IMPORTS:
        case STATE_LENV_DONE_FIELDS_AND_METHODS:
        case STATE_METHODS_VERIFIED:
        case STATE_CODE_ANALYZED:
        case STATE_BYTE_CODE_GENERATED:
            // always start from the unit
            success = ensureUnitState(model, nextState);
            done = NESTED_TEAMS; // recursion is included.
            break;
        }
        if (!success)
            return false;
        if (done < NESTED_TEAMS) {
            // pass some states down to our roles.
            // This currently affects
            // + ROLES_LINKED,
            // + ROLE_FEATURES_COPIED
            // + ROLE_HIERARCHY_ANALYZED
            // + TYPES_ADJUSTED
            // + STATEMENTS_TRANSFORMED
            // + MAPPINGS_RESOLVED
            // + MAPPINGS_TRANSFORMED
            // + LATE_ELEMENTS_COPIED
            // + BYTE_CODE_PREPARED

            RoleModel[] roles = model.getRoles(true); // includeSynthIfcs
            if (roles != null) {
                for (int idx = 0; idx < roles.length; idx++) {
                    if (done == NONE) {
                        success &= ensureRoleState(roles[idx], nextState);
                    } else { // did roles, but not as nested teams.
                        if (roles[idx].isTeam()) {
                            success &= ensureTeamState(roles[idx].getTeamModelOfThis(), nextState);
                            // only now this class if fully processed, mark it:
                            roles[idx].setState(nextState);
                        }
                    }
                }
            }
            model.setState(nextState);
        }

        if (model.getNumRoles() > numMemberTypes)
            lateRolesCatchup(model);

        if (model.getState() == oldState)
            throw new InternalCompilerError("Translation (team) does not advance, fails to establish state " //$NON-NLS-1$
                    + ITranslationStates.STATE_NAMES[oldState + 1]);
    }
    return true;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies.java

License:Open Source License

private static boolean establishMethodsCreated(TeamModel teamModel) {
    if (teamModel.getBinding().isRole())
        ensureRoleState(teamModel.getRoleModelOfThis(), STATE_METHODS_CREATED);
    ReferenceBinding superTeam = teamModel.getBinding().superclass();
    // synthetics from binary super team (binary has synthetics right from the beginning):
    // Note: for source super team this is done in TypeDeclaration.generateCode().
    if (teamModel.getAst() != null && superTeam.isBinaryBinding())
        // (requires role features copied of our roles in order to map the fields)
        CopyInheritance.copySyntheticTeamMethods(teamModel, (BinaryTypeBinding) superTeam);
    if (teamModel.getAst() != null) {
        if (!TypeAnalyzer.isOrgObjectteamsTeam(teamModel.getBinding())
                && !teamModel.getBinding().superclass().isTeam()) {
            LookupEnvironment env = teamModel.getAst().scope.environment();
            env.getTeamMethodGenerator().addMethodsAndFields(teamModel.getAst());
        }//from w w  w  . j  a v a 2s  . c  o m
    }
    return true;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies.java

License:Open Source License

private static boolean establishMethodsCreated(RoleModel clazz) {
    TypeDeclaration teamType = clazz.getTeamModel().getAst();
    ReferenceBinding subRole = clazz.getBinding();
    TypeDeclaration subRoleDecl = clazz.getAst();

    if (subRole == null) { // extra caution, none of the code below would work
        clazz.setState(STATE_METHODS_CREATED);
        return false;
    }/*from   ww  w.  jav a2  s .c o m*/

    if (OTNameUtils.isTSuperMarkerInterface(clazz.getInternalName()) || teamType == null) {
        // 0. binary only: create OTRE-generated methods:
        if (subRole.isBinaryBinding())
            ((BinaryTypeBinding) subRole).createOTREMethods(clazz);
        clazz.setState(STATE_METHODS_CREATED);
        return true; // nothing to do
    }

    SourceTypeBinding subTeam = teamType.binding;

    if (subRoleDecl == null) {
        // 1. create creation methods from constructors (binding version):
        //     TODO (SH): currently, this is only invoked for roles that are
        //                explicitly mentioned in classes being compiled.
        //                Need a place to store a list of previously compiled roles!
        if (subRole.isClass() // interfaces have not constructores, don't bother.
                && !subRole.isLocalType()) // local types need no creators, are only copied along with their containing method
        {
            createCreators(clazz, teamType, subRole, subTeam);
        }
        // no steps 2.+3.
    }
    // Next translations only for source types (no role nested types)
    if (subRoleDecl != null && subRole.isDirectRole()) {
        // 1. create creation methods from constructors (AST version)
        if (subRole.isClass()) // interfaces have not constructores, don't bother.
            createCtorsAndCreators(clazz, teamType, subRoleDecl, subTeam);

        // 2. create getTeam methods:
        if (subRoleDecl.isInterface()) {
            // process class and ifc at the same time, because otherwise an error
            // somewhere along the line may cause inconsistency between them two.
            StandardElementGenerator.createGetTeamMethod(subRoleDecl);
            TypeDeclaration classPart = clazz.getClassPartAst();
            if (classPart != null)
                StandardElementGenerator.createGetTeamMethod(classPart);
        }
        // 3. add methods from non-role super-class to the ifc-part
        if (!subRole.isInterface())
            RoleSplitter.setupInterfaceForExtends(clazz.getTeamModel().getAst(), subRoleDecl,
                    clazz.getInterfaceAst());
    }

    // 4. cast and getClass methods (independent of the source/binary difference):
    if (subRole.isInterface()
            && (subRoleDecl == null || needMethodBodies(subRoleDecl) || subRoleDecl.isRoleFile())) {
        TypeDeclaration sourceType = subRoleDecl != null ? subRoleDecl : teamType;
        TypeDeclaration classPart = clazz.getClassPartAst();
        if (classPart != null)
            StandardElementGenerator.createCastMethod(clazz.getTeamModel(), classPart, /*dims*/ 0); // FIXME dimensions
        else // difference is only in source positions used.
            StandardElementGenerator.getCastMethod(clazz.getTeamModel(), subRole, teamType.scope, /*dims*/ 0,
                    false, sourceType.sourceStart, sourceType.sourceEnd); // FIXME dimensions
        if (subRole.isPublic())
            RoleClassLiteralAccess.ensureGetClassMethod(teamType.getTeamModel(), clazz);
    }

    // 5. special case roles which need an abstract _OT$getBase() method:
    StandardElementGenerator.createGetBaseForUnboundLowerable(clazz);

    // 6. resolve method mappings and create callout methods:
    MethodMappingResolver resolver = resolveCalloutMappings(clazz);
    CalloutImplementor.transformCallouts(clazz);
    if (resolver != null)
        resolver.resolve(false/*doCallout*/); // callins last so all methods incl. callout are already in place

    if (subRoleDecl != null)
        checkMissingMethods(subRole, subRoleDecl);

    clazz.setState(STATE_METHODS_CREATED);
    return true;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies.java

License:Open Source License

private static boolean establishLateElementsCopied(RoleModel model) {
    boolean success = true;
    TypeDeclaration roleDecl = model.getAst();
    if (roleDecl != null) {
        success = CopyInheritance.copyLocalTypes(model);
        if (!roleDecl.isInterface()) {
            if (roleDecl.methods != null)
                for (AbstractMethodDeclaration method : roleDecl.methods)
                    if (method.isGenerated && method.model != null)
                        method.model.generateStatements();

            if (model.isBound()) {
                MethodBinding unimplementedGetBase = model.getInheritedUnimplementedGetBase();
                if (unimplementedGetBase != null) {
                    ReferenceBinding classBinding = model.getClassPartBinding();
                    if (classBinding != null && !classBinding.isBinaryBinding()) {
                        MethodBinding getBaseMethod = classBinding.getExactMethod(IOTConstants._OT_GETBASE,
                                Binding.NO_PARAMETERS, null);
                        SourceTypeBinding classSourceType = (SourceTypeBinding) classBinding;
                        classSourceType.addSyntheticBridgeMethod(unimplementedGetBase, getBaseMethod);
                    }/*from  w  ww  .ja va  2s  .c o m*/
                }
            }
        }
    }
    model.setState(STATE_LATE_ELEMENTS_COPIED);
    return success;
}

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

License:Open Source License

/**
 * Retrieve or create a method binding representing the base call surrogate for a callin method.
 * The actual method will be created by the OTRE.
 *
 * PRE: callinMethod already has all signature enhancements
 *
 * @param callinMethod/*from w  ww  . ja  v  a  2s.c  o  m*/
 * @param environment   needed for lookup of java/lang/Object (needed for return type generalization).
 *                      and for wrapping role types.
 * @return a MethodBinding (if it already exists or if role is binary) or a new SyntheticBaseCallSurrogate or null (if none is required)
 */
public static MethodBinding getBaseCallSurrogate(MethodBinding callinMethod, RoleModel clazz,
        LookupEnvironment environment) {

    try {
        if (TSuperHelper.isTSuper(callinMethod))
            return null;
        if (SyntheticBaseCallSurrogate.isBindingForCallinMethodInherited(callinMethod))
            return null;
        MethodBinding result = null;
        ReferenceBinding roleType = callinMethod.declaringClass;
        ReferenceBinding teamType = roleType.enclosingType();
        ReferenceBinding declaringClass = callinMethod.isStatic() ? teamType : roleType;

        char[] roleName = roleType.sourceName();
        char[] selector = genSurrogateName(callinMethod.selector, roleName, callinMethod.isStatic());
        TypeBinding returnType = MethodSignatureEnhancer.getGeneralizedReturnType(callinMethod.returnType,
                environment);
        TypeBinding[] baseCallParameters = callinMethod.parameters;
        if (!callinMethod.isStatic())
            baseCallParameters = addIsSuperAccessArg(baseCallParameters,
                    environment.globalOptions.weavingScheme);

        // search existing surrogate:
        candidates: for (MethodBinding candidate : declaringClass.getMethods(selector)) {
            if (candidate.parameters.length != baseCallParameters.length)
                continue;
            for (int i = 0; i < baseCallParameters.length; i++)
                if (!areTypesEqual(baseCallParameters[i].erasure(), candidate.parameters[i]))
                    continue candidates;
            result = candidate;
            break;
        }
        if (result == null) {
            if (declaringClass.isBinaryBinding())
                result = new MethodBinding(ClassFileConstants.AccPublic, selector, returnType,
                        baseCallParameters, null /*exceptions*/, declaringClass);
            else
                result = ((SourceTypeBinding) declaringClass).addSyntheticBaseCallSurrogate(callinMethod);
            MethodModel.getModel(result)._fakeKind = MethodModel.FakeKind.BASECALL_SURROGATE;
            RoleTypeCreator.wrapTypesInMethodBindingSignature(result, environment);
            result.modifiers &= ~ExtraCompilerModifiers.AccUnresolved;
            declaringClass.addMethod(result);
        }
        MethodModel.getModel(callinMethod).setBaseCallSurrogate(result);
        return result;
    } catch (RuntimeException ex) {
        // check if failure is due to incompatible class file version
        if (clazz != null && clazz.isIncompatibleCompilerVersion()) {
            String version;
            version = WordValueAttribute.getBytecodeVersionString(clazz._compilerVersion);
            // note: we have no source to report this error against,
            // so use whatever the current problem reporter is configured for.
            String errorMessage = "Byte code for class " + String.valueOf(clazz.getBinding().readableName()) //$NON-NLS-1$
                    + " has incompatible version " + version + ", original error was: " + ex.toString(); //$NON-NLS-1$ //$NON-NLS-2$
            try {
                Config.getLookupEnvironment().problemReporter.abortDueToInternalError(errorMessage);
            } catch (NotConfiguredException e) {
                throw new AbortCompilation(false, e);
            }
            return null;
        }
        throw ex; // want to see all other exceptions
    }
}

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

License:Open Source License

/**
 * Get the access method for a given team and field when accessing from outside.
 *
 * @param enclosingTeam/*from  ww w  .  j  a  v a2 s  .c om*/
 * @param targetField
 * @param isReadAccess
 * @param externalizedReceiver whether the receiver of this field access is an externalized role
 * @return a synthetic field accessor method or null if not found
 */
public static @Nullable SyntheticMethodBinding getAccessorFor(ReferenceBinding enclosingTeam,
        FieldBinding targetField, boolean isReadAccess, boolean externalizedReceiver) {
    if (enclosingTeam.isBinaryBinding()) {
        for (MethodBinding method : enclosingTeam.methods()) {
            if (SyntheticRoleFieldAccess.isAccessFor(method, targetField, isReadAccess))
                return (SyntheticMethodBinding) method;
        }
        return null;
    } else {
        SourceTypeBinding outerSrc = (SourceTypeBinding) enclosingTeam;
        return outerSrc.addSyntheticMethod(targetField, isReadAccess, false/*isSuperAccess*/,
                externalizedReceiver);
    }
}