【问题标题】:Eclipse - CDT programmatically added include paths does not appearEclipse - CDT 以编程方式添加的包含路径不出现
【发布时间】:2012-10-02 22:18:14
【问题描述】:

我正在开发一个 eclipse-java 插件以编程方式将包含路径添加到项目中。 我使用的部分代码如下。

String includePath = null;
ICProjectDescription projectDescription = CoreModel.getDefault().getProjectDescription(project, true);
ICConfigurationDescription configDecriptions[] = projectDescription.getConfigurations();
for (ICConfigurationDescription configDescription : configDecriptions) {
ICFolderDescription projectRoot = configDescription.getRootFolderDescription();
ICLanguageSetting[] settings = projectRoot.getLanguageSettings();
for (ICLanguageSetting setting : settings) {
    if (!"org.eclipse.cdt.core.gcc".equals(setting.getLanguageId())) {
    continue;
    }
    List<ICLanguageSettingEntry> includes = new ArrayList<ICLanguageSettingEntry>();
        includes.addAll(setting.getSettingEntriesList(ICSettingEntry.INCLUDE_PATH));
    for (int i = 0; i < tableViewer.getTable().getItemCount(); i++) {
        includePath = tableViewer.getTable().getItem(i).getText();
        includes.add(new CIncludePathEntry(includePath, ICSettingEntry.LOCAL));
    }
    setting.setSettingEntries(ICSettingEntry.INCLUDE_PATH, includes);
    }
}
CoreModel.getDefault().setProjectDescription(project, projectDescription);

当我打印从 ICLanguageSetting.getSettingEntries() 返回的值时,包含路径已成功添加。 但它们不会反映在 properties->C/C++General->Paths&Symbols 对话框或 Project Explorer 视图中。

我错过了任何 update() 或 refresh() 吗?

【问题讨论】:

    标签: eclipse include eclipse-cdt


    【解决方案1】:

    我知道这已经 3 个月了,所以希望它仍然有意义。

    我的代码看起来几乎与您的相同,但包含路径显示在 properties->C/C++General->Paths&Symbols 和工作。所以我浏览了每一行,我只能看到一个很大的不同:

    为了构造一个新的CIncludePathEntry,我传入的第一个参数是IFolder,而不是String,所以我使用了不同的构造函数。我不确定您的程序的其余部分是如何构建的,但也许您可以致电 IProject.getFolder(String) 并使用它来代替。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-05
      • 1970-01-01
      • 2021-12-04
      • 1970-01-01
      • 2013-04-21
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多