diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/index/provider/test/DummyProvider1.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/index/provider/test/DummyProvider1.java new file mode 100644 index 00000000000..d457a680d08 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/index/provider/test/DummyProvider1.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian Software Ltd. 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: + * Andrew Ferguson (Symbian) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.internal.index.provider.test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.index.provider.IPDOMDescriptor; +import org.eclipse.cdt.core.index.provider.IReadOnlyPDOMProvider; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.core.runtime.CoreException; + +/** + * Provides no pdom descriptors, used for testing the behaviour of IndexManager over + * project lifecycles. + */ +public class DummyProvider1 implements IReadOnlyPDOMProvider { + static List trace = Collections.synchronizedList(new ArrayList()); + + public static List getProjectsTrace() { + return trace; + } + + public IPDOMDescriptor[] getDescriptors(ICConfigurationDescription config) { + return new IPDOMDescriptor[0]; + } + + public boolean providesFor(ICProject project) throws CoreException { + trace.add(project); + return true; + } +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java new file mode 100644 index 00000000000..e52377c322a --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java @@ -0,0 +1,475 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.index.tests; + +import java.io.File; +import java.lang.reflect.Array; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor; +import org.eclipse.cdt.core.dom.IPDOMManager; +import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.provider.IIndexProvider; +import org.eclipse.cdt.core.internal.index.provider.test.DummyProvider1; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.core.settings.model.ICBuildSetting; +import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICExternalSetting; +import org.eclipse.cdt.core.settings.model.ICFileDescription; +import org.eclipse.cdt.core.settings.model.ICFolderDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.settings.model.ICResourceDescription; +import org.eclipse.cdt.core.settings.model.ICSettingContainer; +import org.eclipse.cdt.core.settings.model.ICSettingObject; +import org.eclipse.cdt.core.settings.model.ICSourceEntry; +import org.eclipse.cdt.core.settings.model.ICStorageElement; +import org.eclipse.cdt.core.settings.model.ICTargetPlatformSetting; +import org.eclipse.cdt.core.settings.model.WriteAccessException; +import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; +import org.eclipse.cdt.core.testplugin.CProjectHelper; +import org.eclipse.cdt.internal.core.index.IIndexFragment; +import org.eclipse.cdt.internal.core.index.provider.IIndexFragmentProvider; +import org.eclipse.cdt.internal.core.index.provider.IndexProviderManager; +import org.eclipse.cdt.internal.core.pdom.PDOMManager; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.QualifiedName; + +/** + * Example usage and test for IIndexProvider + */ +public class IndexProviderManagerTest extends IndexTestBase { + public IndexProviderManagerTest() { + super("IndexProviderManagerTest"); + } + + public static TestSuite suite() { + return suite(IndexProviderManagerTest.class); + } + + public void testProvider_SimpleLifeCycle() throws Exception { + DummyProvider1.getProjectsTrace().clear(); + List cprojects = new ArrayList(), expectedTrace = new ArrayList(); + try { + for(int i=0; i<3; i++) { + ICProject cproject = CProjectHelper.createCProject("P"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); + IIndex index = CCorePlugin.getIndexManager().getIndex(cproject); + cprojects.add(cproject); + expectedTrace.add(cproject); + } + assertEquals(expectedTrace, DummyProvider1.getProjectsTrace()); + for(int i=0; i + + + + diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index 09200e0bbf6..8918170bccc 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -23,6 +23,7 @@ Export-Package: org.eclipse.cdt.core, org.eclipse.cdt.core.formatter, org.eclipse.cdt.core.index, org.eclipse.cdt.core.index.export, + org.eclipse.cdt.core.index.provider, org.eclipse.cdt.core.model, org.eclipse.cdt.core.model.util, org.eclipse.cdt.core.parser, @@ -44,6 +45,7 @@ Export-Package: org.eclipse.cdt.core, org.eclipse.cdt.internal.core.dom.parser.cpp;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring", org.eclipse.cdt.internal.core.envvar, org.eclipse.cdt.internal.core.index;x-internal:=true, + org.eclipse.cdt.internal.core.index.provider, org.eclipse.cdt.internal.core.language, org.eclipse.cdt.internal.core.model;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring", org.eclipse.cdt.internal.core.model.ext;x-friends:="org.eclipse.cdt.ui", diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexManager.java index 36550b24095..0df7123718d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexManager.java @@ -32,10 +32,33 @@ import org.eclipse.core.runtime.IProgressMonitor; * @since 4.0 */ public interface IIndexManager { + /** + * Constant for passing to getIndex methods. This constant, when set, indicates + * projects referenced by the set of input projects should also be added + * to the resulting index. + */ public final static int ADD_DEPENDENCIES = 0x1; + + /** + * Constant for passing to getIndex methods. This constant, when set, indicates + * projects which reference any of the set of input projects should also be + * added to the resulting index. + */ public final static int ADD_DEPENDENT = 0x2; + /** + * Constant for passing to getIndex methods. This constant, when set, indicates + * that index content provided via the CIndex extension point should not be included + * in the resulting index, as it would have done otherwise. + */ + public final static int SKIP_PROVIDED = 0x4; + + /** + * Constant for indicating there is no time out period for joining the indexer job. + * @see IIndexManager#joinIndexer(int, IProgressMonitor) + */ public final static int FOREVER= -1; + /** * Returns the index for the given project. * @param project the project to get the index for diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/provider/IIndexProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/provider/IIndexProvider.java new file mode 100644 index 00000000000..f9e599bbd2b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/provider/IIndexProvider.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.core.index.provider; + +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.core.runtime.CoreException; + +/** + * An IIndexProvider implementation provides additional indexing information for CDT projects + * This interface only exists to hold commonality from sub-interfaces. + */ +public interface IIndexProvider { + /** + * This method is called to attach the index provider to the project specified. If the provider determines that it doesn't + * and will never provide indexes for the specified project, then it should return false to opt-out of being queried for + * that project. + *

+ * The method will only be called once per project per eclipse session. This method will be called when a project is deleted + * and a new project of the same name added. It also may be called lazily (at the point of first logical index use). + *

+ * It is also expected the provider implementation will want to watch some properties of the project to determine + * what index content to provide. + * @param project + * @return + */ + public boolean providesFor(ICProject project) throws CoreException; +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/provider/IPDOMDescriptor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/provider/IPDOMDescriptor.java new file mode 100644 index 00000000000..b7de50731b3 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/provider/IPDOMDescriptor.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.core.index.provider; + +import org.eclipse.cdt.core.index.IIndexLocationConverter; +import org.eclipse.core.runtime.IPath; + +/** + * + */ +public interface IPDOMDescriptor { + /** + * The absolute location in a local file system of the PDOM format file + * to contribute to the logical index. + * @return an absolute location of an existing file + */ + IPath getLocation(); + + /** + * An index location converter suitable of translating the internal + * formatted path representations to index locations representing the + * current content location. + * @return an index location converter + */ + IIndexLocationConverter getIndexLocationConverter(); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/provider/IReadOnlyPDOMProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/provider/IReadOnlyPDOMProvider.java new file mode 100644 index 00000000000..372775f99fe --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/provider/IReadOnlyPDOMProvider.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.core.index.provider; + +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; + +/** + * This interface is intended for ISVs to implement when plugging a mechanism + * for read-only/offline indexes into the CIndex.ReadOnlyPDOMProvider extension point element. + */ +public interface IReadOnlyPDOMProvider extends IIndexProvider { + /** + * Returns the descriptors + * @param cproject + * @param config + * @return + */ + public IPDOMDescriptor[] getDescriptors(ICConfigurationDescription config); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFactory.java index d0842f1cc49..560d454f337 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2007 Wind River Systems, Inc. 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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.internal.core.index; @@ -17,6 +18,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -25,6 +27,9 @@ import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.internal.core.index.provider.IndexProviderManager; import org.eclipse.cdt.internal.core.pdom.PDOMManager; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; @@ -36,6 +41,7 @@ import org.eclipse.core.runtime.CoreException; public class IndexFactory { private static final int ADD_DEPENDENCIES = IIndexManager.ADD_DEPENDENCIES; private static final int ADD_DEPENDENT = IIndexManager.ADD_DEPENDENT; + private static final int SKIP_PROVIDED = IIndexManager.SKIP_PROVIDED; private PDOMManager fPDOMManager; @@ -44,26 +50,37 @@ public class IndexFactory { } public IIndex getIndex(ICProject[] projects, int options) throws CoreException { + projects = (ICProject[]) ArrayUtil.removeNulls(ICProject.class, projects); + boolean addDependencies= (options & ADD_DEPENDENCIES) != 0; boolean addDependent= (options & ADD_DEPENDENT) != 0; + boolean skipProvided= (options & SKIP_PROVIDED) != 0; + IndexProviderManager m = ((PDOMManager)CCorePlugin.getPDOMManager()).getIndexProviderManager(); HashMap map= new HashMap(); Collection selectedProjects= getProjects(projects, addDependencies, addDependent, map, new Integer(1)); - ArrayList pdoms= new ArrayList(); + HashMap fragments= new LinkedHashMap(); for (Iterator iter = selectedProjects.iterator(); iter.hasNext(); ) { - ICProject project = (ICProject) iter.next(); - IWritableIndexFragment pdom= (IWritableIndexFragment) fPDOMManager.getPDOM(project); + ICProject cproject = (ICProject) iter.next(); + IWritableIndexFragment pdom= (IWritableIndexFragment) fPDOMManager.getPDOM(cproject); if (pdom != null) { - pdoms.add(pdom); + fragments.put(pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID), pdom); + + if(!skipProvided) { + ICConfigurationDescription activeCfg= CoreModel.getDefault().getProjectDescription(cproject.getProject()).getActiveConfiguration(); + IIndexFragment[] pFragments= m.getProvidedIndexFragments(activeCfg); + for(int i=0; i + * + *

+ * IndexProviders are registered via the extension point + * org.eclipse.cdt.core.CIndex + *

+ */ +public interface IIndexFragmentProvider extends IIndexProvider { + /** + * Returns an array of IIndexFragment objects to add to the specified {@link ICConfigurationDescription} + * @param project + * @return an array of IIndexFragment objects to add to the specified {@link ICConfigurationDescription} + */ + IIndexFragment[] getIndexFragments(ICConfigurationDescription config) throws CoreException; +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/provider/IndexProviderManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/provider/IndexProviderManager.java new file mode 100644 index 00000000000..4eccd877ade --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/provider/IndexProviderManager.java @@ -0,0 +1,187 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.provider; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.index.provider.IIndexProvider; +import org.eclipse.cdt.core.index.provider.IReadOnlyPDOMProvider; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ElementChangedEvent; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICElementDelta; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IElementChangedListener; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.internal.core.index.IIndexFragment; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; + + +/** + * The IndexProviderManager is responsible for maintaining the set of index + * fragments contributed via the CIndex extension point. This is done + * for the current project state (on a per-project basis). + *

+ * It is an internal class, and is public only for testing purposes. + */ +public final class IndexProviderManager implements IElementChangedListener { + public static final String READ_ONLY_PDOM_PROVIDER= "ReadOnlyPDOMProvider"; //$NON-NLS-1$ + private IIndexFragmentProvider[] allProviders; + + public IndexProviderManager() { + List providers = new ArrayList(); + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint indexProviders = registry.getExtensionPoint(CCorePlugin.INDEX_UNIQ_ID); + IExtension[] extensions = indexProviders.getExtensions(); + for(int i=0; i*/ path2pdom; // gives the pdom for a particular path + + private static PDOMCache singleton; + private static Object singletonMutex = new Object(); + + private PDOMCache() { + this.path2pdom = new HashMap(); + } + + /** + * Returns the instance of the cache + * @return + */ + public static PDOMCache getInstance() { + synchronized(singletonMutex) { + if(singleton == null) { + singleton = new PDOMCache(); + } + return singleton; + } + } + + /** + * Returns the mapped pdom for the path specified, if such a pdom is not already known about + * then one is created using the location converter specified. + * @param path + * @param converter + * @return a pdom instance + */ + public PDOM getPDOM(IPath path, IIndexLocationConverter converter) { + File file = path.toFile(); + synchronized(path2pdom) { + PDOM result = null; + if(path2pdom.containsKey(file)) { + result = (PDOM) path2pdom.get(file); + } + if(result==null) { + try { + result = new PDOM(file, converter); + } catch(CoreException ce) { + CCorePlugin.log(ce); + } + path2pdom.put(file, result); + } + return result; + } + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/provider/ReadOnlyPDOMProviderBridge.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/provider/ReadOnlyPDOMProviderBridge.java new file mode 100644 index 00000000000..d8dfd6b0a02 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/provider/ReadOnlyPDOMProviderBridge.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian 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: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.provider; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.index.provider.IPDOMDescriptor; +import org.eclipse.cdt.core.index.provider.IReadOnlyPDOMProvider; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.internal.core.index.IIndexFragment; +import org.eclipse.core.runtime.CoreException; + +/** + * Wraps the offline PDOM provider as an IIndexFragmentProvider + */ +public class ReadOnlyPDOMProviderBridge implements IIndexFragmentProvider { + protected IReadOnlyPDOMProvider opp; + + public ReadOnlyPDOMProviderBridge(IReadOnlyPDOMProvider opp) { + this.opp = opp; + } + + public IIndexFragment[] getIndexFragments(ICConfigurationDescription config) throws CoreException { + IPDOMDescriptor[] descs = opp.getDescriptors(config); + + List preresult = new ArrayList(); + + if(descs!=null) { + for(int i=0; i + @@ -45,7 +46,9 @@ - This element allows contribution of alternate IExportProjectProvider implementations. These can then be referenced by fully qualified class name in the command line tool (see option -pprovider). + <h2>ExportProjectProvider</h2> +<p> +This subelement of CIndex allows contribution of alternate IExportProjectProvider implementations. These can then be referenced by fully qualified class name in the command line tool (see option -pprovider). <p> <b>Invoking the application as a headless application</b> @@ -53,30 +56,30 @@ This example ant file shows how to invoke the tool headlessly, the same approach <pre> <project name="Generate PDOM" default="generate"> - <target name="generate"> - <!-- This script shows how to invoke the default project provider (ExternalExportProjectProvider) --> - <property name="pprovider" value="org.eclipse.cdt.core.index.export.ExternalExportProjectProvider"/> - <property name="target" value="C:\ExportedPDOMs\acmeSDK_2_5.pdom"/> <!-- Where the output pdom is to go --> - <property name="source" value="E:\AcmeSDK\v2.5\inc"/> <!-- e.g. the directory to source content from --> - <property name="id" value="com.acme.mysdk.v2.5"/> <!-- the id to store in the generate pdom --> - - <property name="eclipse.home" value="C:\eclipse"/> <!-- e.g. The eclipse installation to use. This installation must contain CDT 4.0+ plugins --> - - <java classname="org.eclipse.equinox.launcher.Main"> - <classpath> - <fileset dir="${eclipse.home}/plugins"> - <include name="*equinox.launcher*.jar"/> - </fileset> - </classpath> - <arg value="-nosplash"/> - <arg value="-exitdata"/> - <arg value="-application"/><arg value="org.eclipse.cdt.core.GeneratePDOM"/> - <arg value="-pprovider"/><arg value="${pprovider}"/> - <arg value="-source"/><arg value="${source}"/> - <arg value="-target"/><arg value="${target}"/> - <arg value="-id"/><arg value="${id}"/> - </java> - </target> + <target name="generate"> + <!-- This script shows how to invoke the default project provider (ExternalExportProjectProvider) --> + <property name="pprovider" value="org.eclipse.cdt.core.index.export.ExternalExportProjectProvider"/> + <property name="target" value="C:\ExportedPDOMs\acmeSDK_2_5.pdom"/> <!-- Where the output pdom is to go --> + <property name="source" value="E:\AcmeSDK\v2.5\inc"/> <!-- e.g. the directory to source content from --> + <property name="id" value="com.acme.mysdk.v2.5"/> <!-- the id to store in the generate pdom --> + + <property name="eclipse.home" value="C:\eclipse"/> <!-- e.g. The eclipse installation to use. This installation must contain CDT 4.0+ plugins --> + + <java classname="org.eclipse.equinox.launcher.Main"> + <classpath> + <fileset dir="${eclipse.home}/plugins"> + <include name="*equinox.launcher*.jar"/> + </fileset> + </classpath> + <arg value="-nosplash"/> + <arg value="-exitdata"/> + <arg value="-application"/><arg value="org.eclipse.cdt.core.GeneratePDOM"/> + <arg value="-pprovider"/><arg value="${pprovider}"/> + <arg value="-source"/><arg value="${source}"/> + <arg value="-target"/><arg value="${target}"/> + <arg value="-id"/><arg value="${id}"/> + </java> + </target> </project> </pre> <p> @@ -85,15 +88,15 @@ This example ant file shows how to invoke the tool headlessly, the same approach Specify "org.eclipse.cdt.core.GeneratePDOM" as the application to launch <p> In the Argument tabs provide (for example) - -target C:\ExportedPDOMs\acmeSDK_2_5.pdom -source E:\AcmeSDK\v2.5\inc -include E:\this.h -id com.acme.mysdk.v2.5 + -target C:\ExportedPDOMs\acmeSDK_2_5.pdom -source E:\AcmeSDK\v2.5\inc -include E:\this.h -id com.acme.mysdk.v2.5 <p> - + - + the fully qualified name of the IExportProjectProvider implementation to register @@ -103,6 +106,66 @@ In the Argument tabs provide (for example) + + + + <h2>ReadOnlyPDOMProvider</h2> +<p> +This subelement of CIndex allows ISVs to contribute read-only prebuilt PDOM files to the CDT Index. The only information needed is the fully qualified class name of an implementatin of org.eclipse.cdt.core.index.IOfflinePDOMProvider. This implementation will be consulted during the eclipse session for the appropriate read-only content to make add to the logical index. The logical index is accessible via the org.eclipse.core.index.IIndex API. + + An example of contributing a prebuilt read-only pdom: +<pre> +<CIndex> + <ReadOnlyPDOMProvider class="com.acme.ide.index.AcmeSDKProvider"/> +</CIndex> +</pre> + +and the corresponding implementation + +<pre> +package com.acme.ide.index.sdk; + +import org.eclipse.core.index.provider.IReadOnlyPDOMProvider; +import org.eclipse.core.index.provider.IPDOMDescriptor; +import org.eclipse.core.index.IIndexLocationConverter; +import org.eclipse.core.index.URIRelativeLocationConverter; + +public class AcmeSDKProvider implements IReadOnlyPDOMProvider { + public boolean providesFor(ICProject project) { + // e.g. decide by looking for acme project nature + return AcmeNature.isAcmeProject(project); + } + + public IPDOMDescriptor[] getDescriptors(ICProject cproject, ICConfigurationDescription config) { + final IPath sdkBase = AcmeSDKAPI.getSDKBase(cproject, config); + return new IPDOMDescriptor[] { new IPDOMDescriptor() { + public IIndexLocationConverter getIndexLocationConverter() { + return new URIRelativeLocationConverter(URIUtil.toURI(sdkBase)); + } + public IPath getLocation() { + IPath path = sdkBase.append(AcmeSDKAPI.getPrebuiltPDOMFilename(config)); + return path; + } + }}; + } +} +</pre> + + + + + + + the fully qualified name of the IReadOnlyPDOMProvider implementation to register + + + + + + + + + diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoLabelProvider.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoLabelProvider.java index 47c83d9862f..c87cf8efc5c 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoLabelProvider.java +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoLabelProvider.java @@ -8,19 +8,23 @@ * Contributors: * IBM Corporation - initial API and implementation * QNX Software Systems - adapted for use in CDT + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.ui.browser.typeinfo; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; + import org.eclipse.cdt.core.browser.IQualifiedTypeName; import org.eclipse.cdt.core.browser.ITypeInfo; import org.eclipse.cdt.core.browser.ITypeReference; 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.ui.CPluginImages; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.graphics.Image; public class TypeInfoLabelProvider extends LabelProvider { @@ -112,7 +116,12 @@ public class TypeInfoLabelProvider extends LabelProvider { ITypeReference ref = typeRef.getResolvedReference(); if (ref != null) { path = ref.getPath(); - if (CoreModel.isValidHeaderUnitName(typeRef.getEnclosingProject().getProject(), path.lastSegment())) { + + // IndexTypeInfo may not have an enclosing project + ICProject cproject = typeRef.getEnclosingProject(); + IProject project = cproject==null ? null : cproject.getProject(); + + if (CoreModel.isValidHeaderUnitName(project, path.lastSegment())) { return HEADER_ICON; } }