【发布时间】:2019-08-07 08:37:58
【问题描述】:
问题一:我找不到org.eclipse.cdt.core.index.IIndexer
来自 API:
API信息:想要扩展这个扩展点的插件必须实现org.eclipse.cdt.core.index.IIndexer接口。
API 信息是否不正确/已弃用?如果不是 IIndexer,应该实现哪个接口?
问题 2:我可以在 CDT 6.8 版(eclipse 2019-06)中安装我自己的索引器,但不能在 6.5 版(eclipse 2018-09)中安装,但我看不出有什么区别插件代码。
更多详情:
我的索引器类:
@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);
}
}
plugin.xml
<extension
id="org.eclipse.cdt.core.fastIndexer"
name="My Indexer"
point="org.eclipse.cdt.core.CIndexer">
<run
class="de.blub.MyIndexer">
</run>
MANIFEST.MF 文件在 Require-Bundle 部分列出了 org.eclipse.cdt.core,但没有 bundle-version。当然cdt插件有不同的版本:
在 Eclipse 2019-06 中:
Eclipse CDT C/C++ 开发工具核心 6.8.1.201907021957 org.eclipse.cdt.core
在 Eclipse 2018-09 中:
Eclipse CDT C/C++ 开发工具核心 6.5.0.201811180605 org.eclipse.cdt.core
此代码来自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;
}
两个 cdt 版本的代码相同。 indexer 在 2018-09 日食中变为 PDOMFastIndexer,但在 2019-06 中变为 MyIndexer。
我可以看到的一个区别是RegistryObjectManager
private Object basicGetObject(int id, byte type) {
Object result = cache.get(id);
if (result != null)
return result;
...
}
一个 id 用于从 cache 对象中获取正确的 ConfigurationElement (result),我不太了解它是如何构建的。但是,返回的 ConfigurationElement 包含一个字段 propertiesAnsValues,这在一种情况下是不正确的(org.eclipse.cdt.internal.core.pdom.indexer.PDOMFastIndexer 而不是 de.blub.MyIndexer)。
如何解决这个问题,以便在 eclipse 2018-09 中也拥有自己的索引器? 还请注意我的问题 1。因为如果 API 描述是正确的,这意味着我试图以错误的方式安装我的索引器,需要做一些事情来“查看”IIndexer 接口。
【问题讨论】:
标签: eclipse-cdt