diff options
Diffstat (limited to 'core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ConfigBasedPathEntryStore.java')
-rw-r--r-- | core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ConfigBasedPathEntryStore.java | 164 |
1 files changed, 84 insertions, 80 deletions
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ConfigBasedPathEntryStore.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ConfigBasedPathEntryStore.java index 4dbf1b75e64..201b0e88e6c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ConfigBasedPathEntryStore.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/ConfigBasedPathEntryStore.java @@ -48,7 +48,8 @@ import org.eclipse.core.runtime.QualifiedName; public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDescriptionListener { private List<IPathEntryStoreListener> fListeners; 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$ /** * @@ -57,7 +58,8 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc fProject = project; fListeners = Collections.synchronizedList(new ArrayList<IPathEntryStoreListener>()); - CProjectDescriptionManager.getInstance().addCProjectDescriptionListener(this, CProjectDescriptionEvent.APPLIED | CProjectDescriptionEvent.LOADED); + CProjectDescriptionManager.getInstance().addCProjectDescriptionListener(this, + CProjectDescriptionEvent.APPLIED | CProjectDescriptionEvent.LOADED); } /* (non-Javadoc) @@ -77,7 +79,8 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc } private void fireContentChangedEvent(IProject project) { - PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(this, project, PathEntryStoreChangedEvent.CONTENT_CHANGED); + PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(this, project, + PathEntryStoreChangedEvent.CONTENT_CHANGED); IPathEntryStoreListener[] observers = new IPathEntryStoreListener[fListeners.size()]; fListeners.toArray(observers); for (IPathEntryStoreListener observer : observers) { @@ -90,7 +93,8 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc */ @Override public void close() { - PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(this, fProject, PathEntryStoreChangedEvent.STORE_CLOSED); + PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(this, fProject, + PathEntryStoreChangedEvent.STORE_CLOSED); IPathEntryStoreListener[] observers = new IPathEntryStoreListener[fListeners.size()]; fListeners.toArray(observers); for (IPathEntryStoreListener observer : observers) { @@ -119,7 +123,7 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc public IPathEntry[] getRawPathEntries() throws CoreException { ICConfigurationDescription cfg = getIndexCfg(fProject); List<IPathEntry>[] es = getEntries(fProject, cfg); - if(es != null){ + if (es != null) { List<IPathEntry> list = new ArrayList<IPathEntry>(es[0].size() + 1); list.addAll(es[0]); list.add(CoreModel.newContainerEntry(ConfigBasedPathEntryContainer.CONTAINER_PATH)); @@ -132,16 +136,16 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc public void setRawPathEntries(IPathEntry[] entries) throws CoreException { ICConfigurationDescription cfg = getIndexCfg(fProject); List<IPathEntry> es[] = getEntries(fProject, cfg); - if(es != null){ + if (es != null) { List<IPathEntry> sysList = es[1]; List<IPathEntry> usrList = es[0]; List<IPathEntry> newUsrList = new ArrayList<IPathEntry>(entries.length); for (IPathEntry entry : entries) { - if(entry.getEntryKind() != IPathEntry.CDT_CONTAINER) + if (entry.getEntryKind() != IPathEntry.CDT_CONTAINER) newUsrList.add(entry); } - if(!newUsrList.equals(usrList)){ + if (!newUsrList.equals(usrList)) { usrList = newUsrList; ICProjectDescription des = CoreModel.getDefault().getProjectDescription(fProject, true); ICConfigurationDescription cfgDes = des.getDefaultSettingConfiguration(); @@ -149,13 +153,13 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc PathEntryTranslator tr = new PathEntryTranslator(fProject, data); IPathEntry[] usrEntries = usrList.toArray(new IPathEntry[usrList.size()]); IPathEntry[] sysEntries = sysList.toArray(new IPathEntry[sysList.size()]); - ReferenceSettingsInfo rInfo = tr.applyPathEntries(usrEntries, sysEntries, PathEntryTranslator.OP_REPLACE); + ReferenceSettingsInfo rInfo = tr.applyPathEntries(usrEntries, sysEntries, + PathEntryTranslator.OP_REPLACE); cfgDes.removeExternalSettings(); ICExternalSetting extSettings[] = rInfo.getExternalSettings(); for (ICExternalSetting setting : extSettings) { cfgDes.createExternalSetting(setting.getCompatibleLanguageIds(), - setting.getCompatibleContentTypeIds(), - setting.getCompatibleExtensions(), + setting.getCompatibleContentTypeIds(), setting.getCompatibleExtensions(), setting.getEntries()); } Map<String, String> refMap = rInfo.getRefProjectsMap(); @@ -166,7 +170,7 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc } } - private static void clearCachedEntries(ICProjectDescription des){ + private static void clearCachedEntries(ICProjectDescription des) { ICConfigurationDescription[] cfgDess = des.getConfigurations(); for (ICConfigurationDescription cfgDes : cfgDess) { setCachedEntries(cfgDes, null); @@ -176,67 +180,67 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc @Override public void handleEvent(CProjectDescriptionEvent event) { IProject project = event.getProject(); - if(!fProject.equals(project)) + if (!fProject.equals(project)) return; - switch(event.getEventType()){ - case CProjectDescriptionEvent.APPLIED:{ - ICProjectDescription des = event.getNewCProjectDescription(); - ICProjectDescription oldDes = event.getOldCProjectDescription(); - List<IPathEntry> oldCrEntries = null; - if(oldDes != null){ - ICConfigurationDescription oldIndexCfg = oldDes.getDefaultSettingConfiguration(); - List<IPathEntry>[] oldEs = getCachedEntries(oldIndexCfg); - if(oldEs != null) - oldCrEntries = oldEs[1]; - - clearCachedEntries(oldDes); - } - if(des != null){ - //TODO: smart delta handling - clearCachedEntries(des); - - if(oldCrEntries != null){ - ICConfigurationDescription newIndexCfg = des.getDefaultSettingConfiguration(); - List<IPathEntry>[] newEs = getEntries(fProject, newIndexCfg); - List<IPathEntry> newCrEntries = newEs[1]; - if(!Arrays.equals(oldCrEntries.toArray(), newCrEntries.toArray())){ - CModelManager manager = CModelManager.getDefault(); - ICProject cproject = manager.create(project); - - - // ConfigBasedPathEntryContainer newContainer = createContainer(des); - try { - PathEntryManager.getDefault().clearPathEntryContainer(new ICProject[]{cproject}, ConfigBasedPathEntryContainer.CONTAINER_PATH, new NullProgressMonitor()); - } catch (CModelException e) { - CCorePlugin.log(e); - } + switch (event.getEventType()) { + case CProjectDescriptionEvent.APPLIED: { + ICProjectDescription des = event.getNewCProjectDescription(); + ICProjectDescription oldDes = event.getOldCProjectDescription(); + List<IPathEntry> oldCrEntries = null; + if (oldDes != null) { + ICConfigurationDescription oldIndexCfg = oldDes.getDefaultSettingConfiguration(); + List<IPathEntry>[] oldEs = getCachedEntries(oldIndexCfg); + if (oldEs != null) + oldCrEntries = oldEs[1]; + + clearCachedEntries(oldDes); + } + if (des != null) { + //TODO: smart delta handling + clearCachedEntries(des); + + if (oldCrEntries != null) { + ICConfigurationDescription newIndexCfg = des.getDefaultSettingConfiguration(); + List<IPathEntry>[] newEs = getEntries(fProject, newIndexCfg); + List<IPathEntry> newCrEntries = newEs[1]; + if (!Arrays.equals(oldCrEntries.toArray(), newCrEntries.toArray())) { + CModelManager manager = CModelManager.getDefault(); + ICProject cproject = manager.create(project); + + // ConfigBasedPathEntryContainer newContainer = createContainer(des); + try { + PathEntryManager.getDefault().clearPathEntryContainer(new ICProject[] { cproject }, + ConfigBasedPathEntryContainer.CONTAINER_PATH, new NullProgressMonitor()); + } catch (CModelException e) { + CCorePlugin.log(e); } } } - fireContentChangedEvent(fProject); - break; } + fireContentChangedEvent(fProject); + break; + } } } -// private static PathEntryCollector getCollector(ICProjectDescription des){ -// ICConfigurationDescription cfgDes = ((CProjectDescription)des).getIndexConfiguration(); -// if(cfgDes != null){ -// PathEntryCollector cr = getCachedCollector(cfgDes); -// if(cr == null){ -// cr = PathEntryTranslator.collectEntries(des.getProject(), cfgDes); -// setCachedCollector(cfgDes, cr); -// } -// return cr; -// } -// return null; -// } - - private static List<IPathEntry>[] getEntries(IProject project, ICConfigurationDescription cfgDes){ - if(cfgDes != null){ + // private static PathEntryCollector getCollector(ICProjectDescription des){ + // ICConfigurationDescription cfgDes = ((CProjectDescription)des).getIndexConfiguration(); + // if(cfgDes != null){ + // PathEntryCollector cr = getCachedCollector(cfgDes); + // if(cr == null){ + // cr = PathEntryTranslator.collectEntries(des.getProject(), cfgDes); + // setCachedCollector(cfgDes, cr); + // } + // return cr; + // } + // return null; + // } + + private static List<IPathEntry>[] getEntries(IProject project, ICConfigurationDescription cfgDes) { + if (cfgDes != null) { List<IPathEntry>[] es = getCachedEntries(cfgDes); - if(es == null){ + if (es == null) { PathEntryCollector cr = PathEntryTranslator.collectEntries(project, cfgDes); es = createEntriesList(cfgDes, cr); setCachedEntries(cfgDes, es); @@ -246,7 +250,7 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc return null; } - private static List<IPathEntry>[] createEntriesList(ICConfigurationDescription cfgDes, PathEntryCollector cr){ + private static List<IPathEntry>[] createEntriesList(ICConfigurationDescription cfgDes, PathEntryCollector cr) { @SuppressWarnings("unchecked") ArrayList<IPathEntry>[] es = new ArrayList[2]; es[0] = new ArrayList<IPathEntry>(); @@ -260,47 +264,47 @@ public class ConfigBasedPathEntryStore implements IPathEntryStore, ICProjectDesc } @SuppressWarnings("unchecked") - private static List<IPathEntry>[] getCachedEntries(ICConfigurationDescription cfgDes){ - return (List<IPathEntry>[])cfgDes.getSessionProperty(PATH_ENTRY_COLLECTOR_PROPERTY_NAME); + private static List<IPathEntry>[] getCachedEntries(ICConfigurationDescription cfgDes) { + return (List<IPathEntry>[]) cfgDes.getSessionProperty(PATH_ENTRY_COLLECTOR_PROPERTY_NAME); } - private static void setCachedEntries(ICConfigurationDescription cfgDes, List<IPathEntry>[] es){ + private static void setCachedEntries(ICConfigurationDescription cfgDes, List<IPathEntry>[] es) { cfgDes.setSessionProperty(PATH_ENTRY_COLLECTOR_PROPERTY_NAME, es); } -// public static PathEntryCollector getCollector(IProject project){ -// ICProjectDescription des = CCorePlugin.getDefault().getProjectDescription(project, false); -// if(des != null) -// return getCollector(des); -// return null; -// } + // public static PathEntryCollector getCollector(IProject project){ + // ICProjectDescription des = CCorePlugin.getDefault().getProjectDescription(project, false); + // if(des != null) + // return getCollector(des); + // return null; + // } - private static ICConfigurationDescription getIndexCfg(IProject project){ + private static ICConfigurationDescription getIndexCfg(IProject project) { ICProjectDescription des = CCorePlugin.getDefault().getProjectDescription(project, false); 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); - if(des != null) + if (des != null) return getContainerEntries(des); return new ArrayList<IPathEntry>(0); } - private static List<IPathEntry> getContainerEntries(ICProjectDescription des){ + private static List<IPathEntry> getContainerEntries(ICProjectDescription des) { ICConfigurationDescription cfg = des.getDefaultSettingConfiguration(); List<IPathEntry> es[] = getEntries(des.getProject(), cfg); - if(es != null) + if (es != null) return es[1]; return new ArrayList<IPathEntry>(0); } - public static ConfigBasedPathEntryContainer createContainer(IProject project){ + public static ConfigBasedPathEntryContainer createContainer(IProject project) { List<IPathEntry> list = getContainerEntries(project); return new ConfigBasedPathEntryContainer(list); } - public static ConfigBasedPathEntryContainer createContainer(ICProjectDescription des){ + public static ConfigBasedPathEntryContainer createContainer(ICProjectDescription des) { List<IPathEntry> list = getContainerEntries(des); return new ConfigBasedPathEntryContainer(list); } |