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

前端 未结 2 481
醉酒成梦
醉酒成梦 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:00

    Generally you can set an option to different objects, i.e. a configuration (if you want the option to apply to all files of a given type in a configuration) or a resource (if you want the option to apply only to the files in a folder or to a single file).

    setOption() has multiple prototypes; it looks like you used the one that applies to a file resource.

    In my GNU ARM Eclipse Plug-in I successfully used another version:

    setOption(IConfiguration config, IHoldsOptions holder, IOption option, String value)
    

    You can see an example in this file, line 583.

    I guess this will work in your case too.

    0 讨论(0)
  • 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?

    0 讨论(0)
提交回复
热议问题