Example usage for org.eclipse.jdt.internal.compiler.lookup SourceTypeBinding setFields

List of usage examples for org.eclipse.jdt.internal.compiler.lookup SourceTypeBinding setFields

Introduction

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

Prototype

public FieldBinding[] setFields(FieldBinding[] fields) 

Source Link

Usage

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)./* w  w w . jav a 2 s .  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;
    }
}