使用 ReadOnlyPDOMProvider 导入索引内容

本文介绍如何生成和导入 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

请注意target和source参数。


为了测试导入,我编写了一个实现的类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;

            }

        }};

    }

路径正确吗?我实际上不知道这里应该返回哪个位置。


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


<extension

     point="org.eclipse.cdt.core.CIndex">

  <ReadOnlyPDOMProvider

        class="de.blub.plugin.MyReadOnlyPDOMProvider">

  </ReadOnlyPDOMProvider>

</extension>


当我右键单击testThis()并选择转到声明时,我希望转到/home/sadik/my-plugin-runtime-2019-06/CDTTest_Local/tests/indexer/declaration.h. 两个文件位于同一目录中。


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


路径缺少项目名称。所以我猜 pdom 文件存储的位置位于指定的源目录下面。我如何告诉 PDOMProvider 查看索引文件的正确目录?


qq_遁去的一_1
浏览 127回答 1
1回答

婷婷同学_

由于某种原因,尾随的“/”已被省略URIUtil.toURI(...)。但在它的描述中URIRealtiveLocationConverter说注意:提供的基本 URI 必须以正斜杠结尾因此,我从 String 创建一个 URI 实例,并将“/”附加到该字符串。@Overridepublic IPDOMDescriptor[] getDescriptors(ICConfigurationDescription config) {&nbsp; &nbsp; final IPath fileBase = Path.fromOSString("/home/sadik/eclipse-2019-06/eclipse/");&nbsp; &nbsp; final IPath projectBase = config.getProjectDescription().getProject().getFullPath();&nbsp; &nbsp; return new IPDOMDescriptor[] { new IPDOMDescriptor() {&nbsp; &nbsp; &nbsp; &nbsp; public IIndexLocationConverter getIndexLocationConverter() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; URI baseURI;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; baseURI = new URI(projectBase.toString()+"/");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return new URIRelativeLocationConverter(baseURI);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch (URISyntaxException e) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.printStackTrace();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; baseURI = URIUtil.toURI(projectBase);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return new URIRelativeLocationConverter(URIUtil.toURI(projectBase));&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public IPath getLocation() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IPath path = fileBase.append("pdomExample.pdom");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return path;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }};}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java