2017-02-14 77 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); 
    } 
} 
相關問題