繁体   English   中英

使Netbeans平台注释在Eclipse中工作

[英]Getting Netbeans Platform Annotations working in Eclipse

Netbeans平台最近引入了基于注释的资源文件生成,例如捆绑软件和layer.xml文件。

在Netbeans中有一个基于Maven的Netbeans Platform项目(这些注释在其中工作),可以很容易地将相同的项目导入Eclipse。

但是由于某些原因,即使正确导入了项目(或者至少似乎正确导入了<-已下载必需的库等),上述注释也不由Eclipse执行。

症状缺少在使用这些注释的类中导入的生成类。

例:

import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;

/**
 * Top component which displays something.
 */
@ConvertAsProperties(
    dtd = "-//org.something.ui//Exp//EN",
autostore = false)
@TopComponent.Description(
    preferredID = "ExpTopComponent",
//iconBase="SET/PATH/TO/ICON/HERE", 
persistenceType = TopComponent.PERSISTENCE_ALWAYS)
@TopComponent.Registration(mode = "output", openAtStartup = true)
@ActionID(category = "Window", id = "ExpTopComponent")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
@TopComponent.OpenActionRegistration(
    displayName = "#CTL_ExpAction",
preferredID = "ExpTopComponent")
@Messages({
  "CTL_ExpAction=Example",
  "CTL_ExpTopComponent=Example Window",
  "HINT_ExpTopComponent=This is a Example window"
})
public final class ExpTopComponent extends TopComponent {

  public ExpTopComponent() {
    initComponents();
    setName(Bundle.CTL_ExpTopComponent());
    setToolTipText(Bundle.HINT_ExpTopComponent());
    putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE);

  }

  private void initComponents() {
    setLayout(new java.awt.BorderLayout());

    outlineView1 = new org.openide.explorer.view.OutlineView();
    add(outlineView1, java.awt.BorderLayout.CENTER);
  }

  private org.openide.explorer.view.OutlineView outlineView1;
  @Override
  public void componentOpened() {
    // TODO add custom code on component opening
  }

  @Override
  public void componentClosed() {
    // TODO add custom code on component closing
  }

  void writeProperties(java.util.Properties p) {
    p.setProperty("version", "1.0");
    // TODO store your settings
  }

  void readProperties(java.util.Properties p) {
    String version = p.getProperty("version");
    // TODO read your settings according to their version
  }
}

如上面的示例所示,批注被广泛使用,但是Eclipse不对其进行处理,这导致以下行不可编译,因为Bundle(应自动生成)未被识别为已知类。

    setName(Bundle.CTL_ExpTopComponent());
    setToolTipText(Bundle.HINT_ExpTopComponent());

更多信息:

使用的Eclipse是Juno,并且在项目属性中启用了注释处理。

是否有人对如何在Eclipse中完成此工作有任何想法?

事实证明,您还必须指定包含netbeans批注的批注处理器的库,至少可以这样说很乏味(无论如何,eclipse中的批注处理似乎是反直观的)。

最好的方法是,每当注释被更改并且一切顺利时,就在项目上运行一个简单的Maven构建。

暂无
暂无

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

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