1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 11:25:35 +02:00

cosmetics: enhanced loops etc

This commit is contained in:
Andrew Gvozdev 2010-01-24 22:25:56 +00:00
parent 257f512b69
commit 37c2c68fbd

View file

@ -45,21 +45,21 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc
private List<IPathEntryStoreListener> fListeners; private List<IPathEntryStoreListener> fListeners;
private IProject fProject; private IProject fProject;
static final QualifiedName PATH_ENTRY_COLLECTOR_PROPERTY_NAME = new QualifiedName(CCorePlugin.PLUGIN_ID, "PathEntryStoreCollector"); //$NON-NLS-1$ static final QualifiedName PATH_ENTRY_COLLECTOR_PROPERTY_NAME = new QualifiedName(CCorePlugin.PLUGIN_ID, "PathEntryStoreCollector"); //$NON-NLS-1$
/** /**
* *
*/ */
public ConfigBasedPathEntryStore(IProject project) { public ConfigBasedPathEntryStore(IProject project) {
fProject = project; fProject = project;
fListeners = Collections.synchronizedList(new ArrayList<IPathEntryStoreListener>()); fListeners = Collections.synchronizedList(new ArrayList<IPathEntryStoreListener>());
CProjectDescriptionManager.getInstance().addCProjectDescriptionListener(this, CProjectDescriptionEvent.APPLIED | CProjectDescriptionEvent.LOADED); CProjectDescriptionManager.getInstance().addCProjectDescriptionListener(this, CProjectDescriptionEvent.APPLIED | CProjectDescriptionEvent.LOADED);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.resources.IPathEntryStore#addPathEntryStoreListener(org.eclipse.cdt.core.resources.IPathEntryStoreListener) * @see org.eclipse.cdt.core.resources.IPathEntryStore#addPathEntryStoreListener(org.eclipse.cdt.core.resources.IPathEntryStoreListener)
*/ */
public void addPathEntryStoreListener(IPathEntryStoreListener listener) { public void addPathEntryStoreListener(IPathEntryStoreListener listener) {
fListeners.add(listener); fListeners.add(listener);
} }
@ -74,8 +74,8 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc
PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(this, project, PathEntryStoreChangedEvent.CONTENT_CHANGED); PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(this, project, PathEntryStoreChangedEvent.CONTENT_CHANGED);
IPathEntryStoreListener[] observers = new IPathEntryStoreListener[fListeners.size()]; IPathEntryStoreListener[] observers = new IPathEntryStoreListener[fListeners.size()];
fListeners.toArray(observers); fListeners.toArray(observers);
for (int i = 0; i < observers.length; i++) { for (IPathEntryStoreListener observer : observers) {
observers[i].pathEntryStoreChanged(evt); observer.pathEntryStoreChanged(evt);
} }
} }
@ -86,8 +86,8 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc
PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(this, fProject, PathEntryStoreChangedEvent.STORE_CLOSED); PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(this, fProject, PathEntryStoreChangedEvent.STORE_CLOSED);
IPathEntryStoreListener[] observers = new IPathEntryStoreListener[fListeners.size()]; IPathEntryStoreListener[] observers = new IPathEntryStoreListener[fListeners.size()];
fListeners.toArray(observers); fListeners.toArray(observers);
for (int i = 0; i < observers.length; i++) { for (IPathEntryStoreListener observer : observers) {
observers[i].pathEntryStoreChanged(evt); observer.pathEntryStoreChanged(evt);
} }
CProjectDescriptionManager.getInstance().removeCProjectDescriptionListener(this); CProjectDescriptionManager.getInstance().removeCProjectDescriptionListener(this);
} }
@ -119,11 +119,11 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc
List<IPathEntry> sysList = es[1]; List<IPathEntry> sysList = es[1];
List<IPathEntry> usrList = es[0]; List<IPathEntry> usrList = es[0];
List<IPathEntry> newUsrList = new ArrayList<IPathEntry>(entries.length); List<IPathEntry> newUsrList = new ArrayList<IPathEntry>(entries.length);
for(int i = 0; i < entries.length; i++){ for (IPathEntry entry : entries) {
if(entries[i].getEntryKind() != IPathEntry.CDT_CONTAINER) if(entry.getEntryKind() != IPathEntry.CDT_CONTAINER)
newUsrList.add(entries[i]); newUsrList.add(entry);
} }
if(!newUsrList.equals(usrList)){ if(!newUsrList.equals(usrList)){
usrList = newUsrList; usrList = newUsrList;
ICProjectDescription des = CoreModel.getDefault().getProjectDescription(fProject, true); ICProjectDescription des = CoreModel.getDefault().getProjectDescription(fProject, true);
@ -135,25 +135,24 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc
ReferenceSettingsInfo rInfo = tr.applyPathEntries(usrEntries, sysEntries, PathEntryTranslator.OP_REPLACE); ReferenceSettingsInfo rInfo = tr.applyPathEntries(usrEntries, sysEntries, PathEntryTranslator.OP_REPLACE);
cfgDes.removeExternalSettings(); cfgDes.removeExternalSettings();
ICExternalSetting extSettings[] = rInfo.getExternalSettings(); ICExternalSetting extSettings[] = rInfo.getExternalSettings();
for(int i = 0; i < extSettings.length; i++){ for (ICExternalSetting setting : extSettings) {
ICExternalSetting setting = extSettings[i]; cfgDes.createExternalSetting(setting.getCompatibleLanguageIds(),
cfgDes.createExternalSetting(setting.getCompatibleLanguageIds(),
setting.getCompatibleContentTypeIds(), setting.getCompatibleContentTypeIds(),
setting.getCompatibleExtensions(), setting.getCompatibleExtensions(),
setting.getEntries()); setting.getEntries());
} }
Map<String, String> refMap = rInfo.getRefProjectsMap(); Map<String, String> refMap = rInfo.getRefProjectsMap();
cfgDes.setReferenceInfo(refMap); cfgDes.setReferenceInfo(refMap);
CoreModel.getDefault().setProjectDescription(fProject, des); CoreModel.getDefault().setProjectDescription(fProject, des);
} }
} }
} }
private static void clearCachedEntries(ICProjectDescription des){ private static void clearCachedEntries(ICProjectDescription des){
ICConfigurationDescription[] cfgDess = des.getConfigurations(); ICConfigurationDescription[] cfgDess = des.getConfigurations();
for(int i = 0; i < cfgDess.length; i++){ for (ICConfigurationDescription cfgDes : cfgDess) {
setCachedEntries(cfgDess[i], null); setCachedEntries(cfgDes, null);
} }
} }
@ -161,7 +160,7 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc
IProject project = event.getProject(); IProject project = event.getProject();
if(!fProject.equals(project)) if(!fProject.equals(project))
return; return;
switch(event.getEventType()){ switch(event.getEventType()){
case CProjectDescriptionEvent.APPLIED:{ case CProjectDescriptionEvent.APPLIED:{
ICProjectDescription des = event.getNewCProjectDescription(); ICProjectDescription des = event.getNewCProjectDescription();
@ -172,13 +171,13 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc
List<IPathEntry>[] oldEs = getCachedEntries(oldIndexCfg); List<IPathEntry>[] oldEs = getCachedEntries(oldIndexCfg);
if(oldEs != null) if(oldEs != null)
oldCrEntries = oldEs[1]; oldCrEntries = oldEs[1];
clearCachedEntries(oldDes); clearCachedEntries(oldDes);
} }
if(des != null){ if(des != null){
//TODO: smart delta handling //TODO: smart delta handling
clearCachedEntries(des); clearCachedEntries(des);
if(oldCrEntries != null){ if(oldCrEntries != null){
ICConfigurationDescription newIndexCfg = des.getDefaultSettingConfiguration(); ICConfigurationDescription newIndexCfg = des.getDefaultSettingConfiguration();
List<IPathEntry>[] newEs = getEntries(fProject, newIndexCfg); List<IPathEntry>[] newEs = getEntries(fProject, newIndexCfg);
@ -186,7 +185,7 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc
if(!Arrays.equals(oldCrEntries.toArray(), newCrEntries.toArray())){ if(!Arrays.equals(oldCrEntries.toArray(), newCrEntries.toArray())){
CModelManager manager = CModelManager.getDefault(); CModelManager manager = CModelManager.getDefault();
ICProject cproject = manager.create(project); ICProject cproject = manager.create(project);
// ConfigBasedPathEntryContainer newContainer = createContainer(des); // ConfigBasedPathEntryContainer newContainer = createContainer(des);
try { try {
@ -202,7 +201,7 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc
} }
} }
} }
// private static PathEntryCollector getCollector(ICProjectDescription des){ // private static PathEntryCollector getCollector(ICProjectDescription des){
// ICConfigurationDescription cfgDes = ((CProjectDescription)des).getIndexConfiguration(); // ICConfigurationDescription cfgDes = ((CProjectDescription)des).getIndexConfiguration();
// if(cfgDes != null){ // if(cfgDes != null){
@ -228,16 +227,16 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc
} }
return null; return null;
} }
private static List<IPathEntry>[] createEntriesList(ICConfigurationDescription cfgDes, PathEntryCollector cr){ private static List<IPathEntry>[] createEntriesList(ICConfigurationDescription cfgDes, PathEntryCollector cr){
ArrayList<IPathEntry>[] es = new ArrayList[2]; ArrayList<IPathEntry>[] es = new ArrayList[2];
es[0] = new ArrayList<IPathEntry>(); es[0] = new ArrayList<IPathEntry>();
cr.getEntries(es[0], PathEntryTranslator.INCLUDE_USER, cfgDes); cr.getEntries(es[0], PathEntryTranslator.INCLUDE_USER, cfgDes);
es[0].trimToSize(); es[0].trimToSize();
es[1] = new ArrayList<IPathEntry>(); es[1] = new ArrayList<IPathEntry>();
cr.getEntries(es[1], PathEntryTranslator.INCLUDE_BUILT_INS, cfgDes); cr.getEntries(es[1], PathEntryTranslator.INCLUDE_BUILT_INS, cfgDes);
es[1].trimToSize(); es[1].trimToSize();
return es; return es;
} }
@ -256,12 +255,12 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc
// return getCollector(des); // return getCollector(des);
// return null; // return null;
// } // }
private static ICConfigurationDescription getIndexCfg(IProject project){ private static ICConfigurationDescription getIndexCfg(IProject project){
ICProjectDescription des = CCorePlugin.getDefault().getProjectDescription(project, false); ICProjectDescription des = CCorePlugin.getDefault().getProjectDescription(project, false);
return des != null ? des.getDefaultSettingConfiguration() : null; return des != null ? des.getDefaultSettingConfiguration() : null;
} }
private static List<IPathEntry> getContainerEntries(IProject project){ private static List<IPathEntry> getContainerEntries(IProject project){
ICProjectDescription des = CCorePlugin.getDefault().getProjectDescription(project, false); ICProjectDescription des = CCorePlugin.getDefault().getProjectDescription(project, false);
if(des != null) if(des != null)