Search code examples
eclipse-cdt

Eclipse CDT: Problems with extension point CIndexer


Problem 1: I can't find org.eclipse.cdt.core.index.IIndexer

From the API:

API Information: Plug-ins that want to extend this extension point must implement org.eclipse.cdt.core.index.IIndexer interface.

Is the API Information incorrect/deprecated? Which interface should be implemented if not IIndexer?

Problem 2: I can install my own Indexer in CDT version 6.8 (eclipse 2019-06) but not in version 6.5 (eclipse 2018-09), though I don't see the difference in the plugin code.

More Details:

My Indexer class:

@SuppressWarnings("restriction")
public class MyIndexer extends PDOMFastIndexer {

    public static final String ID = "de.blub.MyIndexer";

    @Override
    public String getID() {
        return ID;
    }

    @Override
    public IPDOMIndexerTask createTask(ITranslationUnit[] added, ITranslationUnit[] changed,
        ITranslationUnit[] removed) {
    if (...) {
        return new MyIndexerTask(added, changed, removed, this, true);
    } else {
        return super.createTask(added, changed, removed);
    }

}

The plugin.xml

<extension
     id="org.eclipse.cdt.core.fastIndexer"
     name="My Indexer"
     point="org.eclipse.cdt.core.CIndexer">
  <run
        class="de.blub.MyIndexer">
  </run>

The MANIFEST.MF File lists org.eclipse.cdt.core in the Require-Bundle section without bundle-version. Of course the cdt plugin has different versions:

In Eclipse 2019-06:

Eclipse CDT C/C++ Development Tools Core 6.8.1.201907021957 org.eclipse.cdt.core

In Eclipse 2018-09:

Eclipse CDT C/C++ Development Tools Core 6.5.0.201811180605 org.eclipse.cdt.core

This code is from org.eclipse.cdt.internal.core.pdom.PDOMManager:

private IPDOMIndexer newIndexer(String indexerId, Properties props) throws CoreException  {
    IPDOMIndexer indexer = null;
    // Look up in extension point
    IExtension indexerExt = Platform.getExtensionRegistry().getExtension(CCorePlugin.INDEXER_UNIQ_ID, indexerId);
    if (indexerExt != null) {
        IConfigurationElement[] elements = indexerExt.getConfigurationElements();
        for (IConfigurationElement element : elements) {
            if ("run".equals(element.getName())) { //$NON-NLS-1$
                try {
                    indexer = (IPDOMIndexer) element.createExecutableExtension("class"); //$NON-NLS-1$
                    indexer.setProperties(props);
                } catch (CoreException e) {
                    CCorePlugin.log(e);
                }
                break;
            }
        }
    }

    // Unknown index, default to the null one
    if (indexer == null)
        indexer = new PDOMNullIndexer();

    return indexer;
}

The code is the same for both cdt versions. indexer becomes a PDOMFastIndexer in eclipse 2018-09, but a MyIndexer in 2019-06.

One difference I could see is that in RegistryObjectManager

private Object basicGetObject(int id, byte type) {
    Object result = cache.get(id);
    if (result != null)
        return result;
    ...
}

An id is used to get the correct ConfigurationElement (result) from a cache object, which I don't really understand how it is built up. However, the returned ConfigurationElement contains a field propertiesAnsValues which is incorrect in the one case (org.eclipse.cdt.internal.core.pdom.indexer.PDOMFastIndexer instead of de.blub.MyIndexer).

How can I fix that to have my own indexer in eclipse 2018-09, too? Please also note my Problem 1. Because if the API description is correct, it means I'm trying to install my indexer the wrong way and need to do something to 'see' the IIndexer interface.


Solution

  • According to the schema definition, the class you need to derive from is IPDOMIndexer (which you're already doing). You can also tell this from the PDOMManager code you quoted, which casts the result of createExecutableExtension() to IPDOMIndexer.

    (The comment saying to use org.eclipse.cdt.core.index.IIndexer is indeed out of date. Based on a brief look, that interface hasn't existed since at least 2005. Patches to update the extension point documentation are welcome.)

    As for your second problem, I believe it's because you're using id="org.eclipse.cdt.core.fastIndexer" for your extension, which is already in use by one of CDT's built-in indexers. The id needs to identify your extension uniquely (so you can make it something like myproject.MyIndexer.)