How do I programmatically change the Eclipse CDT tool settings for a file?

前端 未结 2 559
醉酒成梦
醉酒成梦 2021-02-06 10:23

I want to programmatically (from a plugin) change the \"Other flags\" field in the Miscellaneous settings in the Tool Settings tab for an individual file in a CDT managed build

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-06 11:09

    I suspect there might be problem in you IFileInfo creation. Here's the code that we use to obtain IResourceInfo for a translation unit to set per-file options:

    protected IResourceInfo getResourceInfo(ITranslationUnit translationUnit, ICProjectDescription prjDescription) {
    
        ICProject cProject = translationUnit.getCProject();
        if (cProject != null) {
            ICConfigurationDescription cfgDescription = prjDescription.getActiveConfiguration();
            IConfiguration configuration = ManagedBuildManager.getConfigurationForDescription(cfgDescription);
            IPath projectPath = translationUnit.getResource().getProjectRelativePath(); 
            IResourceInfo ri = configuration.getResourceInfo(projectPath, true);
    
            if (ri == null) { 
                ri = configuration.createFileInfo(projectPath);
            }
    
            return ri;
        }
    
        return null;
    }
    

    Note this line, in particular:

    IPath projectPath = translationUnit.getResource().getProjectRelativePath();
    

    Maybe, all you need is to use getProjectRelativePath() in your code?

提交回复
热议问题