From d0ef57bff8e295f3d2b98337e2ca74dda03bdbdf Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 25 Jan 2010 15:47:23 +0000 Subject: [PATCH] cosmetics: generics/enhanced loops --- .../model/CConfigurationSpecSettings.java | 232 +++++++++--------- 1 file changed, 119 insertions(+), 113 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java index 7f2692f5e6b..a2e4ec0fc79 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationSpecSettings.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 Intel Corporation and others. + * Copyright (c) 2007, 2010 Intel Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.core.settings.model; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; @@ -45,7 +44,7 @@ import org.eclipse.core.runtime.QualifiedName; /** * CConfigurationSpecSettings impelements ICSettingsStorage * to provide storage for ICStorageElements related to project settings - * + * * This corresponds to the clone = (HashMap)base.fSessionPropertiesMap.clone(); + fSessionPropertiesMap = clone; + } + if(base.fEnvironment != null) fEnvironment = EnvironmentVariableManager.fUserSupplier.cloneEnvironmentWithContext(fCfg, base.fEnvironment, des.isReadOnly()); - + fOwnerId = base.fOwnerId; fOwner = base.fOwner; copyExtensionInfo(base); } - + // private void copyRefInfos(Map infosMap){ // if(infosMap == null || infosMap.size() == 0){ // fRefInfoMap = null; // return; // } -// +// // fRefInfoMap = new HashMap(infosMap.size()); // for(Iterator iter = infosMap.entrySet().iterator(); iter.hasNext();){ // Map.Entry entry = (Map.Entry)iter.next(); @@ -184,23 +186,24 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ // fRefInfoMap.put(projName, new ProjectRefInfo(info)); // } // } - + public void setCOwner(String ownerId) throws CoreException{ if(ownerId == null) ownerId = CConfigBasedDescriptorManager.NULL_OWNER_ID; - + if(ownerId.equals(fOwnerId)) return; - + fOwnerId = ownerId; - COwnerConfiguration cfg = CProjectDescriptionManager.getInstance().getDescriptorManager().getOwnerConfiguration(fOwnerId); + CProjectDescriptionManager.getInstance().getDescriptorManager(); + COwnerConfiguration cfg = CConfigBasedDescriptorManager.getOwnerConfiguration(fOwnerId); fOwner = new COwner(cfg); } - + // private void loadReferences(ICStorageElement el){ // fRefInfoMap = new HashMap(); // ICStorageElement children[] = el.getChildren(); -// +// // for(int i = 0; i < children.length; i++){ // ICStorageElement child = children[i]; // String name = child.getName(); @@ -210,11 +213,11 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ // fRefInfoMap.put(info.getProjectName(), info); // } // } -// +// // if(fRefInfoMap.size() == 0) // fRefInfoMap = null; // } - + // private Map normalizeRefs(Map ref){ // for(Iterator iter = ref.entrySet().iterator(); iter.hasNext();){ // Map.Entry entry = (Map.Entry)iter.next(); @@ -225,9 +228,9 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ // String cfg = (String)cfgObj; // if(cfg == null) // cfg = EMPTY_STRING; -// else +// else // cfg = cfg.trim(); -// +// // if(proj.length() > 0){ // entry.setValue(cfg); // } else { @@ -243,9 +246,9 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ // return null; // if(cfgId == null) // cfgId = EMPTY_STRING; -// else +// else // cfgId = cfgId.trim(); -// +// // return new String[] {projName, cfgId}; // } @@ -254,11 +257,11 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ fSettingsStorageElement = getStorage(CProjectDescriptionManager.MODULE_ID, true); return fSettingsStorageElement; } - + public ICStorageElement getStorage(String id,boolean create) throws CoreException { return getStorageBase().getStorage(id, create); } - + public void removeStorage(String id) throws CoreException { getStorageBase().removeStorage(id); } @@ -273,7 +276,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ } return fRootStorageElement; } - + void removeConfiguration() throws CoreException{ CProjectDescriptionManager.getInstance().removeStorage(fCfg.getProjectDescription(), fCfg.getId()); } @@ -285,24 +288,24 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ fStorage = CProjectDescriptionManager.getInstance().getStorageForElement(null, getRootStorageElement()); else fStorage = CProjectDescriptionManager.getInstance().getStorageForElement(fCfg.getProjectDescription().getProject(), getRootStorageElement()); - + return fStorage; } - + void doneInitialization(){ if(isReadOnly()) if(fStorage != null) fStorage.setReadOnly(true, false); } - + public String getBuildSystemId(){ return fBuildSystemId; } - + public ICConfigurationDescription getConfigurarion(){ return fCfg; } - + public String getName() { return fName; } @@ -315,7 +318,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ fIsModified = true; } } - + public String getId() { return fId; } @@ -328,7 +331,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ fIsModified = true; } } - + void setBuildSystemId(String id){ if(isReadOnly()) throw ExceptionFactory.createIsReadOnlyException(); @@ -337,7 +340,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ fIsModified = true; } } - + void serializeId() throws CoreException { fId = fCfg.getId(); ICStorageElement settings = getSettingsStorageElement(); @@ -349,21 +352,21 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ fName = fCfg.getName(); ICStorageElement settings = getSettingsStorageElement(); settings.clear(); - + settings.setAttribute(ID, fId); settings.setAttribute(NAME, fName); settings.setAttribute(BUILD_SYSTEM_ID, fBuildSystemId); - + if(fMacros != null && !fMacros.isEmpty()){ ICStorageElement macrosEl = settings.createChild(StorableCdtVariables.MACROS_ELEMENT_NAME); fMacros.serialize(macrosEl); } - + if(fExtSettingsProvider != null){ ICStorageElement child = settings.createChild(CExternalSettingsHolder.ELEMENT_EXT_SETTINGS_CONTAINER); fExtSettingsProvider.serialize(child); } - + // if(fRefInfoMap != null && fRefInfoMap.size() != 0){ // ICStorageElement el = settings.createChild(ELEMENT_REFERENCES); // for(Iterator iter = fRefInfoMap.values().iterator(); iter.hasNext();){ @@ -372,11 +375,11 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ // info.serialize(child); // } // } - + ICStorageElement extEl = settings.createChild(PROJECT_EXTENSIONS); encodeProjectExtensions(extEl); } - + public boolean isReadOnly(){ return fCfg.isReadOnly(); } @@ -390,7 +393,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ fMacros = new StorableCdtVariables(isReadOnly()); return fMacros; } - + public StorableEnvironment getEnvironment(){ return fEnvironment; } @@ -398,7 +401,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ public void setEnvironment(StorableEnvironment environment){ fEnvironment = environment; } - + public Map getReferenceInfo(){ if(!fCfg.isReadOnly()) return CfgExportSettingContainerFactory.getReferenceMap(fCfg); @@ -407,7 +410,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ return new LinkedHashMap(fRefMapCache); // if(fRefInfoMap == null || fRefInfoMap.size() == 0) // return new HashMap(0); -// +// // Map map = (HashMap)fRefInfoMap.clone(); // for(Iterator iter = map.entrySet().iterator(); iter.hasNext();){ // Map.Entry entry = (Map.Entry)iter.next(); @@ -416,18 +419,18 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ // } // return map; } - + // public Map getProjectRefInfoMap(){ // if(fRefInfoMap == null || fRefInfoMap.size() == 0) // return new HashMap(0); -// +// // return (Map)fRefInfoMap.clone(); // } - + // public void setProjectRefInfoMap(Map map){ // if(map == null && map.size() == 0) // fRefInfoMap = null; -// +// // fRefInfoMap = new HashMap(map); // fIsModified = true; // } @@ -451,13 +454,13 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ // } } -/* +/* private Map getExternalSettingsProviderMap(boolean create){ if(fExternalSettingsProviderMap == null && create) fExternalSettingsProviderMap = new HashMap(); return fExternalSettingsProviderMap; } - + public ExternalSettingInfo getExternalSettingsProviderInfo(String id){ Map map = getExternalSettingsProviderMap(false); if(map != null) @@ -468,11 +471,11 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ public void setExternalSettingsProviderInfo(ExternalSettingInfo info){ getExternalSettingsProviderMap(true).put(info.fProvider.getId(), info.fProvider); } -*/ +*/ public ICExternalSetting[] getExternalSettings(){ return fExtSettingsProvider.getExternalSettings(); } - + public ICExternalSetting createExternalSetting(String[] languageIDs, String[] contentTypeIDs, String[] extensions, ICSettingEntry[] entries) { @@ -490,13 +493,13 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ public boolean isModified(){ if(fIsModified) return true; - + if(fMacros != null && fMacros.isDirty()) return true; - + if(fEnvironment != null && fEnvironment.isDirty()) return true; - + return fExtSettingsProvider.isModified(); } @@ -504,11 +507,11 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ if(isReadOnly()) throw ExceptionFactory.createIsReadOnlyException(); fIsModified = modified; - + if(!modified){ if(fMacros != null) fMacros.setDirty(false); - + if(fEnvironment != null) fEnvironment.setDirty(false); } @@ -517,13 +520,13 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ void setModified(){ setModified(true); } - + private Map getSessionPropertiesMap(boolean create){ if(fSessionPropertiesMap == null && create) fSessionPropertiesMap = new HashMap(); return fSessionPropertiesMap; } - + public Object getSettionProperty(QualifiedName name){ Map map = getSessionPropertiesMap(false); return map != null ? map.get(name) : null; @@ -539,7 +542,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ map.remove(name); fIsModified = true; } - + //extension reference info private HashMap getExtMap(){ @@ -547,32 +550,33 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ fExtMap = new HashMap(); return fExtMap; } - + + @SuppressWarnings("unchecked") public Map getExtensionMapCopy(){ return (HashMap)getExtMap().clone(); } - + private ICConfigExtensionReference[] doGet(String extensionPointID){ return getExtMap().get(extensionPointID); } - - + + public ICConfigExtensionReference[] get(String extensionPointID) { checkReconsile(extensionPointID, true); - + ICConfigExtensionReference refs[] = doGet(extensionPointID); if (refs == null) return new ICConfigExtensionReference[0]; return refs.clone(); } - + private void checkReconsile(String extensionPointID, boolean toExt){ if(toExt){ Set[] delta = getReferenceDelta(extensionPointID); if(delta != null){ if(delta[0] != null){ - for(Iterator iter = delta[0].iterator(); iter.hasNext();){ - ICConfigExtensionReference ref = (ICConfigExtensionReference)iter.next(); + Set extSet = delta[0]; + for (ICConfigExtensionReference ref : extSet) { try { doRemove(ref); } catch (CoreException e) { @@ -581,8 +585,8 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ } } if(delta[1] != null){ - for(Iterator iter = delta[1].iterator(); iter.hasNext();){ - String id = (String)iter.next(); + Set idSet =delta[1]; + for (String id : idSet) { try { doCreate(extensionPointID, id); } catch (CoreException e) { @@ -605,11 +609,11 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ } } } - + private String[] getIds(ICConfigExtensionReference refs[]){ if(refs == null || refs.length == 0) return new String[0]; - + String[] ids = new String[refs.length]; for(int i = 0; i < refs.length; i++){ ids[i] = refs[i].getID(); @@ -621,7 +625,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ checkReconsile(CCorePlugin.BINARY_PARSER_UNIQ_ID, toExts); checkReconsile(CCorePlugin.ERROR_PARSER_UNIQ_ID, toExts); } - + // private boolean checkReconsile(String extPointId, ICConfigExtensionReference refs[], boolean get){ // if(!get || !(((IInternalCCfgInfo)fCfg).getConfigurationData(false) instanceof CConfigurationDescriptionCache)){ // if(CCorePlugin.BINARY_PARSER_UNIQ_ID.equals(extPointId)) @@ -659,7 +663,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ extensions[extensions.length - 1] = new CConfigExtensionReference(this, extensionPoint, extension); return extensions[extensions.length - 1]; } - + private ICConfigExtensionReference doCreate(String extensionPoint, String extension) throws CoreException { ICConfigExtensionReference extRef = createRef(extensionPoint, extension); return extRef; @@ -668,10 +672,10 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ public ICConfigExtensionReference create(String extensionPoint, String extension) throws CoreException { // boolean fireEvent = false; checkReconsile(extensionPoint, true); - + ICConfigExtensionReference[] refs = doGet(extensionPoint); ICConfigExtensionReference extRef = null; - + if (refs != null) { for (ICConfigExtensionReference ref : refs) { if(ref.getID().equals(extension)){ @@ -680,7 +684,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ } } } - + if(extRef == null){ extRef = createRef(extensionPoint, extension); checkReconsile(extensionPoint, false); @@ -718,7 +722,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ public void remove(ICConfigExtensionReference ext) throws CoreException { doRemove(ext); - + fIsModified = true; } @@ -742,11 +746,11 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ } public void remove(String extensionPoint) throws CoreException { - + boolean changed = doRemove(extensionPoint); - + checkReconsile(extensionPoint, false); - + if(changed) fIsModified = true; } @@ -827,14 +831,16 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ } } - public ICStorageElement importStorage(String id, ICStorageElement el) throws CoreException { + public ICStorageElement importStorage(String id, ICStorageElement el) throws CoreException { return getStorageBase().importStorage(id, el); } private void copyExtensionInfo(CConfigurationSpecSettings other){ other.reconcileExtensionSettings(true); if(other.fExtMap != null && other.fExtMap.size() != 0){ - fExtMap = (HashMap)other.fExtMap.clone(); + @SuppressWarnings("unchecked") + HashMap clone = (HashMap)other.fExtMap.clone(); + fExtMap = clone; for (Map.Entry entry : fExtMap.entrySet()) { CConfigExtensionReference refs[] = entry.getValue(); refs = refs.clone(); @@ -844,7 +850,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ entry.setValue(refs); } } - + if(other.fExtInfoMap != null && other.fExtInfoMap.size() != 0){ for (Map.Entry entry : fExtInfoMap.entrySet()) { CExtensionInfo info = entry.getValue(); @@ -853,15 +859,15 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ } } } - + public COwner getCOwner(){ return fOwner; } - + public String getCOwnerId(){ return fOwnerId; } - + private static boolean usesCache(ICConfigurationDescription cfg){ CConfigurationData data = ((IInternalCCfgInfo)cfg).getConfigurationData(false); if(data instanceof CConfigurationDescriptionCache){ @@ -889,8 +895,8 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ } return null; } - - + + private Set[] getReferenceDelta(ICConfigExtensionReference refs[], String[] extIds){ if(refs == null || refs.length == 0){ if(extIds == null || extIds.length == 0) @@ -900,19 +906,19 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ Map map = createRefMap(refs); return new Set[]{new HashSet(map.values()), null}; } - + Set idSet = new HashSet(Arrays.asList(extIds)); - Set idSetCopy = new HashSet(idSet); + Set idSetCopy = new HashSet(idSet); Map refsMap = createRefMap(refs); - + idSet.removeAll(refsMap.keySet()); refsMap.keySet().removeAll(idSetCopy); - + Set extSet = new HashSet(refsMap.values()); - + return new Set[]{extSet, idSet}; } - + private Map createRefMap(ICConfigExtensionReference refs[]){ Map refsMap = new HashMap(refs.length); for (ICConfigExtensionReference ref : refs) { @@ -920,16 +926,16 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ } return refsMap; } - + boolean extRefSettingsEqual(CConfigurationSpecSettings other){ if(fExtMap == null || fExtMap.size() == 0) return other.fExtMap == null || other.fExtMap.size() == 0; if(other.fExtMap == null || other.fExtMap.size() == 0) return false; - + if(fExtMap.size() != other.fExtMap.size()) return false; - + for (Entry entry : fExtMap.entrySet()) { ICConfigExtensionReference[] thisRefs = entry.getValue(); ICConfigExtensionReference[] otherRefs = other.fExtMap.get(entry.getKey()); @@ -937,24 +943,24 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{ return thisRefs.length == 0; if(thisRefs.length != otherRefs.length) return false; - + Map map = createRefMap(thisRefs); map.entrySet().removeAll(createRefMap(otherRefs).entrySet()); if(map.size() != 0) return false; } - + return true; } - + public String[] getExternalSettingsProviderIds(){ return ExtensionContainerFactory.getReferencedProviderIds(fCfg); } - + public void setExternalSettingsProviderIds(String ids[]){ ExtensionContainerFactory.setReferencedProviderIds(fCfg, ids); } - + public void updateExternalSettingsProviders(String[] ids){ ExtensionContainerFactory.updateReferencedProviderIds(fCfg, ids); }