2017-02-14 90 views
2

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

  • 以编程方式向目标项目(工程)添加Xtend依赖项。
  • 以编程方式使用IProject.getFolder(),IFolder.getFile()IFile.create()(JDT API)在项目中创建一些Xtend类。
  • Resfreshing与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编译?

回答

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); 
    } 
} 
相关问题