Java 使用ReadOnlyPDOMProvider导入索引内容

Java 使用ReadOnlyPDOMProvider导入索引内容,java,eclipse-plugin,eclipse-cdt,Java,Eclipse Plugin,Eclipse Cdt,本文介绍如何生成和导入PDOM索引。 调用生成应用程序GeneratePDOM后,我得到了一个pdom文件/home/sadik/eclipse-2019-06/eclipse/pdomExample.pdom。但是我在导入文件时遇到问题 要生成的命令如下所示: java -jar plugins/org.eclipse.equinox.launcher_1.5.400.v20190515-0925.jar -application "org.eclipse.cdt.core.Generate

本文介绍如何生成和导入PDOM索引。 调用生成应用程序
GeneratePDOM
后,我得到了一个pdom文件
/home/sadik/eclipse-2019-06/eclipse/pdomExample.pdom
。但是我在导入文件时遇到问题

要生成的命令如下所示:

 java -jar plugins/org.eclipse.equinox.launcher_1.5.400.v20190515-0925.jar -application "org.eclipse.cdt.core.GeneratePDOM" -target /home/sadik/eclipse-2019-06/eclipse/pdomExample.pdom -source /home/sadik/my-plugin-runtime-2019-06/CDTTest_Local/ -id cdttest_01 -indexer org.eclipse.cdt.core.myfastIndexer
请注意
目标
参数

为了测试导入,我编写了一个实现
IReadOnlyPDOMProvider

public class MyReadOnlyPDOMProvider implements IReadOnlyPDOMProvider {

    public MyReadOnlyPDOMProvider() {
        System.out.println("PDOMProvider");
    }

    @Override
    public boolean providesFor(ICProject project) throws CoreException {
        return true;
    }

    @Override
    public IPDOMDescriptor[] getDescriptors(ICConfigurationDescription config) {
        final IPath fileBase = Path.fromOSString("/home/sadik/eclipse-2019-06/eclipse/");
        final IPath projectBase = Path.fromOSString("/home/sadik/my-plugin-runtime-2019-06/CDTTest_Local/");
        return new IPDOMDescriptor[] { new IPDOMDescriptor() {
            public IIndexLocationConverter getIndexLocationConverter() {
                return new URIRelativeLocationConverter(URIUtil.toURI(projectBase));
            }
            public IPath getLocation() {
                IPath path = fileBase.append("pdomExample.pdom");
                return path;
            }
        }};
    }
路径正确吗?我真的不知道这里应该返回什么位置

我在插件的
Plugin.xml
中的CDT扩展点
CIndex
中定义了该类:

<extension
     point="org.eclipse.cdt.core.CIndex">
  <ReadOnlyPDOMProvider
        class="de.blub.plugin.MyReadOnlyPDOMProvider">
  </ReadOnlyPDOMProvider>
</extension>
当我右键单击
testThis()
并选择go to declaration时,我希望转到
/home/sadik/my-plugin-runtime-2019-06/CDTTest\u Local/tests/indexer/declaration.h
中的函数声明。两个文件位于同一目录中

但实际情况是,打开编辑器时会显示一个空文件。编辑器甚至告诉我路径:
/home/soezoguz/rtt-plugin-runtime-2019-06/tests/indexer/declaration.h


路径缺少项目名称。因此,我猜pdom文件在指定的源目录下存储位置。我如何告诉PDOMProvider查找索引文件的正确目录?

由于某种原因,
URIUtil.toURI(…)
使用了尾随“/”。但是在
URIRealtiveLocationConverter
的描述中,它说

注意:提供的基本URI必须以正斜杠结尾

因此,我从字符串创建了一个URI实例,并在字符串中附加了“/”

@Override
public IPDOMDescriptor[] getDescriptors(ICConfigurationDescription config) {
    final IPath fileBase = Path.fromOSString("/home/sadik/eclipse-2019-06/eclipse/");
    final IPath projectBase = config.getProjectDescription().getProject().getFullPath();
    return new IPDOMDescriptor[] { new IPDOMDescriptor() {
        public IIndexLocationConverter getIndexLocationConverter() {
            URI baseURI;
            try {
                baseURI = new URI(projectBase.toString()+"/");
                return new URIRelativeLocationConverter(baseURI);
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
            baseURI = URIUtil.toURI(projectBase);
            return new URIRelativeLocationConverter(URIUtil.toURI(projectBase));
        }
        public IPath getLocation() {
            IPath path = fileBase.append("pdomExample.pdom");
            return path;
        }
    }};
}

由于某种原因,
URIUtil.toURI(…)
使用了尾随“/”。但是在
URIRealtiveLocationConverter
的描述中,它说

注意:提供的基本URI必须以正斜杠结尾

因此,我从字符串创建了一个URI实例,并在字符串中附加了“/”

@Override
public IPDOMDescriptor[] getDescriptors(ICConfigurationDescription config) {
    final IPath fileBase = Path.fromOSString("/home/sadik/eclipse-2019-06/eclipse/");
    final IPath projectBase = config.getProjectDescription().getProject().getFullPath();
    return new IPDOMDescriptor[] { new IPDOMDescriptor() {
        public IIndexLocationConverter getIndexLocationConverter() {
            URI baseURI;
            try {
                baseURI = new URI(projectBase.toString()+"/");
                return new URIRelativeLocationConverter(baseURI);
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
            baseURI = URIUtil.toURI(projectBase);
            return new URIRelativeLocationConverter(URIUtil.toURI(projectBase));
        }
        public IPath getLocation() {
            IPath path = fileBase.append("pdomExample.pdom");
            return path;
        }
    }};
}