1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-01 05:15:43 +02:00

Got the Namespace and Base Class browsers working in the New Class Wizard.

This commit is contained in:
Doug Schaefer 2006-04-21 16:12:54 +00:00
parent 7729196702
commit f1d3ff83c4
2 changed files with 36 additions and 58 deletions

View file

@ -11,7 +11,6 @@
package org.eclipse.cdt.core.browser; package org.eclipse.cdt.core.browser;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
@ -25,12 +24,13 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.browser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCStructure; import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCStructure;
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPClassType; import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPClassType;
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPNamespace;
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPNamespaceAlias;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
@ -106,6 +106,8 @@ public class AllTypesCache {
try { try {
switch (kind) { switch (kind) {
case ICElement.C_NAMESPACE: case ICElement.C_NAMESPACE:
if (node instanceof PDOMCPPNamespace || node instanceof PDOMCPPNamespaceAlias)
types.add(new PDOMTypeInfo((PDOMBinding)node, kind, project));
return; return;
case ICElement.C_CLASS: case ICElement.C_CLASS:
if (node instanceof PDOMCPPClassType if (node instanceof PDOMCPPClassType
@ -133,19 +135,14 @@ public class AllTypesCache {
} }
} }
/** private static ITypeInfo[] getTypes(ICProject[] projects, int[] kinds) throws CoreException {
* Returns all types in the workspace.
*/
public static ITypeInfo[] getAllTypes() {
try {
List types = new ArrayList(); List types = new ArrayList();
IPDOMManager pdomManager = CCorePlugin.getPDOMManager(); IPDOMManager pdomManager = CCorePlugin.getPDOMManager();
ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects();
for (int i = 0; i < projects.length; ++i) { for (int i = 0; i < projects.length; ++i) {
ICProject project = projects[i]; ICProject project = projects[i];
CTypesCollector cCollector = new CTypesCollector(ITypeInfo.KNOWN_TYPES, types, project); CTypesCollector cCollector = new CTypesCollector(kinds, types, project);
CPPTypesCollector cppCollector = new CPPTypesCollector(ITypeInfo.KNOWN_TYPES, types, project); CPPTypesCollector cppCollector = new CPPTypesCollector(kinds, types, project);
PDOM pdom = (PDOM)pdomManager.getPDOM(project); PDOM pdom = (PDOM)pdomManager.getPDOM(project);
PDOMLinkage cLinkage = pdom.getLinkage(GCCLanguage.getDefault()); PDOMLinkage cLinkage = pdom.getLinkage(GCCLanguage.getDefault());
@ -155,6 +152,15 @@ public class AllTypesCache {
} }
return (ITypeInfo[])types.toArray(new ITypeInfo[types.size()]); return (ITypeInfo[])types.toArray(new ITypeInfo[types.size()]);
}
/**
* Returns all types in the workspace.
*/
public static ITypeInfo[] getAllTypes() {
try {
ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects();
return getTypes(projects, ITypeInfo.KNOWN_TYPES);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
return new ITypeInfo[0]; return new ITypeInfo[0];
@ -169,24 +175,12 @@ public class AllTypesCache {
* C_UNION, C_ENUMERATION, C_TYPEDEF * C_UNION, C_ENUMERATION, C_TYPEDEF
*/ */
public static ITypeInfo[] getTypes(ITypeSearchScope scope, int[] kinds) { public static ITypeInfo[] getTypes(ITypeSearchScope scope, int[] kinds) {
final Collection fTypesFound = new ArrayList(); try {
final ITypeSearchScope fScope = scope; return getTypes(scope.getEnclosingProjects(), kinds);
final int[] fKinds = kinds; } catch (CoreException e) {
ICProject[] projects = scope.getEnclosingProjects(); CCorePlugin.log(e);
ITypeInfoVisitor visitor = new ITypeInfoVisitor() { return new ITypeInfo[0];
public boolean visit(ITypeInfo info) {
if (ArrayUtil.contains(fKinds, info.getCElementType())
&& (fScope != null && info.isEnclosed(fScope))) {
fTypesFound.add(info);
} }
return true;
}
public boolean shouldContinue() { return true; }
};
for (int i = 0; i < projects.length; ++i) {
// TypeCacheManager.getInstance().getCache(projects[i]).accept(visitor);
}
return (ITypeInfo[]) fTypesFound.toArray(new ITypeInfo[fTypesFound.size()]);
} }
/** /**
@ -196,27 +190,12 @@ public class AllTypesCache {
* @param includeGlobalNamespace <code>true</code> if the global (default) namespace should be returned * @param includeGlobalNamespace <code>true</code> if the global (default) namespace should be returned
*/ */
public static ITypeInfo[] getNamespaces(ITypeSearchScope scope, boolean includeGlobalNamespace) { public static ITypeInfo[] getNamespaces(ITypeSearchScope scope, boolean includeGlobalNamespace) {
final Collection fTypesFound = new ArrayList(); try {
final ITypeSearchScope fScope = scope; return getTypes(scope.getEnclosingProjects(), new int[] {ICElement.C_NAMESPACE});
ICProject[] projects = scope.getEnclosingProjects(); } catch (CoreException e) {
ITypeInfoVisitor visitor = new ITypeInfoVisitor() { CCorePlugin.log(e);
public boolean visit(ITypeInfo info) { return new ITypeInfo[0];
if (info.getCElementType() == ICElement.C_NAMESPACE
&& (fScope != null && info.isEnclosed(fScope))) {
fTypesFound.add(info);
} }
return true;
}
public boolean shouldContinue() { return true; }
};
for (int i = 0; i < projects.length; ++i) {
// ITypeCache cache = TypeCacheManager.getInstance().getCache(projects[i]);
// cache.accept(visitor);
// if (includeGlobalNamespace) {
// fTypesFound.add(cache.getGlobalNamespace());
// }
}
return (ITypeInfo[]) fTypesFound.toArray(new ITypeInfo[fTypesFound.size()]);
} }
/** Returns first type in the cache which matches the given /** Returns first type in the cache which matches the given
@ -244,8 +223,7 @@ public class AllTypesCache {
* @return Array of types * @return Array of types
*/ */
public static ITypeInfo[] getTypes(ICProject project, IQualifiedTypeName qualifiedName, boolean matchEnclosed, boolean ignoreCase) { public static ITypeInfo[] getTypes(ICProject project, IQualifiedTypeName qualifiedName, boolean matchEnclosed, boolean ignoreCase) {
// ITypeCache cache = TypeCacheManager.getInstance().getCache(project); // TODO - do we really need this feature? It could be really slow
// return cache.getTypes(qualifiedName, matchEnclosed, ignoreCase);
return new ITypeInfo[0]; return new ITypeInfo[0];
} }

View file

@ -48,7 +48,7 @@ public class PDOMTypeReference implements ITypeReference {
} }
public IPath getLocation() { public IPath getLocation() {
throw new PDOMNotImplementedError(); return path;
} }
public int getOffset() { public int getOffset() {