1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

2004-08-25 Chris Wiebe

support for matching enclosed type names
	* browser/org/eclipse/cdt/browser/AllTypesCache.java
	* browser/org/eclipse/cdt/browser/IQualifiedTypeName.java
	* browser/org/eclipse/cdt/browser/QualifiedTypeName.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:
Chris Wiebe 2004-08-26 02:20:04 +00:00
parent 0ffaa59b58
commit f06a2d122e
6 changed files with 58 additions and 15 deletions

View file

@ -1,3 +1,12 @@
2004-08-25 Chris Wiebe
support for matching enclosed type names
* browser/org/eclipse/cdt/browser/AllTypesCache.java
* browser/org/eclipse/cdt/browser/IQualifiedTypeName.java
* browser/org/eclipse/cdt/browser/QualifiedTypeName.java
* browser/org/eclipse/cdt/internal/core/browser/cache/ITypeCache.java
* browser/org/eclipse/cdt/internal/core/browser/cache/TypeCache.java
2004-08-25 Chris Wiebe
add namespace validation to CConventions

View file

@ -182,19 +182,27 @@ public class AllTypesCache {
* @param qualifiedName The qualified type name
* @param kinds Array containing CElement types: C_NAMESPACE, C_CLASS,
* C_UNION, C_ENUMERATION, C_TYPEDEF
* @param matchEnclosed <code>true</code> if enclosed types count as matches (foo::bar == bar)
*/
public static ITypeInfo[] getTypes(ITypeSearchScope scope, IQualifiedTypeName qualifiedName, int[] kinds) {
public static ITypeInfo[] getTypes(ITypeSearchScope scope, IQualifiedTypeName qualifiedName, int[] kinds, boolean matchEnclosed) {
final Collection fTypesFound = new ArrayList();
final ITypeSearchScope fScope = scope;
final int[] fKinds = kinds;
final IQualifiedTypeName fQualifiedName = qualifiedName;
final boolean fMatchEnclosed = matchEnclosed;
IProject[] projects = scope.getEnclosingProjects();
ITypeInfoVisitor visitor = new ITypeInfoVisitor() {
public boolean visit(ITypeInfo info) {
if (ArrayUtil.contains(fKinds, info.getCElementType())
&& fQualifiedName.equals(info.getQualifiedTypeName())
&& (fScope != null && info.isEnclosed(fScope))) {
fTypesFound.add(info);
IQualifiedTypeName currName = info.getQualifiedTypeName();
if (fMatchEnclosed && currName.segmentCount() > fQualifiedName.segmentCount()
&& currName.lastSegment().equals(fQualifiedName.lastSegment())) {
currName = currName.removeFirstSegments(currName.segmentCount() - fQualifiedName.segmentCount());
}
if (currName.equals(fQualifiedName)) {
fTypesFound.add(info);
}
}
return true;
}
@ -333,12 +341,13 @@ public class AllTypesCache {
*
* @param project the enclosing project
* @param qualifiedName The qualified type name
* @param matchEnclosed <code>true</code> if enclosed types count as matches (foo::bar == bar)
* @param ignoreCase <code>true</code> if case-insensitive
* @return Array of types
*/
public static ITypeInfo[] getTypes(IProject project, IQualifiedTypeName qualifiedName, boolean ignoreCase) {
public static ITypeInfo[] getTypes(IProject project, IQualifiedTypeName qualifiedName, boolean matchEnclosed, boolean ignoreCase) {
ITypeCache cache = TypeCacheManager.getInstance().getCache(project);
return cache.getTypes(qualifiedName, ignoreCase);
return cache.getTypes(qualifiedName, matchEnclosed, ignoreCase);
}
/**

View file

@ -16,12 +16,11 @@ public interface IQualifiedTypeName extends Comparable {
public String getName();
public String getFullyQualifiedName();
public IQualifiedTypeName getEnclosingTypeName();
public String[] getEnclosingNames();
public String getFullyQualifiedName();
public IQualifiedTypeName getEnclosingTypeName();
public boolean isQualified();
public boolean isEmpty();
public boolean isGlobal();

View file

@ -97,10 +97,14 @@ public class QualifiedTypeName implements IQualifiedTypeName {
return null;
}
public boolean isQualified() {
return (fSegments.length > 1);
}
public boolean isEmpty() {
return fSegments.length == 0;
}
public boolean isGlobal() {
if (fSegments.length <= 1) {
return true;

View file

@ -103,9 +103,11 @@ public interface ITypeCache extends ISchedulingRule {
* name. If no types are found, an empty array is returned.
*
* @param qualifiedName the qualified type name to match
* @param matchEnclosed <code>true</code> if enclosed types count as matches (foo::bar == bar)
* @param ignoreCase <code>true</code> if case-insensitive
* @return Array of types
*/
public ITypeInfo[] getTypes(IQualifiedTypeName qualifiedName, boolean ignoreCase);
public ITypeInfo[] getTypes(IQualifiedTypeName qualifiedName, boolean matchEnclosed, boolean ignoreCase);
/** Returns first type in the cache which matches the given
* type and name. If no type is found, <code>null</code>

View file

@ -149,6 +149,10 @@ public class TypeCache implements ITypeCache {
public boolean isGlobal() {
return true;
}
public boolean isQualified() {
return false;
}
public int segmentCount() {
return 1;
@ -481,9 +485,9 @@ public class TypeCache implements ITypeCache {
return (ITypeInfo[]) results.toArray(new ITypeInfo[results.size()]);
}
public synchronized ITypeInfo[] getTypes(IQualifiedTypeName qualifiedName, boolean ignoreCase) {
public synchronized ITypeInfo[] getTypes(IQualifiedTypeName qualifiedName, boolean matchEnclosed, boolean ignoreCase) {
Collection results = new ArrayList();
if (!ignoreCase) {
if (!ignoreCase && !matchEnclosed) {
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) {
@ -499,8 +503,24 @@ public class TypeCache implements ITypeCache {
for (Iterator mapIter = fTypeKeyMap.entrySet().iterator(); mapIter.hasNext(); ) {
Map.Entry entry = (Map.Entry) mapIter.next();
ITypeInfo info = (ITypeInfo) entry.getValue();
if (info.getQualifiedTypeName().compareToIgnoreCase(qualifiedName) == 0) {
results.add(info);
IQualifiedTypeName currName = info.getQualifiedTypeName();
if (ignoreCase) {
if (matchEnclosed && currName.segmentCount() > qualifiedName.segmentCount()
&& currName.lastSegment().equalsIgnoreCase(qualifiedName.lastSegment())) {
currName = currName.removeFirstSegments(currName.segmentCount() - qualifiedName.segmentCount());
}
if (currName.equalsIgnoreCase(qualifiedName)) {
results.add(info);
}
} else {
if (matchEnclosed && currName.segmentCount() > qualifiedName.segmentCount()
&& currName.lastSegment().equals(qualifiedName.lastSegment())) {
currName = currName.removeFirstSegments(currName.segmentCount() - qualifiedName.segmentCount());
}
if (currName.equals(qualifiedName)) {
results.add(info);
}
}
}
}