diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index f4e309fb444..29cf0b35e4a 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -36,7 +36,7 @@ Export-Package: org.eclipse.cdt.core, org.eclipse.cdt.core.settings.model.extension.impl, org.eclipse.cdt.core.settings.model.util, org.eclipse.cdt.internal.core;x-friends:="org.eclipse.cdt.ui", - org.eclipse.cdt.internal.core.browser.util;x-internal:=true, + org.eclipse.cdt.internal.core.browser.util;x-friends:="org.eclipse.cdt.ui", org.eclipse.cdt.internal.core.dom;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring", org.eclipse.cdt.internal.core.dom.parser;x-friends:="org.eclipse.cdt.refactoring", org.eclipse.cdt.internal.core.dom.parser.c;x-friends:="org.eclipse.cdt.refactoring", diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/AllTypesCache.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/AllTypesCache.java index b394639de78..93fa0542e7a 100644 --- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/AllTypesCache.java +++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/AllTypesCache.java @@ -7,33 +7,24 @@ * * Contributors: * QNX Software Systems - initial API and implementation + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.core.browser; -import java.util.ArrayList; -import java.util.List; +import java.util.regex.Pattern; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ILinkage; -import org.eclipse.cdt.core.dom.IPDOMNode; -import org.eclipse.cdt.core.dom.IPDOMVisitor; -import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.ICompositeType; -import org.eclipse.cdt.core.dom.ast.IEnumeration; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias; +import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.internal.core.CCoreInternals; -import org.eclipse.cdt.internal.core.pdom.PDOM; -import org.eclipse.cdt.internal.core.pdom.PDOMManager; -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.c.PDOMCStructure; +import org.eclipse.cdt.internal.core.browser.util.IndexModelUtil; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; /** * Manages a search cache for types in the workspace. Instead of returning @@ -49,137 +40,69 @@ import org.eclipse.core.runtime.CoreException; * waits for the completion of the background job. */ public class AllTypesCache { + private static final boolean DEBUG = false; + + private static ITypeInfo[] getTypes(ICProject[] projects, final int[] kinds, IProgressMonitor monitor) throws CoreException { + IIndex index = CCorePlugin.getIndexManager().getIndex(projects); + + try { + index.acquireReadLock(); + + long start = System.currentTimeMillis(); + + IIndexBinding[] all = + index.findBindings(Pattern.compile(".*"), false, new IndexFilter() { //$NON-NLS-1$ + public boolean acceptBinding(IBinding binding) { + return IndexModelUtil.bindingHasCElementType(binding, kinds); + }}, + monitor + ); + + if(DEBUG) { + System.out.println("Index search took "+(System.currentTimeMillis() - start)); //$NON-NLS-1$ + start = System.currentTimeMillis(); + } + + ITypeInfo[] result = new ITypeInfo[all.length]; + for(int i=0; inull * is returned. diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/PDOMTypeInfo.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java similarity index 58% rename from core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/PDOMTypeInfo.java rename to core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java index 64d410561de..96b9f26867f 100644 --- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/PDOMTypeInfo.java +++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 QNX Software Systems and others. + * Copyright (c) 2006, 2007 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,40 +8,46 @@ * Contributors: * QNX - Initial API and implementation * IBM Corporation + * Andrew Ferguson (Symbian) *******************************************************************************/ - package org.eclipse.cdt.core.browser; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.IName; -import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.cdt.core.index.IIndexFileLocation; +import org.eclipse.cdt.core.index.IIndexName; +import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.internal.core.CCoreInternals; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor; -import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.internal.core.browser.util.IndexModelUtil; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; +import org.eclipse.core.filesystem.URIUtil; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; /** * @author Doug Schaefer * */ -public class PDOMTypeInfo implements ITypeInfo { - - private final IBinding binding; +public class IndexTypeInfo implements ITypeInfo { + private final String[] fqn; private final int elementType; - private final ICProject project; - - public PDOMTypeInfo(IBinding binding, int elementType, ICProject project) { - this.binding = binding; - this.elementType = elementType; - this.project = project; - } + private final IIndex index; + private ITypeReference reference; // lazily constructed + public IndexTypeInfo(String[] fqn, int elementType, IIndex index) { + this.fqn = fqn; + this.elementType = elementType; + this.index = index; + } + public void addDerivedReference(ITypeReference location) { throw new PDOMNotImplementedError(); } @@ -83,7 +89,13 @@ public class PDOMTypeInfo implements ITypeInfo { } public ICProject getEnclosingProject() { - return project; + if(getResolvedReference()!=null) { + IProject project = reference.getProject(); + if(project!=null) { + return CCorePlugin.getDefault().getCoreModel().getCModel().getCProject(project.getName()); + } + } + return null; } public ITypeInfo getEnclosingType() { @@ -96,23 +108,11 @@ public class PDOMTypeInfo implements ITypeInfo { } public String getName() { - return binding.getName(); + return fqn[fqn.length-1]; } public IQualifiedTypeName getQualifiedTypeName() { - String qn; - if(binding instanceof ICPPBinding) { - try { - qn = CPPVisitor.renderQualifiedName(((ICPPBinding)binding).getQualifiedName()); - } catch(DOMException de) { - CCorePlugin.log(de); // can't happen when (binding instanceof PDOMBinding) - return null; - } - } else { - qn = binding.getName(); - } - - return new QualifiedTypeName(qn); + return new QualifiedTypeName(fqn); } public ITypeReference[] getReferences() { @@ -120,14 +120,50 @@ public class PDOMTypeInfo implements ITypeInfo { } public ITypeReference getResolvedReference() { - try { - PDOM pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); - IName[] names= pdom.findNames(binding, IIndex.FIND_DEFINITIONS); - return names != null && names.length > 0 ? new PDOMTypeReference(names[0], project) : null; - } catch (CoreException e) { - CCorePlugin.log(e); - return null; + if(reference==null) { + try { + index.acquireReadLock(); + + char[][] cfqn = new char[fqn.length][]; + for(int i=0; i0) { + IIndexName[] names = index.findNames(ibs[0], IIndex.FIND_DEFINITIONS); + if(names.length>0) { + IIndexFileLocation ifl = names[0].getFile().getLocation(); + String fullPath = ifl.getFullPath(); + if(fullPath!=null) { + IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fullPath)); + if(file!=null) { + reference = new TypeReference( + file, file.getProject(), names[0].getNodeOffset(), names[0].getNodeLength() + ); + } + } else { + IPath path = URIUtil.toPath(ifl.getURI()); + if(path!=null) { + reference = new TypeReference( + path, null, names[0].getNodeOffset(), names[0].getNodeLength() + ); + } + } + } + } + } catch(CoreException ce) { + CCorePlugin.log(ce); + } catch (InterruptedException ie) { + CCorePlugin.log(ie); + } finally { + index.releaseReadLock(); + } } + return reference; } public ITypeInfo getRootNamespace(boolean includeGlobalNamespace) { diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/PDOMTypeReference.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/PDOMTypeReference.java deleted file mode 100644 index 5765e6b0728..00000000000 --- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/PDOMTypeReference.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * QNX - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.core.browser; - -import org.eclipse.cdt.core.dom.IName; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.model.IWorkingCopy; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; - -/** - * @author Doug Schaefer - * - */ -public class PDOMTypeReference implements ITypeReference { - - private final IName name; - private final ICProject project; - private final IPath path; - - public PDOMTypeReference(IName name, ICProject project) { - this.name = name; - this.project = project; - this.path = new Path(name.getFileLocation().getFileName()); - } - - public ICElement[] getCElements() { - throw new PDOMNotImplementedError(); - } - - public int getLength() { - return name.getFileLocation().getNodeLength(); - } - - public IPath getLocation() { - return path; - } - - public int getOffset() { - return name.getFileLocation().getNodeOffset(); - } - - public IPath getPath() { - return path; - } - - public IProject getProject() { - throw new PDOMNotImplementedError(); - } - - public IPath getRelativeIncludePath(IProject project) { - throw new PDOMNotImplementedError(); - } - - public IPath getRelativePath(IPath relativeToPath) { - throw new PDOMNotImplementedError(); - } - - public IResource getResource() { - throw new PDOMNotImplementedError(); - } - - public ITranslationUnit getTranslationUnit() { - ICElement element = CoreModel.getDefault().create(path); - if (element != null && element instanceof ITranslationUnit) - return (ITranslationUnit)element; - else - return CoreModel.getDefault().createTranslationUnitFrom(project, path); - } - - public IWorkingCopy getWorkingCopy() { - throw new PDOMNotImplementedError(); - } - - public boolean isLineNumber() { - return name.getFileLocation().getNodeLength() == -1; - } - -} diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/util/IndexModelUtil.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/util/IndexModelUtil.java new file mode 100644 index 00000000000..b0e14ea7d08 --- /dev/null +++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/util/IndexModelUtil.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX - Initial API and implementation + * IBM Corporation + * Andrew Ferguson (Symbian) + *******************************************************************************/ +package org.eclipse.cdt.internal.core.browser.util; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IEnumeration; +import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias; +import org.eclipse.cdt.core.model.ICElement; + +/** + * Convenience class for bridging the model gap between binding types and CModel types + * + * This is internal in case some IBinding's do not have ICElement constants in future + */ +public class IndexModelUtil { + /** + * Returns whether the binding is of any of the specified CElement type constants + * @param binding + * @param kinds + * @return whether the binding is of any of the specified CElement type constants + */ + public static boolean bindingHasCElementType(IBinding binding, int[] kinds) { + try { + for(int i=0; i0) + try { + IIndex index = CCorePlugin.getIndexManager().getIndex(CoreModel.getDefault().getCModel().getCProjects()); + try { + index.acquireReadLock(); + IBinding[] bindings= index.findBindingsForPrefix(prefix, IndexFilter.ALL, false); + for(int i=0; i