Search in sources :

Example 1 with ICFolderDescription

use of org.eclipse.cdt.core.settings.model.ICFolderDescription in project arduino-eclipse-plugin by Sloeber.

the class Helpers method addIncludeFolder.

/**
 * This method is the internal working class that adds the provided include path
 * to all configurations and languages.
 *
 * @param configurationDescription
 *            The configuration description of the project to add it to
 * @param IncludePath
 *            The path to add to the include folders
 * @see addLibraryDependency {@link #addLibraryDependency(IProject, IProject)}
 */
private static void addIncludeFolder(ICConfigurationDescription configurationDescription, IPath IncludePath) {
    // find all languages
    ICFolderDescription folderDescription = configurationDescription.getRootFolderDescription();
    ICLanguageSetting[] languageSettings = folderDescription.getLanguageSettings();
    // Add include path to all languages
    for (int idx = 0; idx < languageSettings.length; idx++) {
        ICLanguageSetting lang = languageSettings[idx];
        String LangID = lang.getLanguageId();
        if (LangID != null) {
            if (LangID.startsWith("org.eclipse.cdt.")) {
                ICLanguageSettingEntry[] OrgIncludeEntries = lang.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
                ICLanguageSettingEntry[] IncludeEntries = new ICLanguageSettingEntry[OrgIncludeEntries.length + 1];
                System.arraycopy(OrgIncludeEntries, 0, IncludeEntries, 0, OrgIncludeEntries.length);
                IncludeEntries[OrgIncludeEntries.length] = new CIncludePathEntry(IncludePath, // (location.toString());
                ICSettingEntry.VALUE_WORKSPACE_PATH);
                lang.setSettingEntries(ICSettingEntry.INCLUDE_PATH, IncludeEntries);
            }
        }
    }
}
Also used : ICFolderDescription(org.eclipse.cdt.core.settings.model.ICFolderDescription) ICLanguageSettingEntry(org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry) CIncludePathEntry(org.eclipse.cdt.core.settings.model.CIncludePathEntry) ICLanguageSetting(org.eclipse.cdt.core.settings.model.ICLanguageSetting)

Example 2 with ICFolderDescription

use of org.eclipse.cdt.core.settings.model.ICFolderDescription in project arduino-eclipse-plugin by Sloeber.

the class Helpers method removeInvalidIncludeFolders.

/**
 * Removes include folders that are not valid. This method does not save the
 * configurationDescription description
 *
 * @param configurationDescription
 *            the configuration that is checked
 * @return true is a include path has been removed. False if the include path
 *         remains unchanged.
 */
public static boolean removeInvalidIncludeFolders(ICConfigurationDescription configurationDescription) {
    // find all languages
    ICFolderDescription folderDescription = configurationDescription.getRootFolderDescription();
    ICLanguageSetting[] languageSettings = folderDescription.getLanguageSettings();
    boolean hasChange = false;
    // Add include path to all languages
    for (int idx = 0; idx < languageSettings.length; idx++) {
        ICLanguageSetting lang = languageSettings[idx];
        String LangID = lang.getLanguageId();
        if (LangID != null) {
            if (LangID.startsWith("org.eclipse.cdt.")) {
                ICLanguageSettingEntry[] OrgIncludeEntries = lang.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
                ICLanguageSettingEntry[] OrgIncludeEntriesFull = lang.getResolvedSettingEntries(ICSettingEntry.INCLUDE_PATH);
                int copiedEntry = 0;
                for (int curEntry = 0; curEntry < OrgIncludeEntries.length; curEntry++) {
                    IPath cusPath = ((CIncludePathEntry) OrgIncludeEntriesFull[curEntry]).getFullPath();
                    if ((ResourcesPlugin.getWorkspace().getRoot().exists(cusPath)) || (((CIncludePathEntry) OrgIncludeEntries[curEntry]).isBuiltIn())) {
                        OrgIncludeEntries[copiedEntry++] = OrgIncludeEntries[curEntry];
                    } else {
                        Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, "Removed invalid include path" + cusPath, null));
                    }
                }
                if (// do not save
                copiedEntry != OrgIncludeEntries.length) // if nothing
                // has changed
                {
                    ICLanguageSettingEntry[] IncludeEntries = new ICLanguageSettingEntry[copiedEntry];
                    System.arraycopy(OrgIncludeEntries, 0, IncludeEntries, 0, copiedEntry);
                    lang.setSettingEntries(ICSettingEntry.INCLUDE_PATH, IncludeEntries);
                    hasChange = true;
                }
            }
        }
    }
    return hasChange;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ICFolderDescription(org.eclipse.cdt.core.settings.model.ICFolderDescription) ICLanguageSettingEntry(org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry) IPath(org.eclipse.core.runtime.IPath) CIncludePathEntry(org.eclipse.cdt.core.settings.model.CIncludePathEntry) ICLanguageSetting(org.eclipse.cdt.core.settings.model.ICLanguageSetting)

Aggregations

CIncludePathEntry (org.eclipse.cdt.core.settings.model.CIncludePathEntry)2 ICFolderDescription (org.eclipse.cdt.core.settings.model.ICFolderDescription)2 ICLanguageSetting (org.eclipse.cdt.core.settings.model.ICLanguageSetting)2 ICLanguageSettingEntry (org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry)2 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1