1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 04:45:38 +02:00

Removed use of deprecated methods and other code cleanup.

Change-Id: I1c10f713568f0c7fd4d4b0a2212ee855e5b1d55e
This commit is contained in:
Sergey Prigogin 2016-10-06 15:00:54 -07:00
parent 9f7af7a493
commit d6d85f394b

View file

@ -108,6 +108,7 @@ import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ICoreRunnable;
import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -117,7 +118,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager; import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.core.runtime.jobs.IJobManager; import org.eclipse.core.runtime.jobs.IJobManager;
@ -176,14 +177,12 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
private static final QualifiedName SCANNER_INFO_PROVIDER_PROPERTY = new QualifiedName(CCorePlugin.PLUGIN_ID, "scannerInfoProvider"); //$NON-NLS-1$ private static final QualifiedName SCANNER_INFO_PROVIDER_PROPERTY = new QualifiedName(CCorePlugin.PLUGIN_ID, "scannerInfoProvider"); //$NON-NLS-1$
static class CompositeWorkspaceRunnable implements IWorkspaceRunnable { static class CompositeWorkspaceRunnable implements IWorkspaceRunnable {
private List<IWorkspaceRunnable> fRunnables = new ArrayList<IWorkspaceRunnable>(); private List<IWorkspaceRunnable> fRunnables = new ArrayList<>();
private String fName; private String fName;
private boolean fStopOnErr; private boolean fStopOnErr;
CompositeWorkspaceRunnable(String name) { CompositeWorkspaceRunnable(String name) {
if(name == null) fName = name == null ? "" : name; //$NON-NLS-1$
name = ""; //$NON-NLS-1$
fName = name;
} }
public void add(IWorkspaceRunnable runnable) { public void add(IWorkspaceRunnable runnable) {
@ -193,20 +192,14 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
@Override @Override
public void run(IProgressMonitor monitor) throws CoreException { public void run(IProgressMonitor monitor) throws CoreException {
try { try {
monitor.beginTask(fName, fRunnables.size()); SubMonitor progress = SubMonitor.convert(monitor, fName, fRunnables.size());
for (IWorkspaceRunnable r : fRunnables) { for (IWorkspaceRunnable r : fRunnables) {
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
try { try {
r.run(subMonitor); r.run(progress.split(1));
} catch (CoreException e){ } catch (CoreException | RuntimeException e) {
if (fStopOnErr) if (fStopOnErr)
throw e; throw e;
} catch (RuntimeException e) {
if(fStopOnErr)
throw e;
} finally {
subMonitor.done();
} }
} }
} finally { } finally {
@ -247,7 +240,6 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
private boolean fAllowEmptyCreatingDescription = true; // allowed by default private boolean fAllowEmptyCreatingDescription = true; // allowed by default
private ICDataProxyContainer fPrefUpdater = new ICDataProxyContainer() { private ICDataProxyContainer fPrefUpdater = new ICDataProxyContainer() {
@Override @Override
public void updateChild(CDataProxy child, boolean write) { public void updateChild(CDataProxy child, boolean write) {
if (write) { if (write) {
@ -271,13 +263,14 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
private CProjectDescriptionManager() {} private CProjectDescriptionManager() {}
public static CProjectDescriptionManager getInstance() { public static CProjectDescriptionManager getInstance() {
if(fInstance == null) if (fInstance == null) {
synchronized (CProjectDescriptionManager.class) { synchronized (CProjectDescriptionManager.class) {
if (fInstance == null) { if (fInstance == null) {
fInstance = new CProjectDescriptionManager(); fInstance = new CProjectDescriptionManager();
fInstance.initProviderInfo(); fInstance.initProviderInfo();
} }
} }
}
return fInstance; return fInstance;
} }
@ -355,12 +348,7 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
CCorePlugin.log(e); CCorePlugin.log(e);
return e.getStatus(); return e.getStatus();
} }
return new Status( return Status.OK_STATUS;
IStatus.OK,
CCorePlugin.PLUGIN_ID,
IStatus.OK,
"", //$NON-NLS-1$
null);
} }
}; };
@ -450,7 +438,7 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
* @param monitor * @param monitor
* @return scheduled job or null if the operation was run immediately * @return scheduled job or null if the operation was run immediately
*/ */
public static Job runWspModification(final IWorkspaceRunnable runnable, IProgressMonitor monitor) { public static Job runWspModification(final ICoreRunnable runnable, IProgressMonitor monitor) {
return runWspModification(runnable, ResourcesPlugin.getWorkspace().getRoot(), monitor); return runWspModification(runnable, ResourcesPlugin.getWorkspace().getRoot(), monitor);
} }
@ -461,10 +449,7 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
* @param monitor * @param monitor
* @return scheduled job or null if the operation was run immediately * @return scheduled job or null if the operation was run immediately
*/ */
public static Job runWspModification(final IWorkspaceRunnable runnable, final ISchedulingRule rule, IProgressMonitor monitor){ public static Job runWspModification(final ICoreRunnable runnable, final ISchedulingRule rule, IProgressMonitor monitor) {
if(monitor == null)
monitor = new NullProgressMonitor();
// Should the rule be scheduled, or run immediately // Should the rule be scheduled, or run immediately
boolean scheduleRule = ResourcesPlugin.getWorkspace().isTreeLocked(); boolean scheduleRule = ResourcesPlugin.getWorkspace().isTreeLocked();
@ -485,8 +470,6 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
} catch (Exception e) { } catch (Exception e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} finally { } finally {
if(!scheduleRule)
monitor.done();
mngr.endRule(rule); mngr.endRule(rule);
} }
} else { } else {
@ -499,8 +482,6 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
return e.getStatus(); return e.getStatus();
} finally {
monitor.done();
} }
return Status.OK_STATUS; return Status.OK_STATUS;
} }
@ -514,9 +495,9 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
return null; return null;
} }
private static void runAtomic(final IWorkspaceRunnable r, ISchedulingRule rule, IProgressMonitor monitor) throws CoreException{ private static void runAtomic(final ICoreRunnable r, ISchedulingRule rule, IProgressMonitor monitor) throws CoreException{
IWorkspace wsp = ResourcesPlugin.getWorkspace(); IWorkspace wsp = ResourcesPlugin.getWorkspace();
wsp.run(new IWorkspaceRunnable(){ wsp.run(new ICoreRunnable() {
@Override @Override
public void run(IProgressMonitor monitor) throws CoreException { public void run(IProgressMonitor monitor) throws CoreException {
try { try {
@ -531,10 +512,6 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
@Override @Override
public void updateProjectDescriptions(IProject[] projects, IProgressMonitor monitor) throws CoreException{ public void updateProjectDescriptions(IProject[] projects, IProgressMonitor monitor) throws CoreException{
if(monitor == null)
monitor = new NullProgressMonitor();
try {
IWorkspace wsp = ResourcesPlugin.getWorkspace(); IWorkspace wsp = ResourcesPlugin.getWorkspace();
if (projects == null) if (projects == null)
projects = wsp.getRoot().getProjects(); projects = wsp.getRoot().getProjects();
@ -551,41 +528,31 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
} }
if (num != 0) { if (num != 0) {
final int[] fi = new int[1]; final int finalNum = num;
fi[0] = num; runWspModification(new ICoreRunnable() {
runWspModification(new IWorkspaceRunnable(){
@Override @Override
public void run(IProgressMonitor monitor) throws CoreException { public void run(IProgressMonitor monitor) throws CoreException {
monitor.beginTask(SettingsModelMessages.getString("CProjectDescriptionManager.13"), fi[0]); //$NON-NLS-1$ SubMonitor subMonitor = SubMonitor.convert(monitor,
SettingsModelMessages.getString("CProjectDescriptionManager.13"), finalNum); //$NON-NLS-1$
for (int i = 0; i < fi[0]; i++) { for (int i = 0; i < finalNum; i++) {
ICProjectDescription des = dessWritable[i]; ICProjectDescription des = dessWritable[i];
ICProjectDescription desCache = dessCache[i]; ICProjectDescription desCache = dessCache[i];
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
try { try {
// Only apply the project description if it is still current, otherwise: // Only apply the project description if it is still current, otherwise:
// - someone else must already have called setProjectDescription, so there is // - someone else must already have called setProjectDescription, so there is
// nothing to do // nothing to do
// - we might overwrite someone else's changes with our older description // - we might overwrite someone else's changes with our older description
if (desCache == getProjectDescription(des.getProject(), false, if (desCache == getProjectDescription(des.getProject(), false, false)) {
false)) { setProjectDescription(des.getProject(), des, true, subMonitor.split(1));
setProjectDescription(des.getProject(), des, true, subMonitor);
} }
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} finally {
subMonitor.done();
} }
} }
} }
}, monitor); }, monitor);
} }
} finally {
monitor.done();
}
} }
public ICProjectConverter getConverter(IProject project, String oldOwnerId, ICProjectDescription des) { public ICProjectConverter getConverter(IProject project, String oldOwnerId, ICProjectDescription des) {
@ -1071,11 +1038,11 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
if (rootElement != null) { if (rootElement != null) {
ICStorageElement children[] = rootElement.getChildren(); ICStorageElement children[] = rootElement.getChildren();
for (ICStorageElement el : children) { for (ICStorageElement elem : children) {
if(CONFIGURATION.equals(el.getName())){ if (CONFIGURATION.equals(elem.getName())) {
String id = el.getAttribute(CConfigurationSpecSettings.ID); String id = elem.getAttribute(CConfigurationSpecSettings.ID);
if (id != null) if (id != null)
map.put(id, el); map.put(id, elem);
} }
} }
} }
@ -1094,10 +1061,10 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
ICStorageElement children[] = rootElement.getChildren(); ICStorageElement children[] = rootElement.getChildren();
ICStorageElement element = null; ICStorageElement element = null;
for (ICStorageElement el : children) { for (ICStorageElement elem : children) {
if(CONFIGURATION.equals(el.getName()) if (CONFIGURATION.equals(elem.getName())
&& cfgId.equals(el.getAttribute(CConfigurationSpecSettings.ID))){ && cfgId.equals(elem.getAttribute(CConfigurationSpecSettings.ID))) {
element = el; element = elem;
break; break;
} }
} }
@ -1146,10 +1113,10 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
if (rootElement != null) { if (rootElement != null) {
ICStorageElement children[] = rootElement.getChildren(); ICStorageElement children[] = rootElement.getChildren();
for (ICStorageElement el: children) { for (ICStorageElement elem: children) {
if(CONFIGURATION.equals(el.getName()) if (CONFIGURATION.equals(elem.getName())
&& cfgId.equals(el.getAttribute(CConfigurationSpecSettings.ID))){ && cfgId.equals(elem.getAttribute(CConfigurationSpecSettings.ID))) {
rootElement.removeChild(el); rootElement.removeChild(elem);
break; break;
} }
} }
@ -2068,17 +2035,17 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
} }
path = path.makeRelative(); path = path.makeRelative();
ICElement el = null; ICElement elem = null;
try { try {
el = cProject.findElement(path); elem = cProject.findElement(path);
} catch (CModelException e) { } catch (CModelException e) {
return; return;
} }
IResource rc = el.getResource(); IResource rc = elem.getResource();
if (rc != null) { if (rc != null) {
CElementDelta ceRcDelta = new CElementDelta(el.getCModel()); CElementDelta ceRcDelta = new CElementDelta(elem.getCModel());
ceRcDelta.changed(el, ICElementDelta.F_MODIFIERS); ceRcDelta.changed(elem, ICElementDelta.F_MODIFIERS);
list.add(ceRcDelta); list.add(ceRcDelta);
if (rc.getType() == IResource.FILE) { if (rc.getType() == IResource.FILE) {
@ -2086,7 +2053,7 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
ICLanguageSetting newLS = getLanguageSetting(newRcDes, fileName); ICLanguageSetting newLS = getLanguageSetting(newRcDes, fileName);
ICLanguageSetting oldLS = getLanguageSetting(oldRcDes, fileName); ICLanguageSetting oldLS = getLanguageSetting(oldRcDes, fileName);
ICDescriptionDelta ld = createDelta(newLS, oldLS); ICDescriptionDelta ld = createDelta(newLS, oldLS);
generateCElementDeltasFromLanguageDelta(el, ld, list); generateCElementDeltasFromLanguageDelta(elem, ld, list);
} else { } else {
if (newRcDes.getType() != ICSettingBase.SETTING_FOLDER) { if (newRcDes.getType() != ICSettingBase.SETTING_FOLDER) {
CCorePlugin.log(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, SettingsModelMessages.getString("CProjectDescriptionManager.wrongTypeOfResourceDescription")+newRcDes)); //$NON-NLS-1$ CCorePlugin.log(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, SettingsModelMessages.getString("CProjectDescriptionManager.wrongTypeOfResourceDescription")+newRcDes)); //$NON-NLS-1$
@ -2104,7 +2071,7 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
if (folderDelta != null) { if (folderDelta != null) {
for (ICDescriptionDelta child : folderDelta.getChildren()) { for (ICDescriptionDelta child : folderDelta.getChildren()) {
if (child.getSettingType() == ICSettingBase.SETTING_LANGUAGE) { if (child.getSettingType() == ICSettingBase.SETTING_LANGUAGE) {
generateCElementDeltasFromLanguageDelta(el, child, list); generateCElementDeltasFromLanguageDelta(elem, child, list);
} }
} }
} }
@ -2120,7 +2087,7 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
return ((ICFolderDescription) rcDes).getLanguageSettingForFile(fileName); return ((ICFolderDescription) rcDes).getLanguageSettingForFile(fileName);
} }
private List<CElementDelta> generateCElementDeltasFromLanguageDelta(ICElement el, ICDescriptionDelta delta, List<CElementDelta> list){ private List<CElementDelta> generateCElementDeltasFromLanguageDelta(ICElement elem, ICDescriptionDelta delta, List<CElementDelta> list) {
if (delta == null) if (delta == null)
return list; return list;
@ -2129,8 +2096,8 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
flags |= calculateEntriesFlags(delta.getRemovedEntriesKinds(), false); flags |= calculateEntriesFlags(delta.getRemovedEntriesKinds(), false);
flags |= calculateEntriesFlags(delta.getReorderedEntriesKinds(), true); flags |= calculateEntriesFlags(delta.getReorderedEntriesKinds(), true);
if (flags != 0) { if (flags != 0) {
CElementDelta cElDelta = new CElementDelta(el.getCModel()); CElementDelta cElDelta = new CElementDelta(elem.getCModel());
cElDelta.changed(el, flags); cElDelta.changed(elem, flags);
list.add(cElDelta); list.add(cElDelta);
} }
return list; return list;
@ -2239,8 +2206,6 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
IWorkspaceRunnable toRun = context.createOperationRunnable(); IWorkspaceRunnable toRun = context.createOperationRunnable();
if (toRun != null) { if (toRun != null) {
runWspModification(toRun, monitor); runWspModification(toRun, monitor);
} else if (monitor != null){
monitor.done();
} }
} }
@ -2287,15 +2252,15 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
} }
private void savePreferenceConfiguration(String buildStystemId, CConfigurationDescriptionCache cache) throws CoreException{ private void savePreferenceConfiguration(String buildStystemId, CConfigurationDescriptionCache cache) throws CoreException{
ICStorageElement el = cache.getSpecSettings().getRootStorageElement(); ICStorageElement elem = cache.getSpecSettings().getRootStorageElement();
saveBuildSystemConfigPreferenceStorage(buildStystemId, el); saveBuildSystemConfigPreferenceStorage(buildStystemId, elem);
} }
private void saveBuildSystemConfigPreferenceStorage(String buildSystemId, ICStorageElement el) throws CoreException{ private void saveBuildSystemConfigPreferenceStorage(String buildSystemId, ICStorageElement elem) throws CoreException{
ICStorageElement cur = getBuildSystemConfigPreferenceStorage(buildSystemId); ICStorageElement cur = getBuildSystemConfigPreferenceStorage(buildSystemId);
ICStorageElement parent = cur.getParent(); ICStorageElement parent = cur.getParent();
parent.removeChild(cur); parent.removeChild(cur);
parent.importChild(el); parent.importChild(elem);
savePreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, parent); savePreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, parent);
} }
@ -2344,9 +2309,9 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
} }
// private XmlStorage createBuildSystemCfgPrefStore() throws CoreException{ // private XmlStorage createBuildSystemCfgPrefStore() throws CoreException{
// ICStorageElement el = getPreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, true, false); // ICStorageElement elem = getPreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, true, false);
// //
// XmlStorage store = new XmlStorage((InternalXmlStorageElement)el); // XmlStorage store = new XmlStorage((InternalXmlStorageElement) elem);
// //
// return store; // return store;
// } // }
@ -2364,11 +2329,11 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
} }
private ICStorageElement getBuildSystemConfigPreferenceStorage(String buildSystemId, boolean createIfNotDound, boolean readOnly) throws CoreException{ private ICStorageElement getBuildSystemConfigPreferenceStorage(String buildSystemId, boolean createIfNotDound, boolean readOnly) throws CoreException{
ICStorageElement el = getPreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, createIfNotDound, readOnly); ICStorageElement elem = getPreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, createIfNotDound, readOnly);
ICStorageElement cfgEl = null; ICStorageElement cfgEl = null;
if(el != null){ if (elem != null) {
ICStorageElement children[] = el.getChildren(); ICStorageElement children[] = elem.getChildren();
for (ICStorageElement child : children) { for (ICStorageElement child : children) {
if (PREFERENCE_BUILD_SYSTEM_ELEMENT.equals(child.getName())) { if (PREFERENCE_BUILD_SYSTEM_ELEMENT.equals(child.getName())) {
if (buildSystemId.equals(child.getAttribute(ID))) { if (buildSystemId.equals(child.getAttribute(ID))) {
@ -2380,7 +2345,7 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
} }
if (cfgEl == null) { if (cfgEl == null) {
cfgEl = el.createChild(PREFERENCE_BUILD_SYSTEM_ELEMENT); cfgEl = elem.createChild(PREFERENCE_BUILD_SYSTEM_ELEMENT);
cfgEl.setAttribute(ID, buildSystemId); cfgEl.setAttribute(ID, buildSystemId);
} }
@ -2390,9 +2355,9 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
} }
private ICConfigurationDescription loadPreference(String buildSystemId) throws CoreException{ private ICConfigurationDescription loadPreference(String buildSystemId) throws CoreException{
ICStorageElement el = getPreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, false, false); ICStorageElement elem = getPreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, false, false);
ICStorageElement children[] = el.getChildren(); ICStorageElement children[] = elem.getChildren();
ICStorageElement cfgEl = null; ICStorageElement cfgEl = null;
for (ICStorageElement child : children) { for (ICStorageElement child : children) {
if (PREFERENCE_BUILD_SYSTEM_ELEMENT.equals(child.getName())) { if (PREFERENCE_BUILD_SYSTEM_ELEMENT.equals(child.getName())) {
@ -2416,16 +2381,16 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
} }
private XmlStorage getPreferenceStore(String prefKey, boolean createIfNotDound, boolean readOnly) throws CoreException{ private XmlStorage getPreferenceStore(String prefKey, boolean createIfNotDound, boolean readOnly) throws CoreException{
ICStorageElement el = createPreferenceStorage(prefKey, createIfNotDound, readOnly); ICStorageElement elem = createPreferenceStorage(prefKey, createIfNotDound, readOnly);
XmlStorage store = new XmlStorage((InternalXmlStorageElement)el); XmlStorage store = new XmlStorage((InternalXmlStorageElement) elem);
return store; return store;
} }
public void savePreferenceStorage(String prefKey, String storageId, ICStorageElement el) throws CoreException{ public void savePreferenceStorage(String prefKey, String storageId, ICStorageElement elem) throws CoreException{
XmlStorage store = getPreferenceStore(prefKey, true, false); XmlStorage store = getPreferenceStore(prefKey, true, false);
store.importStorage(storageId, el); store.importStorage(storageId, elem);
InternalXmlStorageElement rootEl = new InternalXmlStorageElement(store.fElement, store.isReadOnly()); InternalXmlStorageElement rootEl = new InternalXmlStorageElement(store.fElement, store.isReadOnly());
serializePreference(prefKey, rootEl); serializePreference(prefKey, rootEl);
@ -2549,7 +2514,7 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
} }
static private HashMap<HashSet<String>, CLanguageData> createExtSetToLDataMap(IProject project, CLanguageData[] lDatas) { static private HashMap<HashSet<String>, CLanguageData> createExtSetToLDataMap(IProject project, CLanguageData[] lDatas) {
HashMap<HashSet<String>, CLanguageData> map = new HashMap<HashSet<String>, CLanguageData>(); HashMap<HashSet<String>, CLanguageData> map = new HashMap<>();
for (CLanguageData lData : lDatas) { for (CLanguageData lData : lDatas) {
String[] exts = CDataUtil.getSourceExtensions(project, lData); String[] exts = CDataUtil.getSourceExtensions(project, lData);
@ -2702,28 +2667,21 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
@Override @Override
public boolean setProjectDescriptionWorkspacePreferences(ICProjectDescriptionWorkspacePreferences prefs, public boolean setProjectDescriptionWorkspacePreferences(ICProjectDescriptionWorkspacePreferences prefs,
boolean updateProjects, boolean updateProjects, IProgressMonitor monitor) {
IProgressMonitor monitor) {
if(monitor == null)
monitor = new NullProgressMonitor();
boolean changed = false; boolean changed = false;
ICProjectDescriptionWorkspacePreferences oldPrefs = getProjectDescriptionWorkspacePreferences(false); ICProjectDescriptionWorkspacePreferences oldPrefs = getProjectDescriptionWorkspacePreferences(false);
try { try {
do { if (oldPrefs != prefs && prefs.getConfigurationRelations() != oldPrefs.getConfigurationRelations()) {
if(oldPrefs != prefs){
if(prefs.getConfigurationRelations() != oldPrefs.getConfigurationRelations()){
changed = true; changed = true;
break;
} }
}
} while(false);
if (changed) { if (changed) {
CProjectDescriptionWorkspacePreferences basePrefs; CProjectDescriptionWorkspacePreferences basePrefs;
if(prefs instanceof CProjectDescriptionWorkspacePreferences) if (prefs instanceof CProjectDescriptionWorkspacePreferences) {
basePrefs = (CProjectDescriptionWorkspacePreferences) prefs; basePrefs = (CProjectDescriptionWorkspacePreferences) prefs;
else } else {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
}
fPreferences = new CProjectDescriptionWorkspacePreferences(basePrefs, null, true); fPreferences = new CProjectDescriptionWorkspacePreferences(basePrefs, null, true);
@ -2734,41 +2692,39 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
} }
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} finally {
monitor.done();
} }
return changed; return changed;
} }
private void storePreferences(CProjectDescriptionWorkspacePreferences prefs) throws CoreException { private void storePreferences(CProjectDescriptionWorkspacePreferences prefs) throws CoreException {
ICStorageElement el = getCProjectDescriptionPreferencesElement(true, false); ICStorageElement elem = getCProjectDescriptionPreferencesElement(true, false);
prefs.serialize(el); prefs.serialize(elem);
saveCProjectDescriptionPreferencesElement(el); saveCProjectDescriptionPreferencesElement(elem);
} }
private void saveCProjectDescriptionPreferencesElement(ICStorageElement el) throws CoreException{ private void saveCProjectDescriptionPreferencesElement(ICStorageElement elem) throws CoreException{
ICStorageElement cur = getCProjectDescriptionPreferencesElement(true, false); ICStorageElement cur = getCProjectDescriptionPreferencesElement(true, false);
ICStorageElement parent = cur.getParent(); ICStorageElement parent = cur.getParent();
parent.removeChild(cur); parent.removeChild(cur);
parent.importChild(el); parent.importChild(elem);
savePreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, parent); savePreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, parent);
} }
private CProjectDescriptionWorkspacePreferences loadPreferences() throws CoreException{ private CProjectDescriptionWorkspacePreferences loadPreferences() throws CoreException{
ICStorageElement el = getCProjectDescriptionPreferencesElement(false, true); ICStorageElement elem = getCProjectDescriptionPreferencesElement(false, true);
return new CProjectDescriptionWorkspacePreferences(el, null, true); return new CProjectDescriptionWorkspacePreferences(elem, null, true);
} }
private ICStorageElement getCProjectDescriptionPreferencesElement(boolean createIfNotFound, boolean readOnly) throws CoreException{ private ICStorageElement getCProjectDescriptionPreferencesElement(boolean createIfNotFound, boolean readOnly) throws CoreException{
ICStorageElement el = getPreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, createIfNotFound, readOnly); ICStorageElement elem = getPreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, createIfNotFound, readOnly);
ICStorageElement[] children = el.getChildren(); ICStorageElement[] children = elem.getChildren();
for (ICStorageElement child : children) { for (ICStorageElement child : children) {
if (PREFERENCES_ELEMENT.equals(child.getName())) if (PREFERENCES_ELEMENT.equals(child.getName()))
return child; return child;
} }
if (createIfNotFound) if (createIfNotFound)
return el.createChild(PREFERENCES_ELEMENT); return elem.createChild(PREFERENCES_ELEMENT);
throw ExceptionFactory.createCoreException(SettingsModelMessages.getString("CProjectDescriptionManager.14")); //$NON-NLS-1$ throw ExceptionFactory.createCoreException(SettingsModelMessages.getString("CProjectDescriptionManager.14")); //$NON-NLS-1$
} }
@ -2784,5 +2740,4 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
void setEmptyCreatingDescriptionAllowed(boolean allow) { void setEmptyCreatingDescriptionAllowed(boolean allow) {
fAllowEmptyCreatingDescription = allow; fAllowEmptyCreatingDescription = allow;
} }
} }