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