diff options
author | Stephan Herrmann | 2013-01-13 15:34:45 +0000 |
---|---|---|
committer | Stephan Herrmann | 2013-01-13 15:45:25 +0000 |
commit | 1566c962a10f52e1f012e1bcb8e9701c60c2c84d (patch) | |
tree | 19c66dafe8c7cf27be1ade9a4f9e7622a3f43ca9 | |
parent | 0a73c21c1765bd74e1f27ababb03717df96b2d1a (diff) | |
download | org.eclipse.objectteams-1566c962a10f52e1f012e1bcb8e9701c60c2c84d.tar.gz org.eclipse.objectteams-1566c962a10f52e1f012e1bcb8e9701c60c2c84d.tar.xz org.eclipse.objectteams-1566c962a10f52e1f012e1bcb8e9701c60c2c84d.zip |
Bug 397851 - reconciler does not understand role hierarchy involving
role file
5 files changed, 125 insertions, 68 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java index ec6aba89d..792d9a224 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java @@ -244,7 +244,7 @@ void buildTypeBindings(AccessRestriction accessRestriction) { } //{ObjectTeams: role files: (a) classes never match the name of the unit: prepended __OT__! -// (b) always check for matching file name (also protected) +// (b) always check for matching file name (also protected), except for purely copied role files boolean isRole = typeDecl.isRole() ; if ( (typeDecl.modifiers & ClassFileConstants.AccPublic) != 0 || typeDecl.isRole()) // (b) check independently of publicness @@ -258,7 +258,8 @@ void buildTypeBindings(AccessRestriction accessRestriction) { :giro */ if ((mainTypeName = this.referenceContext.getMainTypeName()) != null // mainTypeName == null means that implementor of ICompilationUnit decided to return null && !CharOperation.equals(mainTypeName, typeDecl.name) - && !(isRole && !typeDecl.isInterface())) // (a): ignore role classes + && !(isRole && !typeDecl.isInterface()) // (a): ignore role classes + && !typeDecl.isPurelyCopied) // (has no file) { if (typeDecl.isRole()) // (b) : more specific message problemReporter().roleFileMismatchingName(this.referenceContext, typeDecl); diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java index 7b8808307..6994dabda 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java @@ -52,7 +52,6 @@ import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; import org.eclipse.jdt.internal.compiler.util.SimpleSetOfCharArray; import org.eclipse.jdt.internal.compiler.util.Util; import org.eclipse.objectteams.otdt.core.compiler.IOTConstants; -import org.eclipse.objectteams.otdt.core.compiler.OTNameUtils; import org.eclipse.objectteams.otdt.core.exceptions.InternalCompilerError; import org.eclipse.objectteams.otdt.internal.core.compiler.ast.LiftingTypeReference; import org.eclipse.objectteams.otdt.internal.core.compiler.ast.RoleFileCache; @@ -1442,6 +1441,9 @@ public MethodBinding[] getMethods(char[] selector) { } //{ObjectTeams: ROFI if it is a team, the member might be a role file still to be found: public ReferenceBinding getMemberType(char[] name) { + if (this.notFoundMemberNames != null && this.notFoundMemberNames.includes(name)) + return null; + ReferenceBinding result = super.getMemberType(name); if (result != null) { // is it a member in a different file? @@ -1455,33 +1457,31 @@ public ReferenceBinding getMemberType(char[] name) { } return result; } -// FIXME(SH): needed for 1.7.7-otjld-5f, but causes more problems. -// Note: since State-Management has been restructured, things *might* -// be different by now. - if ( isTeam() - && !StateHelper.hasState(this, ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY) - && StateHelper.isReadyToProcess(this, ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY)) - { - if ( Dependencies.ensureBindingState(this, ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY) - && StateHelper.hasState(this, ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY)) - { - ReferenceBinding member = getMemberType(name); // try again for copied roles. - if (member != null && (member.tagBits & TagBits.HasMissingType) == 0) - return member; + if (isTeam() && !StateHelper.hasState(this, ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY)) { + if (StateHelper.isReadyToProcess(this, ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY)) { + if ( Dependencies.ensureBindingState(this, ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY) + && StateHelper.hasState(this, ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY)) + { + ReferenceBinding member = getMemberType(name); // try again for copied roles. + if (member != null && (member.tagBits & TagBits.HasMissingType) == 0) + return member; + } } + ReferenceBinding member = CopyInheritance.checkCopyLateRoleFile(this, name); + if (member != null) + return member; } - if (!isTeam() || this.teamPackage == null) - return null; - if (this.notFoundMemberNames != null && this.notFoundMemberNames.includes(name)) { - return null; + if (isTeam() && this.teamPackage != null) { + ReferenceBinding member = findTypeInTeamPackage(name); + if (member != null) + return member; } - ReferenceBinding res = findTypeInTeamPackage(name); - if (res == null) { - if (this.notFoundMemberNames == null) - this.notFoundMemberNames = new SimpleSetOfCharArray(); - this.notFoundMemberNames.add(name); + if (StateHelper.hasState(this, ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY)) { + if (this.notFoundMemberNames == null) + this.notFoundMemberNames = new SimpleSetOfCharArray(); + this.notFoundMemberNames.add(name); } - return res; + return null; } SimpleSetOfCharArray notFoundMemberNames; @@ -1549,27 +1549,13 @@ ReferenceBinding findTypeInTeamPackage(char[] name) { // teamModel.liftingEnv.init(teamModel.getAst()); } } else if (teamModel.getState() >= ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY) { - return checkCopyLateRoleFile(teamModel, name); + TypeDeclaration roleDecl = CopyInheritance.internalCheckCopyLateRoleFile(this, name); + if (roleDecl != null) + return roleDecl.binding; } } return result; } -private ReferenceBinding checkCopyLateRoleFile(TeamModel teamModel, char[] name) { - ReferenceBinding superTeam = superclass(); // FIXME(SH): tsuper teams - if ( superTeam != null - && !TypeAnalyzer.isOrgObjectteamsTeam(superTeam) - && !teamModel._isCopyingLateRole - && !OTNameUtils.isTSuperMarkerInterface(name)) - { - ReferenceBinding tsuperRole = superTeam.getMemberType(name); - if ( tsuperRole != null && tsuperRole.isRole() && tsuperRole.isValidBinding() - && !tsuperRole.isLocalType()) - { - return CopyInheritance.copyLateRole(teamModel.getAst(), tsuperRole); - } - } - return null; -} //SH} /* Answer the synthetic field for <actualOuterLocalVariable> * or null if one does not exist. diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TeamModel.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TeamModel.java index d4dbd96f9..9fe51d2e5 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TeamModel.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TeamModel.java @@ -76,13 +76,14 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.util.TSuperHelper; public class TeamModel extends TypeModel { // constants for bits in tagBits: + public static final int CopyRolesFromTSuperMASK = 0x0FF; + public static final int MaxTSuperRoles = 8; // so many bits allocated in CopyRolesFromTSuperMask - // can lifting fail due to role abstractness? - public static final int HasAbstractRelevantRole = ASTNode.Bit20; - - // details of completeTypeBindings: - public static final int BeginCopyRoles = ASTNode.Bit21; + // details of completeTypeBindings: + public static final int BeginCopyRoles = ASTNode.Bit9; + // can lifting fail due to role abstractness? + public static final int HasAbstractRelevantRole = ASTNode.Bit10; /** The Marker interface created for this Team (_TSuper__OT__TeamName); */ public TypeDeclaration markerInterface; @@ -332,8 +333,12 @@ public class TeamModel extends TypeModel { return false; } - public static void setTagBit(ReferenceBinding teamBinding, int tagBit) { - teamBinding.getTeamModel().tagBits |= tagBit; + public static boolean setTagBit(ReferenceBinding teamBinding, int tagBit) { + TeamModel model = teamBinding.getTeamModel(); + if ((model.tagBits & tagBit) != 0) + return false; // was already set + model.tagBits |= tagBit; + return true; } public static boolean hasTagBit(ReferenceBinding typeBinding, int tagBit) { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/CopyInheritance.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/CopyInheritance.java index 35ba3c86e..9b4a64095 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/CopyInheritance.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/CopyInheritance.java @@ -78,6 +78,7 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding; import org.eclipse.jdt.internal.compiler.problem.IProblemRechecker; import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; import org.eclipse.objectteams.otdt.core.compiler.IOTConstants; +import org.eclipse.objectteams.otdt.core.compiler.OTNameUtils; import org.eclipse.objectteams.otdt.core.exceptions.InternalCompilerError; import org.eclipse.objectteams.otdt.internal.core.compiler.ast.RoleClassLiteralAccess; import org.eclipse.objectteams.otdt.internal.core.compiler.ast.TypeContainerMethod; @@ -185,10 +186,6 @@ public class CopyInheritance implements IOTConstants, ClassFileConstants, ExtraC * Also connect roles with OT-specific links. */ public static void copyRoles(SourceTypeBinding teamBinding) { - if (TeamModel.hasTagBit(teamBinding, TeamModel.BeginCopyRoles)) - return; - TeamModel.setTagBit(teamBinding, TeamModel.BeginCopyRoles); - TeamModel teamModel= teamBinding.getTeamModel(); ReferenceBinding superTeam= teamBinding.superclass; if (superTeam == null) { @@ -197,15 +194,24 @@ public class CopyInheritance implements IOTConstants, ClassFileConstants, ExtraC } // super team: - TSuperHelper.addMarkerInterface(teamModel, superTeam); - copyRolesFromTeam(superTeam, teamModel, false/*isTsuperTeam*/); + if (TeamModel.setTagBit(teamBinding, TeamModel.BeginCopyRoles)) { + TSuperHelper.addMarkerInterface(teamModel, superTeam); + copyRolesFromTeam(superTeam, teamModel, false/*isTsuperTeam*/); + } // tsuper teams: if (teamBinding.isRole()) { - RoleModel teamAsRole = teamBinding.roleModel; - for (ReferenceBinding tsuperTeam: teamAsRole.getTSuperRoleBindings()) { - TSuperHelper.addMarkerInterface(teamModel, tsuperTeam); - copyRolesFromTeam(tsuperTeam, teamModel, true/*isTsuperTeam*/); + ReferenceBinding[] tSuperRoleBindings = teamBinding.roleModel.getTSuperRoleBindings(); + int length = tSuperRoleBindings.length; + if (length > TeamModel.MaxTSuperRoles) + throw new InternalCompilerError("Too many tsuper roles in "+String.valueOf(teamBinding.readableName())); //$NON-NLS-1$ + for (int i = 0; i < length; i++) { + ReferenceBinding tsuperTeam = tSuperRoleBindings[i]; + int tagBits = (1<<i) & TeamModel.CopyRolesFromTSuperMASK; + if (TeamModel.setTagBit(teamBinding, tagBits)) { + TSuperHelper.addMarkerInterface(teamModel, tsuperTeam); + copyRolesFromTeam(tsuperTeam, teamModel, true/*isTsuperTeam*/); + } } } @@ -686,7 +692,67 @@ public class CopyInheritance implements IOTConstants, ClassFileConstants, ExtraC subTeam.scope.compilationUnitScope().registerBinaryNested(subRole); } - public static ReferenceBinding copyLateRole(TypeDeclaration teamDecl, ReferenceBinding tsuperRole) { + /** + * If a requested member type was not found in a team binding try if a combination + * of role file loading and role copying resolves the issue. + */ + public static ReferenceBinding checkCopyLateRoleFile(SourceTypeBinding teamBinding, char[] name) { + if (!TeamModel.hasTagBit(teamBinding, TeamModel.BeginCopyRoles)) + return null; + ReferenceBinding ifcPart = null; + if (CharOperation.prefixEquals(IOTConstants.OT_DELIM_NAME, name)) { + char[] ifcName = CharOperation.subarray(name, IOTConstants.OT_DELIM_LEN, -1); + ifcPart = teamBinding.getMemberType(ifcName); + } + TypeDeclaration roleDecl = internalCheckCopyLateRoleFile(teamBinding, name); + if (roleDecl != null && ifcPart != null) { + ReferenceBinding superTeam = teamBinding.superclass; + if (!hasHiearchyCheckBegun(superTeam)) + Dependencies.ensureBindingState(superTeam, ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY); + TypeLevel.connectRoleClasses(superTeam, roleDecl); + } + if (roleDecl != null) + return roleDecl.binding; + return null; + } + private static boolean hasHiearchyCheckBegun(ReferenceBinding type) { + if ((type.tagBits & TagBits.BeginHierarchyCheck) != 0) + return true; + if (type.enclosingType() != null) + return hasHiearchyCheckBegun(type.enclosingType()); + return false; + } + + 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; + } + 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; + } + + public static TypeDeclaration copyLateRole(TypeDeclaration teamDecl, ReferenceBinding tsuperRole) { TypeDeclaration roleType = null; ReferenceBinding ifcPart = null; char[] tsuperName = tsuperRole.internalName(); @@ -696,19 +762,18 @@ public class CopyInheritance implements IOTConstants, ClassFileConstants, ExtraC } roleType = copyLateRolePart(teamDecl, tsuperRole); if (ifcPart != null) { - // FIXME(SH): improve catch up: connecting bindings etc. - Dependencies.ensureBindingState(tsuperRole.enclosingType(), ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY); + 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(tsuperRole.enclosingType(), roleType); - // subRole.set = ifcPart; - // ifcPart.roleModel._classPart = roleType.binding; + TypeLevel.connectRoleClasses(superTeam, roleType); setRoleState(subRole, STATE_LENV_CONNECT_TYPE_HIERARCHY); } } if (roleType == null) return null; Dependencies.lateRolesCatchup(teamDecl.getTeamModel()); - return roleType.binding; + return roleType; } private static TypeDeclaration copyLateRolePart(TypeDeclaration teamDecl, ReferenceBinding tsuperRole) { TypeDeclaration roleDecl = copyRole(tsuperRole, false, teamDecl, false); diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/TypeLevel.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/TypeLevel.java index 8b112720a..5843a2fb3 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/TypeLevel.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/TypeLevel.java @@ -63,7 +63,7 @@ public class TypeLevel { * @param superTeam * @param roleDecl */ - static SupertypeObligation[] connectRoleClasses( + public static SupertypeObligation[] connectRoleClasses( ReferenceBinding superTeam, TypeDeclaration roleDecl) { |