mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
2004-08-13 Chris Wiebe
Extra functionality in type cache to support new class wizard * browser/org/eclipse/cdt/core/browser/AllTypesCache.java * browser/org/eclipse/cdt/core/browser/IQualifiedTypeName.java * browser/org/eclipse/cdt/core/browser/QualifiedTypeName.java * browser/org/eclipse/cdt/core/browser/ITypeInfo.java * browser/org/eclipse/cdt/core/browser/TypeInfo.java * browser/org/eclipse/cdt/internal/core/browser/cache/ITypeCache.java * browser/org/eclipse/cdt/internal/core/browser/cache/TypeCache.java
This commit is contained in:
parent
3cd2cd8098
commit
3ead56997c
9 changed files with 192 additions and 28 deletions
|
@ -1,3 +1,14 @@
|
||||||
|
2004-08-13 Chris Wiebe
|
||||||
|
|
||||||
|
Extra functionality in type cache to support new class wizard
|
||||||
|
* browser/org/eclipse/cdt/core/browser/AllTypesCache.java
|
||||||
|
* browser/org/eclipse/cdt/core/browser/IQualifiedTypeName.java
|
||||||
|
* browser/org/eclipse/cdt/core/browser/QualifiedTypeName.java
|
||||||
|
* browser/org/eclipse/cdt/core/browser/ITypeInfo.java
|
||||||
|
* browser/org/eclipse/cdt/core/browser/TypeInfo.java
|
||||||
|
* browser/org/eclipse/cdt/internal/core/browser/cache/ITypeCache.java
|
||||||
|
* browser/org/eclipse/cdt/internal/core/browser/cache/TypeCache.java
|
||||||
|
|
||||||
2004-08-13 Chris Wiebe
|
2004-08-13 Chris Wiebe
|
||||||
|
|
||||||
Add findSourceRoot() method needed for class wizard
|
Add findSourceRoot() method needed for class wizard
|
||||||
|
|
|
@ -314,6 +314,33 @@ public class AllTypesCache {
|
||||||
return TypeUtil.getTypeForElement(elem);
|
return TypeUtil.getTypeForElement(elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns first type in the cache which matches the given
|
||||||
|
* type and name. If no type is found, <code>null</code>
|
||||||
|
* is returned.
|
||||||
|
*
|
||||||
|
* @param project the enclosing project
|
||||||
|
* @param type the ICElement type
|
||||||
|
* @param qualifiedName the qualified type name to match
|
||||||
|
* @return the matching type
|
||||||
|
*/
|
||||||
|
public static ITypeInfo getType(IProject project, int type, IQualifiedTypeName qualifiedName) {
|
||||||
|
ITypeCache cache = TypeCacheManager.getInstance().getCache(project);
|
||||||
|
return cache.getType(type, qualifiedName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all types matching name in the given project.
|
||||||
|
*
|
||||||
|
* @param project the enclosing project
|
||||||
|
* @param qualifiedName The qualified type name
|
||||||
|
* @param ignoreCase <code>true</code> if case-insensitive
|
||||||
|
* @return Array of types
|
||||||
|
*/
|
||||||
|
public static ITypeInfo[] getTypes(IProject project, IQualifiedTypeName qualifiedName, boolean ignoreCase) {
|
||||||
|
ITypeCache cache = TypeCacheManager.getInstance().getCache(project);
|
||||||
|
return cache.getTypes(qualifiedName, ignoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and returns a type hierarchy for this type containing
|
* Creates and returns a type hierarchy for this type containing
|
||||||
* this type and all of its supertypes and subtypes in the workspace.
|
* this type and all of its supertypes and subtypes in the workspace.
|
||||||
|
|
|
@ -40,4 +40,9 @@ public interface IQualifiedTypeName extends Comparable {
|
||||||
|
|
||||||
public boolean isLowLevel();
|
public boolean isLowLevel();
|
||||||
public boolean validate();
|
public boolean validate();
|
||||||
|
|
||||||
|
public boolean equals(IQualifiedTypeName typeName);
|
||||||
|
public boolean equalsIgnoreCase(IQualifiedTypeName typeName);
|
||||||
|
public int compareTo(IQualifiedTypeName typeName);
|
||||||
|
public int compareToIgnoreCase(IQualifiedTypeName typeName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,11 @@ public interface ITypeInfo extends Comparable {
|
||||||
*/
|
*/
|
||||||
public ITypeInfo getEnclosingType();
|
public ITypeInfo getEnclosingType();
|
||||||
|
|
||||||
|
/** Gets the enclosing namespace for this type.
|
||||||
|
* @return the enclosing namespace, or <code>null</code> if none exists.
|
||||||
|
*/
|
||||||
|
public ITypeInfo getEnclosingNamespace();
|
||||||
|
|
||||||
/** Gets the first enclosing type which matches one of the given kinds.
|
/** Gets the first enclosing type which matches one of the given kinds.
|
||||||
* @param kinds Array containing CElement types: C_NAMESPACE, C_CLASS, C_STRUCT
|
* @param kinds Array containing CElement types: C_NAMESPACE, C_CLASS, C_STRUCT
|
||||||
* @return the enclosing type, or <code>null</code> if not found.
|
* @return the enclosing type, or <code>null</code> if not found.
|
||||||
|
|
|
@ -246,8 +246,35 @@ public class QualifiedTypeName implements IQualifiedTypeName {
|
||||||
if (!(obj instanceof IQualifiedTypeName)) {
|
if (!(obj instanceof IQualifiedTypeName)) {
|
||||||
throw new ClassCastException();
|
throw new ClassCastException();
|
||||||
}
|
}
|
||||||
IQualifiedTypeName typeName = (IQualifiedTypeName) obj;
|
return compareTo((IQualifiedTypeName)obj);
|
||||||
return getFullyQualifiedName().compareTo(typeName.getFullyQualifiedName());
|
}
|
||||||
|
|
||||||
|
public int compareTo(IQualifiedTypeName typeName) {
|
||||||
|
if (typeName == this)
|
||||||
|
return 0;
|
||||||
|
if (typeName == null)
|
||||||
|
return 1;
|
||||||
|
String[] segments = typeName.segments();
|
||||||
|
int len = Math.min(fSegments.length, segments.length);
|
||||||
|
int result = 0;
|
||||||
|
for (int i = 0; result == 0 && i < len; ++i) {
|
||||||
|
result = fSegments[i].compareTo(segments[i]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareToIgnoreCase(IQualifiedTypeName typeName) {
|
||||||
|
if (typeName == this)
|
||||||
|
return 0;
|
||||||
|
if (typeName == null)
|
||||||
|
return 1;
|
||||||
|
String[] segments = typeName.segments();
|
||||||
|
int len = Math.min(fSegments.length, segments.length);
|
||||||
|
int result = 0;
|
||||||
|
for (int i = 0; result == 0 && i < len; ++i) {
|
||||||
|
result = fSegments[i].compareToIgnoreCase(segments[i]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
|
@ -255,23 +282,40 @@ public class QualifiedTypeName implements IQualifiedTypeName {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!(obj instanceof IQualifiedTypeName)) {
|
if (!(obj instanceof IQualifiedTypeName)) {
|
||||||
return false;
|
throw new ClassCastException();
|
||||||
}
|
}
|
||||||
IQualifiedTypeName typeName = (IQualifiedTypeName) obj;
|
return equals((IQualifiedTypeName)obj);
|
||||||
return matchSegments(fSegments, typeName.segments());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean matchSegments(String[] a, String[] b) {
|
public boolean equals(IQualifiedTypeName typeName) {
|
||||||
if (a == null && b == null)
|
if (typeName == this)
|
||||||
return true;
|
return true;
|
||||||
if (a == null || b == null)
|
if (typeName == null)
|
||||||
return false;
|
return false;
|
||||||
if (a.length != b.length)
|
String[] segments = typeName.segments();
|
||||||
return false;
|
int len = segments.length;
|
||||||
for (int i = 0; i < a.length; ++i) {
|
if (fSegments.length != len)
|
||||||
if (!a[i].equals(b[i]))
|
return false;
|
||||||
return false;
|
for (int i = 0; i < len; ++i) {
|
||||||
}
|
if (!fSegments[i].equals(segments[i]))
|
||||||
return true;
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equalsIgnoreCase(IQualifiedTypeName typeName) {
|
||||||
|
if (typeName == this)
|
||||||
|
return true;
|
||||||
|
if (typeName == null)
|
||||||
|
return false;
|
||||||
|
String[] segments = typeName.segments();
|
||||||
|
int len = segments.length;
|
||||||
|
if (fSegments.length != len)
|
||||||
|
return false;
|
||||||
|
for (int i = 0; i < len; ++i) {
|
||||||
|
if (!fSegments[i].equalsIgnoreCase(segments[i]))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,6 +149,13 @@ public class TypeInfo implements ITypeInfo
|
||||||
return getEnclosingType(KNOWN_TYPES);
|
return getEnclosingType(KNOWN_TYPES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ITypeInfo getEnclosingNamespace() {
|
||||||
|
if (fTypeCache != null) {
|
||||||
|
return fTypeCache.getEnclosingNamespace(this);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public ITypeInfo getRootNamespace(boolean includeGlobalNamespace) {
|
public ITypeInfo getRootNamespace(boolean includeGlobalNamespace) {
|
||||||
if (fTypeCache != null) {
|
if (fTypeCache != null) {
|
||||||
return fTypeCache.getRootNamespace(this, true);
|
return fTypeCache.getRootNamespace(this, true);
|
||||||
|
|
|
@ -85,6 +85,7 @@ public class TypeUtil {
|
||||||
return (ICElement[])typeList.toArray(new ICElement[typeList.size()]);
|
return (ICElement[])typeList.toArray(new ICElement[typeList.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO move method to CModelUtil
|
||||||
public static IQualifiedTypeName getFullyQualifiedName(ICElement type) {
|
public static IQualifiedTypeName getFullyQualifiedName(ICElement type) {
|
||||||
String name = type.getElementName();
|
String name = type.getElementName();
|
||||||
IQualifiedTypeName qualifiedName = new QualifiedTypeName(name);
|
IQualifiedTypeName qualifiedName = new QualifiedTypeName(name);
|
||||||
|
|
|
@ -105,7 +105,7 @@ public interface ITypeCache extends ISchedulingRule {
|
||||||
* @param qualifiedName the qualified type name to match
|
* @param qualifiedName the qualified type name to match
|
||||||
* @return Array of types
|
* @return Array of types
|
||||||
*/
|
*/
|
||||||
public ITypeInfo[] getTypes(IQualifiedTypeName qualifiedName);
|
public ITypeInfo[] getTypes(IQualifiedTypeName qualifiedName, boolean ignoreCase);
|
||||||
|
|
||||||
/** Returns first type in the cache which matches the given
|
/** Returns first type in the cache which matches the given
|
||||||
* type and name. If no type is found, <code>null</code>
|
* type and name. If no type is found, <code>null</code>
|
||||||
|
@ -126,6 +126,13 @@ public interface ITypeCache extends ISchedulingRule {
|
||||||
*/
|
*/
|
||||||
public ITypeInfo getEnclosingType(ITypeInfo info, int[] kinds);
|
public ITypeInfo getEnclosingType(ITypeInfo info, int[] kinds);
|
||||||
|
|
||||||
|
/** Returns the enclosing namespace for the given type, or
|
||||||
|
* <code>null</code> if none exists.
|
||||||
|
*
|
||||||
|
* @param type the ICElement type
|
||||||
|
* @return the namespace
|
||||||
|
*/
|
||||||
|
public ITypeInfo getEnclosingNamespace(ITypeInfo info);
|
||||||
|
|
||||||
/** Gets the root namespace of which encloses the given type.
|
/** Gets the root namespace of which encloses the given type.
|
||||||
*
|
*
|
||||||
|
|
|
@ -218,8 +218,7 @@ public class TypeCache implements ITypeCache {
|
||||||
if (!(obj instanceof IQualifiedTypeName)) {
|
if (!(obj instanceof IQualifiedTypeName)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
IQualifiedTypeName typeName = (IQualifiedTypeName) obj;
|
return equals((IQualifiedTypeName)obj);
|
||||||
return (typeName instanceof GlobalNamespace);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(Object obj) {
|
public int compareTo(Object obj) {
|
||||||
|
@ -229,9 +228,36 @@ public class TypeCache implements ITypeCache {
|
||||||
if (!(obj instanceof IQualifiedTypeName)) {
|
if (!(obj instanceof IQualifiedTypeName)) {
|
||||||
throw new ClassCastException();
|
throw new ClassCastException();
|
||||||
}
|
}
|
||||||
IQualifiedTypeName typeName = (IQualifiedTypeName) obj;
|
return compareTo((IQualifiedTypeName)obj);
|
||||||
return getFullyQualifiedName().compareTo(typeName.getFullyQualifiedName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.browser.IQualifiedTypeName#equals(org.eclipse.cdt.core.browser.IQualifiedTypeName)
|
||||||
|
*/
|
||||||
|
public boolean equals(IQualifiedTypeName typeName) {
|
||||||
|
return (typeName instanceof GlobalNamespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.browser.IQualifiedTypeName#equalsIgnoreCase(org.eclipse.cdt.core.browser.IQualifiedTypeName)
|
||||||
|
*/
|
||||||
|
public boolean equalsIgnoreCase(IQualifiedTypeName typeName) {
|
||||||
|
return (typeName instanceof GlobalNamespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.browser.IQualifiedTypeName#compareTo(org.eclipse.cdt.core.browser.IQualifiedTypeName)
|
||||||
|
*/
|
||||||
|
public int compareTo(IQualifiedTypeName typeName) {
|
||||||
|
return getFullyQualifiedName().compareTo(typeName.getFullyQualifiedName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.browser.IQualifiedTypeName#compareToIgnoreCase(org.eclipse.cdt.core.browser.IQualifiedTypeName)
|
||||||
|
*/
|
||||||
|
public int compareToIgnoreCase(IQualifiedTypeName typeName) {
|
||||||
|
return getFullyQualifiedName().compareToIgnoreCase(typeName.getFullyQualifiedName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class HashKey {
|
private static class HashKey {
|
||||||
|
@ -454,17 +480,28 @@ public class TypeCache implements ITypeCache {
|
||||||
return (ITypeInfo[]) results.toArray(new ITypeInfo[results.size()]);
|
return (ITypeInfo[]) results.toArray(new ITypeInfo[results.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized ITypeInfo[] getTypes(IQualifiedTypeName qualifiedName) {
|
public synchronized ITypeInfo[] getTypes(IQualifiedTypeName qualifiedName, boolean ignoreCase) {
|
||||||
Collection results = new ArrayList();
|
Collection results = new ArrayList();
|
||||||
for (int i = 0; i < ITypeInfo.KNOWN_TYPES.length; ++i) {
|
if (!ignoreCase) {
|
||||||
ITypeInfo info = (ITypeInfo) fTypeKeyMap.get(new HashKey(qualifiedName, ITypeInfo.KNOWN_TYPES[i]));
|
for (int i = 0; i < ITypeInfo.KNOWN_TYPES.length; ++i) {
|
||||||
|
ITypeInfo info = (ITypeInfo) fTypeKeyMap.get(new HashKey(qualifiedName, ITypeInfo.KNOWN_TYPES[i]));
|
||||||
|
if (info != null) {
|
||||||
|
results.add(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ITypeInfo info = (ITypeInfo) fTypeKeyMap.get(new HashKey(qualifiedName, 0));
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
results.add(info);
|
results.add(info);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
ITypeInfo info = (ITypeInfo) fTypeKeyMap.get(new HashKey(qualifiedName, 0));
|
// TODO this should probably use a more efficient search algorithm
|
||||||
if (info != null) {
|
for (Iterator mapIter = fTypeKeyMap.entrySet().iterator(); mapIter.hasNext(); ) {
|
||||||
results.add(info);
|
Map.Entry entry = (Map.Entry) mapIter.next();
|
||||||
|
ITypeInfo info = (ITypeInfo) entry.getValue();
|
||||||
|
if (info.getQualifiedTypeName().compareToIgnoreCase(qualifiedName) == 0) {
|
||||||
|
results.add(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (ITypeInfo[]) results.toArray(new ITypeInfo[results.size()]);
|
return (ITypeInfo[]) results.toArray(new ITypeInfo[results.size()]);
|
||||||
}
|
}
|
||||||
|
@ -492,6 +529,26 @@ public class TypeCache implements ITypeCache {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized ITypeInfo getEnclosingNamespace(ITypeInfo info) {
|
||||||
|
IQualifiedTypeName enclosingName = info.getQualifiedTypeName().getEnclosingTypeName();
|
||||||
|
if (enclosingName != null) {
|
||||||
|
// look for namespace
|
||||||
|
ITypeInfo enclosingType = (ITypeInfo) fTypeKeyMap.get(new HashKey(enclosingName, ICElement.C_NAMESPACE));
|
||||||
|
if (enclosingType != null) {
|
||||||
|
return enclosingType;
|
||||||
|
}
|
||||||
|
// try class, struct, then undefined
|
||||||
|
final int[] kinds = {ICElement.C_CLASS, ICElement.C_STRUCT, 0};
|
||||||
|
for (int i = 0; enclosingType == null && i < kinds.length; ++i) {
|
||||||
|
enclosingType = (ITypeInfo) fTypeKeyMap.get(new HashKey(enclosingName, kinds[i]));
|
||||||
|
}
|
||||||
|
if (enclosingType != null) {
|
||||||
|
return getEnclosingNamespace(enclosingType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized ITypeInfo getRootNamespace(ITypeInfo info, boolean includeGlobalNamespace) {
|
public synchronized ITypeInfo getRootNamespace(ITypeInfo info, boolean includeGlobalNamespace) {
|
||||||
IQualifiedTypeName qualifiedName = info.getQualifiedTypeName();
|
IQualifiedTypeName qualifiedName = info.getQualifiedTypeName();
|
||||||
if (qualifiedName.isGlobal()) {
|
if (qualifiedName.isGlobal()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue