1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

cosmetics: generics/enhanced loops

This commit is contained in:
Andrew Gvozdev 2010-01-25 15:47:23 +00:00
parent f3bd8f6e30
commit d0ef57bff8

View file

@ -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 <cconfiguration id="....> elements within
* the org.eclipse.cdt.core.settings storageModule in the project xml file
*/
@ -87,21 +86,21 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
private COwner fOwner;
// private CConfigBasedDescriptor fDescriptor;
// private Map fExternalSettingsProviderMap;
public CConfigurationSpecSettings(ICConfigurationDescription des, ICStorageElement storage) throws CoreException{
fCfg = des;
fRootStorageElement = storage;
ICStorageElement settings = getSettingsStorageElement();
fBuildSystemId = settings.getAttribute(BUILD_SYSTEM_ID);
fName = settings.getAttribute(NAME);
fId = settings.getAttribute(ID);
setCOwner(settings.getAttribute(OWNER_ID));
for (ICStorageElement child : settings.getChildren()) {
String name = child.getName();
if(StorableCdtVariables.MACROS_ELEMENT_NAME.equals(name)){
fMacros = new StorableCdtVariables(child, fCfg.isReadOnly());
}/* else if(ELEMENT_REFERENCES.equals(name)){
@ -114,19 +113,19 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
loadExtensionInfo(child, false);
}
}
// if(fMacros == null)
// fMacros = new StorableMacros(des.isReadOnly());
}
public CConfigurationSpecSettings(ICConfigurationDescription des, ICStorageElement storage, ICStorageElement oldInfo) throws CoreException{
fCfg = des;
fRootStorageElement = storage;
loadOldStileDescription(oldInfo);
}
private void loadOldStileDescription(ICStorageElement storage) throws CoreException{
setCOwner(storage.getAttribute(OLD_OWNER_ID));
@ -149,33 +148,36 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
fBuildSystemId = base.fBuildSystemId;
fName = base.fName;
fId = base.fId;
// copyRefInfos(base.fRefInfoMap);
if(base.fMacros != null)
fMacros = new StorableCdtVariables(base.fMacros, des.isReadOnly());
if(base.fExtSettingsProvider != null)
fExtSettingsProvider = new CExternalSettingsHolder(base.fExtSettingsProvider);
if(base.fSessionPropertiesMap != null)
fSessionPropertiesMap = (HashMap<QualifiedName, Object>)base.fSessionPropertiesMap.clone();
if(base.fSessionPropertiesMap != null) {
@SuppressWarnings("unchecked")
HashMap<QualifiedName, Object> clone = (HashMap<QualifiedName, Object>)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<String, String> getReferenceInfo(){
if(!fCfg.isReadOnly())
return CfgExportSettingContainerFactory.getReferenceMap(fCfg);
@ -407,7 +410,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
return new LinkedHashMap<String, String>(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<QualifiedName, Object> getSessionPropertiesMap(boolean create){
if(fSessionPropertiesMap == null && create)
fSessionPropertiesMap = new HashMap<QualifiedName, Object>();
return fSessionPropertiesMap;
}
public Object getSettionProperty(QualifiedName name){
Map<QualifiedName, Object> 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<String, CConfigExtensionReference[]> getExtMap(){
@ -547,32 +550,33 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
fExtMap = new HashMap<String, CConfigExtensionReference[]>();
return fExtMap;
}
@SuppressWarnings("unchecked")
public Map<String, CConfigExtensionReference[]> getExtensionMapCopy(){
return (HashMap<String, CConfigExtensionReference[]>)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<ICConfigExtensionReference> 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<String> 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<String, CConfigExtensionReference[]>)other.fExtMap.clone();
@SuppressWarnings("unchecked")
HashMap<String, CConfigExtensionReference[]> clone = (HashMap<String, CConfigExtensionReference[]>)other.fExtMap.clone();
fExtMap = clone;
for (Map.Entry<String, CConfigExtensionReference[]> 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<CConfigExtensionReference, CExtensionInfo> 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<String, ICConfigExtensionReference> map = createRefMap(refs);
return new Set[]{new HashSet<ICConfigExtensionReference>(map.values()), null};
}
Set<String> idSet = new HashSet<String>(Arrays.asList(extIds));
Set<String> idSetCopy = new HashSet<String>(idSet);
Set<String> idSetCopy = new HashSet<String>(idSet);
Map<String, ICConfigExtensionReference> refsMap = createRefMap(refs);
idSet.removeAll(refsMap.keySet());
refsMap.keySet().removeAll(idSetCopy);
Set<ICConfigExtensionReference> extSet = new HashSet<ICConfigExtensionReference>(refsMap.values());
return new Set[]{extSet, idSet};
}
private Map<String, ICConfigExtensionReference> createRefMap(ICConfigExtensionReference refs[]){
Map<String, ICConfigExtensionReference> refsMap = new HashMap<String, ICConfigExtensionReference>(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<String, CConfigExtensionReference[]> 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<String, ICConfigExtensionReference> 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);
}