gpt4 book ai didi

java - IntelliJ IDEA 插件 : Jump to declaration for custom xml

转载 作者:行者123 更新时间:2023-11-29 05:33:10 25 4
gpt4 key购买 nike

我有基于组件的应用程序。所有组件都在 XML 中定义。组件可以在不同的 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>

现在我正在尝试编写一个插件,以便我可以从子组件跳转到父组件。在上面的示例中,组件类型“x”和名称“z”扩展了组件类型“x”和名称“y”。

通过浏览来自不同插件的一些源代码,我能够添加一个菜单项并在插入符号下获取内容。

比如说,如果我的插入符在第二个组件中的“x:y”下,我可以对 x 和 y 进行修饰,这样至少我可以知道要查找的组件类型和组件名称。

但我想在扩展下的内容下划线,即“x:y”,当我按下 ctrl 并搜索组件时,当 ctrl+click 时跳转到组件的声明,就像我们跳转到类的声明一样。

我需要指导,比如我应该看哪个类,我应该怎么去或类似的实现。

谢谢

最佳答案

我想你要找的是 reference contributor .

参见 this answer有关如何设置贡献者的更多详细信息。创建此贡献者后,我认为您将有两种方法来查找 x:y 引用的 XML 元素:

  • 解析每个潜在的 XML 文件并尝试找到具有正确属性的标签,然后返回相应的 PsiElement
  • 创建一个 index每个 component 标签,并在此索引中查找 x:y(需要更多工作)

关于java - IntelliJ IDEA 插件 : Jump to declaration for custom xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20415061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com