简体   繁体   English

IntelliJ IDEA插件:跳转到自定义xml的声明

[英]IntelliJ IDEA plugin : Jump to declaration for custom xml

I have component based application. 我有基于组件的应用程序。 All of the components are defined in XML. 所有组件均以XML定义。 The components may be defined in different xml files. 组件可以在不同的xml文件中定义。

<!-- filename: components.xml -->

<components>
   <component type="x" name="y">
      <property1 attribute="attr"/>
      <property2 attribute="attr"/>
   </component>
   <component type="a" name="b">
      <property1 attribute="attr"/>
      …
   </component>
 </components>


<!-- filename: extra-components.xml -->
<components>
    <component type="x" name="z" extends="x:y">  <!-- this extends component x:y -->
        <property3 attribute="attr"/>
    </component>
</components>

Right now I'm trying to write a plugin so that I can jump from the child components to parent component. 现在,我正在尝试编写一个插件,以便可以从子组件跳到父组件。 In the example above, the component type 'x' and name 'z' extends component type 'x' and name 'y'. 在上面的示例中,组件类型“ x”和名称“ z”扩展了组件类型“ x”和名称“ y”。

Going throughs some of the source from different plugins, I was able to add a menu item and grab content under the caret. 通过查看来自不同插件的一些资源,我能够添加菜单项并在插入符号下获取内容。

Say, if my caret is under "x:y" in second component, I can garb x and y so at least I can know the component type and component name to look for. 说,如果我的插入符号在第二个组件中的“ x:y”下,则可以加扰x和y,这样至少我可以知道要查找的组件类型和组件名称。

But I want to underline the contents under extends ie "x:y" when I press ctrl and search for the component and jump to the declaration of the component when ctrl+click like we jump to declaration of class. 但是我想在我按下ctrl并搜索组件并在ctrl + click时跳转到组件的声明时在extends的下划线,即“ x:y”,就像我们跳转到类的声明一样。

I want guidance like which class should I look, how should I go or similar implementation. 我想要一些指导,例如我应该看哪个班级,应该如何去学习或类似的实现。

Thanks 谢谢

I think what you are looking for is a reference contributor . 我认为您正在寻找的是参考贡献者

See this answer for more details on how to set up a contributor. 有关如何设置贡献者的更多详细信息,请参见此答案 Once this contributor is created, I think you'll have two ways to find which XML element x:y refers to: 创建该贡献者之后,我想您将有两种方法来查找x:y所指的XML元素:

  • parse every potential XML file and try to find a tag with the correct attributes, then return the corresponding PsiElement 解析每个潜在的XML文件并尝试查找具有正确属性的标签,然后返回相应的PsiElement
  • create an index of every component tag, and lookup x:y in this index (requires much more work) 创建每个component标签的索引 ,并在此索引中查找x:y (需要更多工作)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM