我目前正在尝试编译以编程方式生成的Xtend类。这是Eclipse插件的所有部分。这就是我的工作:
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编译?
答案 0 :(得分: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);
}
}