diff options
author | Stephan Herrmann | 2010-08-14 20:00:51 +0000 |
---|---|---|
committer | Stephan Herrmann | 2010-08-14 20:00:51 +0000 |
commit | 9099dc0d7203e200631f0f2efe4c55f06b93a8b7 (patch) | |
tree | 44cacc0520d2c1cc264da6991a9a71bbc37e3c9b /org.eclipse.jdt.core | |
parent | 765ab5fa391f9221b89de52117130f0fc63f942f (diff) | |
download | org.eclipse.objectteams-9099dc0d7203e200631f0f2efe4c55f06b93a8b7.tar.gz org.eclipse.objectteams-9099dc0d7203e200631f0f2efe4c55f06b93a8b7.tar.xz org.eclipse.objectteams-9099dc0d7203e200631f0f2efe4c55f06b93a8b7.zip |
Cleanup for Bug 321411 - [hierarchy] Replace OTTypeHierarchy with adapting the original TypeHierarchy
(remove references to OTTypeHierarchy - see comment 7 for details)
Diffstat (limited to 'org.eclipse.jdt.core')
4 files changed, 54 insertions, 82 deletions
diff --git a/org.eclipse.jdt.core/model/org/eclipse/objectteams/otdt/core/IOTType.java b/org.eclipse.jdt.core/model/org/eclipse/objectteams/otdt/core/IOTType.java index f3399fd8c..c89d4df6f 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/objectteams/otdt/core/IOTType.java +++ b/org.eclipse.jdt.core/model/org/eclipse/objectteams/otdt/core/IOTType.java @@ -20,7 +20,7 @@ **********************************************************************/ package org.eclipse.objectteams.otdt.core; -import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jdt.core.Flags; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; @@ -74,7 +74,7 @@ public interface IOTType extends IOTJavaElement, IType /** * Returns the flags from parsing. These flags provide additional * information about the type's modifiers e.g. IConstants.AccTeam - * @see org.eclipse.jdt.internal.compiler.env.IConstants + * @see Flags */ public int getFlags(); @@ -99,23 +99,21 @@ public interface IOTType extends IOTJavaElement, IType /** * Returns all roles of this team. Either the inlined, the role files or both are * returned. + * See {@link IOTType#getRoleTypes()} for gathering all role types. * * @param which an ORed combination of IOTType.INLINED, IOTType.ROLEFILE, IOTType.IMPLICITLY_INHERITED, * IOTType.EXPLICITLY_INHERITED and IOTType.EXCLUDE_SELF - * @see IOTType.getRoleTypes() for gathering all role types. */ public IType[] getRoleTypes(int which) throws JavaModelException; /** * Returns roles named roleName of this team. Either the inlined, the role files or both are * returned. + * See {@link IOTType#getRoleTypes()} for gathering all role types. * * @param which an ORed combination of IOTType.INLINED, IOTType.ROLEFILE, IOTType.IMPLICITLY_INHERITED, * IOTType.EXPLICITLY_INHERITED and IOTType.EXCLUDE_SELF - * @see IOTType.getRoleTypes() for gathering all role types. */ public IType[] getRoleTypes(int which, String roleName) throws JavaModelException; - public IOTTypeHierarchy newOTTypeHierarchy(IProgressMonitor monitor) throws JavaModelException; - public IOTTypeHierarchy newSuperOTTypeHierarchy(IProgressMonitor monitor) throws JavaModelException; } diff --git a/org.eclipse.jdt.core/model/org/eclipse/objectteams/otdt/internal/core/OTType.java b/org.eclipse.jdt.core/model/org/eclipse/objectteams/otdt/internal/core/OTType.java index cbd84e8d3..65c2646a0 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/objectteams/otdt/internal/core/OTType.java +++ b/org.eclipse.jdt.core/model/org/eclipse/objectteams/otdt/internal/core/OTType.java @@ -54,7 +54,6 @@ import org.eclipse.jdt.core.search.SearchRequestor; import org.eclipse.jdt.internal.core.JavaElement; import org.eclipse.jdt.internal.core.util.MementoTokenizer; import org.eclipse.objectteams.otdt.core.IOTType; -import org.eclipse.objectteams.otdt.core.IOTTypeHierarchy; import org.eclipse.objectteams.otdt.core.OTModelManager; import org.eclipse.objectteams.otdt.core.TypeHelper; import org.eclipse.objectteams.otdt.core.search.OTSearchEngine; @@ -129,13 +128,7 @@ public class OTType extends OTJavaElement implements IOTType } /** - * Returns all roles of this team. Either the inlined, the role files or both are - * returned. - * - * @param which an ORed combination of IOTType.INLINED, IOTType.ROLEFILE, IOTType.IMPLICITLY_INHERITED, - * IOTType.EXPLICITLY_INHERITED and IOTType.ECLUDE_SELF - * @throws JavaModelException - * @see IOTType.getRoleTypes() for gathering all role types. + * {@inheritDoc}. */ public IType[] getRoleTypes(int which) throws JavaModelException { @@ -143,15 +136,7 @@ public class OTType extends OTJavaElement implements IOTType } /** - * Returns roles named roleName of this team. Either the inlined, the role files or both are - * returned. - * - * TODO (carp): specify and implement sort order especially with respect to the hierarchy - * - * @param which an ORed combination of IOTType.INLINED, IOTType.ROLEFILE, IOTType.IMPLICITLY_INHERITED, - * IOTType.EXPLICITLY_INHERITED and IOTType.ECLUDE_SELF - * @throws JavaModelException - * @see IOTType.getRoleTypes() for gathering all role types. + * {@inheritDoc} */ public IType[] getRoleTypes(int which, String roleName) throws JavaModelException { @@ -162,18 +147,9 @@ public class OTType extends OTJavaElement implements IOTType if ((which & BOTH_HIERARCHIES_MASK) != 0) { - IOTTypeHierarchy hierarchy = newSuperOTTypeHierarchy(new NullProgressMonitor()); - switch (which & BOTH_HIERARCHIES_MASK) { - case EXPLICITLY_INHERITED: - typesToConsider = new IType[] { hierarchy.getExplicitSuperclass(this) }; - break; - case IMPLICTLY_INHERITED: - typesToConsider = hierarchy.getAllTSuperTypes(this); - break; - case BOTH_HIERARCHIES_MASK: - typesToConsider = hierarchy.getAllSuperclasses(this); - break; - } + ITypeHierarchy hierarchy = ((IType)getCorrespondingJavaElement()).newSupertypeHierarchy(new NullProgressMonitor()); + typesToConsider = getTypesToSearchForRoles(hierarchy, which & BOTH_HIERARCHIES_MASK); + } if ((which & EXCLUDE_SELF) == 0) @@ -215,6 +191,12 @@ public class OTType extends OTJavaElement implements IOTType return result.toArray(new IType[result.size()]); } + + // hook for OTTypeHierarchies to select behavior depending of argument 'which': + private IType[] getTypesToSearchForRoles(ITypeHierarchy hierarchy, int which) throws JavaModelException { + // default case: + return hierarchy.getAllSuperclasses(this); + } private static IType[] fixTypesToConsider(IType[] typesToConsider) { @@ -299,7 +281,7 @@ public class OTType extends OTJavaElement implements IOTType { List<IType> roleFiles = searchEngineGetRoleFiles(new IType[] { this }, simpleName); if (roleFiles.size() > 0) - return (IType) roleFiles.get(0); // actually there may be more, due to multiple src-folders... + return roleFiles.get(0); // actually there may be more, due to multiple src-folders... // previous implementation without search engine // String encTeamName = this.getFullyQualifiedName(); @@ -658,20 +640,6 @@ public class OTType extends OTJavaElement implements IOTType getIType().rename(name, replace, monitor); } - public IOTTypeHierarchy newSuperOTTypeHierarchy(IProgressMonitor monitor) throws JavaModelException - { - OTTypeHierarchy hierarchy = new OTTypeHierarchy(this, getJavaProject(), false); - hierarchy.refresh(monitor); - return hierarchy; - } - - public IOTTypeHierarchy newOTTypeHierarchy(IProgressMonitor monitor) throws JavaModelException - { - OTTypeHierarchy hierarchy = new OTTypeHierarchy(this, getJavaProject(), true); - hierarchy.refresh(monitor); - return hierarchy; - } - public void codeComplete(char[] snippet, int insertion, int position, char[][] localVariableTypeNames, char[][] localVariableNames, int[] localVariableModifiers, boolean isStatic, CompletionRequestor requestor) throws JavaModelException { getIType().codeComplete(snippet, insertion, position, localVariableTypeNames, localVariableNames, localVariableModifiers, isStatic, requestor); } diff --git a/org.eclipse.jdt.core/model/org/eclipse/objectteams/otdt/internal/core/RoleType.java b/org.eclipse.jdt.core/model/org/eclipse/objectteams/otdt/internal/core/RoleType.java index fdcbf055d..72eb41585 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/objectteams/otdt/internal/core/RoleType.java +++ b/org.eclipse.jdt.core/model/org/eclipse/objectteams/otdt/internal/core/RoleType.java @@ -31,8 +31,8 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaModelStatus; import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.ITypeHierarchy; import org.eclipse.jdt.core.ITypeParameter; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; @@ -44,7 +44,6 @@ import org.eclipse.jdt.internal.core.util.Util; import org.eclipse.objectteams.otdt.core.IMethodMapping; import org.eclipse.objectteams.otdt.core.IOTJavaElement; import org.eclipse.objectteams.otdt.core.IOTType; -import org.eclipse.objectteams.otdt.core.IOTTypeHierarchy; import org.eclipse.objectteams.otdt.core.IRoleType; import org.eclipse.objectteams.otdt.core.OTModelManager; import org.eclipse.objectteams.otdt.core.TypeHelper; @@ -143,7 +142,10 @@ public class RoleType extends OTType implements IRoleType _baseClass = baseClass; } - public IType getBaseClass() throws JavaModelException + public IType getBaseClass() throws JavaModelException { + return getBaseClass(null); + } + private IType getBaseClass(ITypeHierarchy hierarchy) throws JavaModelException { if (_baseClass == null) { @@ -152,7 +154,7 @@ public class RoleType extends OTType implements IRoleType try { // System.out.println("RoleType.getBaseClass(): " + getElementName()); - _baseClass = findBaseClass(); + _baseClass = findBaseClass(hierarchy); } catch (JavaModelException ex) { @@ -229,10 +231,10 @@ public class RoleType extends OTType implements IRoleType * * @return resolved JavaModel type or null if nothing found */ - private IType findBaseClass() throws JavaModelException + private IType findBaseClass(ITypeHierarchy hierarchy) throws JavaModelException { if (_baseClassName == null) - return findSuperBaseClass(); + return findSuperBaseClass(hierarchy); if (_baseAnchor != null) { @@ -254,34 +256,34 @@ public class RoleType extends OTType implements IRoleType return resolveInType(this, _baseClassName); } - // FIXME remove recursive building of hierarchy through getBaseClass -> findSuperBaseClass -> getBaseOf -> tsuper.getBaseClass() - private IType findSuperBaseClass() throws JavaModelException + // argument avoids recursive building of hierarchy through getBaseClass -> findSuperBaseClass -> getBaseOf -> tsuper.getBaseClass() + private IType findSuperBaseClass(ITypeHierarchy hierarchy) throws JavaModelException { - IOTTypeHierarchy hierarchy = newSuperOTTypeHierarchy(new NullProgressMonitor()); - IType[] tsupers = hierarchy.getTSuperTypes((IType) this.getCorrespondingJavaElement()); - for (int i = 0; i < tsupers.length; i++) - { - IType baseType = getBaseOf(tsupers[i]); + IType currentType = (IType)getCorrespondingJavaElement(); + if (hierarchy == null) + hierarchy = currentType.newSupertypeHierarchy(new NullProgressMonitor()); + currentType = hierarchy.getSuperclass(currentType); + while (currentType != null && OTModelManager.isRole(currentType)) { + IType baseType = getBaseOf(currentType, hierarchy); if (baseType != null) return baseType; + currentType = hierarchy.getSuperclass(currentType); // relies on OTTypeHierarchies whereby getSuperclass() produces the full (t)super linearization } - - IType explicitSuper = hierarchy.getExplicitSuperclass((IType) this.getCorrespondingJavaElement()); - return getBaseOf(explicitSuper); + return null; } - private IType getBaseOf(IType type) throws JavaModelException + private IType getBaseOf(IType type, ITypeHierarchy hierarchy) throws JavaModelException { if (type != null && type.exists()) { IOTType otType = OTModelManager.getOTElement(type); - if (otType == null) // i.e. java.lang.Object + if (otType == null) // i.e. non-role superclass return null; if (otType.isRole()) { - IRoleType tsuperRole = (IRoleType) otType; - IType tsuperBase = tsuperRole.getBaseClass(); + RoleType tsuperRole = (RoleType) otType; + IType tsuperBase = tsuperRole.getBaseClass(hierarchy); if (tsuperBase != null) return tsuperBase; } @@ -366,7 +368,7 @@ public class RoleType extends OTType implements IRoleType ArrayList<IType> tsuperRoles = new ArrayList<IType>(); IType teamType = getTeam(); if (teamType == null) - throw new JavaModelException(new JavaModelStatus(IJavaModelStatus.ERROR, "Enclosing team not found for "+this.getElementName()+" perhaps this element is not on the build path?")); + throw new JavaModelException(new JavaModelStatus(IStatus.ERROR, "Enclosing team not found for "+this.getElementName()+" perhaps this element is not on the build path?")); //$NON-NLS-1$ //$NON-NLS-2$ String superteamName = teamType.getSuperclassName(); if (superteamName != null) { if (superteamName.indexOf('.') != -1) { diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodPattern.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodPattern.java index 482d8e547..2f0fa40ad 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodPattern.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodPattern.java @@ -15,14 +15,18 @@ package org.eclipse.jdt.internal.core.search.matching; import java.io.IOException; -import org.eclipse.jdt.core.*; +import org.eclipse.jdt.core.BindingKey; +import org.eclipse.jdt.core.Flags; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.ITypeHierarchy; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.search.IJavaSearchConstants; import org.eclipse.jdt.core.search.SearchPattern; -import org.eclipse.jdt.internal.core.index.*; +import org.eclipse.jdt.internal.core.index.EntryResult; +import org.eclipse.jdt.internal.core.index.Index; import org.eclipse.jdt.internal.core.util.Util; -import org.eclipse.objectteams.otdt.core.IOTType; -import org.eclipse.objectteams.otdt.core.IOTTypeHierarchy; import org.eclipse.objectteams.otdt.core.OTModelManager; public class MethodPattern extends JavaSearchPattern { @@ -49,7 +53,7 @@ public static ThreadLocal<Object> findingCallers = new ThreadLocal<Object>(); // for tsuper/tsub matching: private IType declaringRoleClass= null; -private IOTTypeHierarchy cachedRoleHierarchy= null; +private ITypeHierarchy cachedRoleHierarchy= null; // SH} // extra reference info @@ -449,11 +453,10 @@ protected StringBuffer print(StringBuffer output) { } //{ObjectTeams: tsuper/tsub checking: public void setDeclaringRoleClass(IType declaringClass) { - IOTType roleType= OTModelManager.getOTElement(declaringClass); - if (roleType != null) { + if (OTModelManager.isRole(declaringClass)) { this.declaringRoleClass= declaringClass; try { - cachedRoleHierarchy= roleType.newSuperOTTypeHierarchy(null); + this.cachedRoleHierarchy= declaringClass.newSupertypeHierarchy(null); // FIXME(SH): really need to eagerly compute this? } catch (JavaModelException e) { /* no hope for exact matching */ } } } @@ -463,10 +466,11 @@ public int resolveLevelForType(String typeName, int declaringLevel) { return declaringLevel; if (this.cachedRoleHierarchy != null) { - IType[] tsubTypes= this.cachedRoleHierarchy.getTSuperTypes(this.declaringRoleClass); - for (IType tsubType : tsubTypes) { - if (typeName.equals(tsubType.getFullyQualifiedName('.'))) + IType superType = this.cachedRoleHierarchy.getSuperclass(this.declaringRoleClass); // OTTypeHierarchies will ensure that tsupers are traversed, too. + while (superType != null && OTModelManager.isRole(superType)) { + if (typeName.equals(superType.getFullyQualifiedName('.'))) return declaringLevel; + superType = this.cachedRoleHierarchy.getSuperclass(superType); } } return PatternLocator.IMPOSSIBLE_MATCH; |