简体   繁体   English

将'plugin.xml'中的类字段用于eclipse插件

[英]Use a class field in the 'plugin.xml' for an eclipse plugin

I am currently working on a little eclipse plugin and i have to deal with the classic 'plugin.xml' stuff, such as the creation of a nature: 我目前正在开发一个小eclipse插件,我必须处理经典的“ plugin.xml”内容,例如创建自然对象:

<extension
    id="aplugin.natures.MyNature.NATURE_ID.id"
    name="Sample Project Nature"
    point="org.eclipse.core.resources.natures">

Now in this particular example, i must, somewhere in my plugin code, give this 'id' as a String to some eclipse function. 现在在这个特定示例中,我必须在插件代码中的某个地方,将此“ id”作为字符串提供给某些eclipse函数。 So i need to create a specific class like: 所以我需要创建一个特定的类,如:

package aplugin.natures;

public class MyNature implements IProjectNature {
    public static final String NATURE_ID = "aplugin.natures.MyNature.NATURE_ID.id"; //$NON-NLS-1$
}

And here comes my problem, i got some copy and paste of my 'id' . 这是我的问题,我得到了一些复制和粘贴我的'id' I must admit that i am not very proud of it. 我必须承认,我对此并不感到骄傲。


So my question is, do someone know a way to use the 'NATURE_ID' field in the 'MyNature' class directly in the 'plugin.xml' file ?. 所以我的问题是,有人知道直接在“ plugin.xml”文件中使用“ MyNature”类中的“ NATURE_ID”字段的方法吗?

In the end i wish to write something like: 最后,我希望写一些类似的东西:

<extension id="${aplugin.natures.MyNature.NATURE_ID}" ... >

That is not possible by design. 设计上不可能做到这一点。

The idea is that the Eclipse core can load the plugin.xml files for all resolved plug-ins/bundles without loading/activating the plug-ins. 这个想法是Eclipse核心可以为所有已解析的插件/捆绑包加载plugin.xml文件,而无需加载/激活插件。 Resolving your construct above would normally require Eclipse to resolve all references for the class - MyNature in this case - which can easily lead to the activation of many other dependent plug-ins. 解决上面的构造通常需要Eclipse解析该类的所有引用-在这种情况下为MyNature这很容易导致激活许多其他从属插件。 Not good. 不好。

So - by design - all data in plugin.xml must be self-contained. 因此,根据设计, plugin.xml所有数据必须是独立的。 (With the possible exception of localized strings). (本地化字符串可能有例外)。

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

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