【问题标题】:Programmatically compiling Xtend classes is not working以编程方式编译 Xtend 类不起作用
【发布时间】:2017-08-06 19:02:53
【问题描述】:

我目前正在尝试编译以编程方式生成的 Xtend 类。这都是 Eclipse 插件的一部分。我就是这样做的:

  • 以编程方式将 Xtend 依赖项添加到目标项目(有效)。
  • 使用IProject.getFolder()IFolder.getFile()IFile.create() (JDT API) 以编程方式在项目中创建一些 Xtend 类。
  • IProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());刷新整个项目
  • IProject.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());编译项目

现在,我可以在 Eclipse IDE 中看到生成的类。问题是,xtend-gen 文件夹中没有为 Xtend 类生成的 Java 类。

当我现在在 Eclipse IDE 中手动打开生成的 Xtend 类之一时,它将触发编译。现在我可以看到为 Xtend 类生成的 Java 类了。

但我需要以编程方式执行此操作。无需手动打开一个 Xtend 类。我怎样才能做到这一点?这里有什么问题?为什么我没有触发 Xtend 编译?

【问题讨论】:

    标签: java eclipse eclipse-plugin eclipse-jdt xtend


    【解决方案1】:

    好像我没有正确更新项目描述。未设置 Xtext 构建器。

    这就是我现在的做法:

    private static void updateProjectDescription(IProject project) {
        String builderName = "org.eclipse.xtext.ui.shared.xtextBuilder";
        String xtextNature = "org.eclipse.xtext.ui.shared.xtextNature";
        IProjectDescription description = null;
        try {
            description = project.getDescription();
        } catch (CoreException exception) {
            exception.printStackTrace();
        }
        // add xtext builder:
        ICommand[] commands = description.getBuildSpec();
        ICommand command = description.newCommand();
        command.setBuilderName(builderName);
        if (Arrays.asList(commands).contains(command)) {
            logger.warn(".project already contains " + builderName);
        } else {
            ICommand[] newCommands = new ICommand[commands.length + 1];
            System.arraycopy(commands, 0, newCommands, 0, commands.length);
            newCommands[commands.length] = command;
            description.setBuildSpec(newCommands);
        }
        // Add xtext nature:
        String[] natures = description.getNatureIds();
        if (Arrays.asList(natures).contains(xtextNature)) {
            logger.warn(".project already contains " + xtextNature);
        } else {
            String[] newNatures = new String[natures.length + 1];
            System.arraycopy(natures, 0, newNatures, 0, natures.length);
            newNatures[natures.length] = xtextNature;
            description.setNatureIds(newNatures);
        }
        try {
            project.setDescription(description, new ProgressMonitorAdapter(logger));
        } catch (CoreException exception) {
            logger.fatal(exception);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-21
      • 1970-01-01
      相关资源
      最近更新 更多