我正在开发一个Eclipse插件,其中包括其他必须检查当前C项目中设置的编译器选项。 基本上,我想访问属性 - > C/C++编译 - >设置 - > GCC C编译器 - >所有选项字段。Eclipse CDT从代码
我已经搜索了如何访问它,但我还没有找到办法做到这一点。 我试图通过喜好来存取权限它像下面的代码:
IEclipsePreferences root = Platform.getPreferencesService().getRootNode();
我可以使用插件的喜好这种方式,但不与C项目。
有没有人知道一种方法来做到这一点?我不需要更改编译器选项,只需知道设置了哪些标志。
更新:我找到了解决方案。
IResourceInfo info = getResourceInfo(translationUnit, description);
ITool tools[] = info.getTools();
for (ITool t : tools) {
if (t.getName().compareToIgnoreCase("GCC C Compiler") == 0) {
try {
//Finally the field I was looking for
String commandLine = t.getToolCommandFlagsString(getProject().getFullPath(), null);
} catch (BuildException e) {
e.printStackTrace();
}
}
}
我然后可以解析字符串,不理想,但它的工作原理。 我得到了这个职位的getResourceInfo()函数:How do I programmatically change the Eclipse CDT tool settings for a file?
所以,感谢justinmreina的答案!
大声笑,这正是10行代码... –