mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-26 18:35:32 +02:00
removed getResources() from ILanguageSettingsChangeEvent
This commit is contained in:
parent
9beee54466
commit
8d38ea9dbb
4 changed files with 21 additions and 177 deletions
|
@ -635,8 +635,6 @@ public class LanguageSettingsListenersTests extends TestCase {
|
||||||
assertEquals(project.getName(), event.getProjectName());
|
assertEquals(project.getName(), event.getProjectName());
|
||||||
assertEquals(1, event.getConfigurationDescriptionIds().length);
|
assertEquals(1, event.getConfigurationDescriptionIds().length);
|
||||||
assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]);
|
assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]);
|
||||||
assertEquals(1, event.getResources(cfgDescriptionId).length);
|
|
||||||
assertEquals(project, event.getResources(cfgDescriptionId)[0]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,9 +699,6 @@ public class LanguageSettingsListenersTests extends TestCase {
|
||||||
assertEquals(project.getName(), event.getProjectName());
|
assertEquals(project.getName(), event.getProjectName());
|
||||||
assertEquals(1, event.getConfigurationDescriptionIds().length);
|
assertEquals(1, event.getConfigurationDescriptionIds().length);
|
||||||
assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]);
|
assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]);
|
||||||
assertEquals(1, event.getResources(cfgDescriptionId).length);
|
|
||||||
assertEquals(project, event.getResources(cfgDescriptionId)[0]);
|
|
||||||
// TODO - drill to the entries
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -774,9 +769,6 @@ public class LanguageSettingsListenersTests extends TestCase {
|
||||||
assertEquals(project.getName(), event.getProjectName());
|
assertEquals(project.getName(), event.getProjectName());
|
||||||
assertEquals(1, event.getConfigurationDescriptionIds().length);
|
assertEquals(1, event.getConfigurationDescriptionIds().length);
|
||||||
assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]);
|
assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]);
|
||||||
assertEquals(1, event.getResources(cfgDescriptionId).length);
|
|
||||||
assertEquals(project, event.getResources(cfgDescriptionId)[0]);
|
|
||||||
// TODO - drill to the entries
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ICConfigurationDescription[] cfgDescriptions = prjDescription_2.getConfigurations();
|
ICConfigurationDescription[] cfgDescriptions = prjDescription_2.getConfigurations();
|
||||||
|
@ -935,8 +927,6 @@ public class LanguageSettingsListenersTests extends TestCase {
|
||||||
assertEquals(project.getName(), event.getProjectName());
|
assertEquals(project.getName(), event.getProjectName());
|
||||||
assertEquals(1, event.getConfigurationDescriptionIds().length);
|
assertEquals(1, event.getConfigurationDescriptionIds().length);
|
||||||
assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]);
|
assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]);
|
||||||
assertEquals(1, event.getResources(cfgDescriptionId).length);
|
|
||||||
assertEquals(project, event.getResources(cfgDescriptionId)[0]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1014,9 +1004,6 @@ public class LanguageSettingsListenersTests extends TestCase {
|
||||||
assertEquals(project.getName(), event.getProjectName());
|
assertEquals(project.getName(), event.getProjectName());
|
||||||
assertEquals(1, event.getConfigurationDescriptionIds().length);
|
assertEquals(1, event.getConfigurationDescriptionIds().length);
|
||||||
assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]);
|
assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]);
|
||||||
assertEquals(1, event.getResources(cfgDescriptionId).length);
|
|
||||||
assertEquals(project, event.getResources(cfgDescriptionId)[0]);
|
|
||||||
// TODO - drill to the entries
|
|
||||||
}
|
}
|
||||||
// Change the provider's entries back (bug was found for this case)
|
// Change the provider's entries back (bug was found for this case)
|
||||||
{
|
{
|
||||||
|
@ -1052,9 +1039,6 @@ public class LanguageSettingsListenersTests extends TestCase {
|
||||||
assertEquals(project.getName(), event.getProjectName());
|
assertEquals(project.getName(), event.getProjectName());
|
||||||
assertEquals(1, event.getConfigurationDescriptionIds().length);
|
assertEquals(1, event.getConfigurationDescriptionIds().length);
|
||||||
assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]);
|
assertEquals(cfgDescriptionId, event.getConfigurationDescriptionIds()[0]);
|
||||||
assertEquals(1, event.getResources(cfgDescriptionId).length);
|
|
||||||
assertEquals(project, event.getResources(cfgDescriptionId)[0]);
|
|
||||||
// TODO - drill to the entries
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,26 +11,28 @@
|
||||||
package org.eclipse.cdt.internal.core.language.settings.providers;
|
package org.eclipse.cdt.internal.core.language.settings.providers;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||||
import org.eclipse.core.resources.IResource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the details of changes that occurred as a result of modifying
|
* Contains the details of changes that occurred as a result of modifying
|
||||||
* language settings entries {@link ICLanguageSettingEntry}.
|
* language settings entries {@link ICLanguageSettingEntry}. The event is
|
||||||
|
* associated with a project.
|
||||||
|
*
|
||||||
|
* API notes: this interface probably is not stable yet as it is not currently
|
||||||
|
* clear how it may need to be used in future. Only bare minimum is provided
|
||||||
|
* here at this point.
|
||||||
*
|
*
|
||||||
* @noextend This interface is not intended to be extended by clients.
|
* @noextend This interface is not intended to be extended by clients.
|
||||||
* @noimplement This interface is not intended to be implemented by clients.
|
* @noimplement This interface is not intended to be implemented by clients.
|
||||||
*/
|
*/
|
||||||
public interface ILanguageSettingsChangeEvent {
|
public interface ILanguageSettingsChangeEvent {
|
||||||
|
/**
|
||||||
|
* @return project name where the event occurred.
|
||||||
|
*/
|
||||||
public String getProjectName();
|
public String getProjectName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return configuration IDs which are affected by the language settings changes.
|
||||||
|
*/
|
||||||
public String[] getConfigurationDescriptionIds();
|
public String[] getConfigurationDescriptionIds();
|
||||||
|
|
||||||
public IResource[] getResources(String cfgDescriptionId);
|
|
||||||
|
|
||||||
// // AG - YAGNI
|
|
||||||
// public List<ICLanguageSettingEntry> getSettingEntriesOld(ICConfigurationDescription cfgDescription, IResource rc, String languageId);
|
|
||||||
// public List<ICLanguageSettingEntry> getSettingEntriesNew(ICConfigurationDescription cfgDescription, IResource rc, String languageId);
|
|
||||||
// // AG - or maybe
|
|
||||||
// ILanguageSettingsDelta getDelta(ICConfigurationDescription cfgDescription);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,29 +10,19 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.language.settings.providers;
|
package org.eclipse.cdt.internal.core.language.settings.providers;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
|
||||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
|
||||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
|
||||||
import org.eclipse.core.resources.IProject;
|
|
||||||
import org.eclipse.core.resources.IResource;
|
|
||||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
|
||||||
import org.eclipse.core.runtime.Assert;
|
|
||||||
|
|
||||||
|
|
||||||
// TODO possibly make an interface from that
|
/**
|
||||||
|
* This class currently is a placeholder holding old and new states.
|
||||||
|
* If more details need to be pulled out of delta, it could be elaborated further.
|
||||||
|
*/
|
||||||
public class LanguageSettingsDelta {
|
public class LanguageSettingsDelta {
|
||||||
// maps need to be ordered by providers
|
// maps need to be ordered by providers
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private LinkedHashMap<String, // providerId
|
private LinkedHashMap<String, // providerId
|
||||||
LanguageSettingsStorage> oldLanguageSettingsState;
|
LanguageSettingsStorage> oldLanguageSettingsState;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private LinkedHashMap<String, // providerId
|
private LinkedHashMap<String, // providerId
|
||||||
LanguageSettingsStorage> newLanguageSettingsState;
|
LanguageSettingsStorage> newLanguageSettingsState;
|
||||||
|
|
||||||
|
@ -41,115 +31,4 @@ public class LanguageSettingsDelta {
|
||||||
newLanguageSettingsState = newState;
|
newLanguageSettingsState = newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME - this API is no good
|
|
||||||
public Set<IResource> getChangedResources(IProject project, ICConfigurationDescription cfgDescription) {
|
|
||||||
Set<IResource> resources = new HashSet<IResource>();
|
|
||||||
|
|
||||||
// Ordered collections
|
|
||||||
Collection<LanguageSettingsStorage> oldStateStorages = oldLanguageSettingsState.values();
|
|
||||||
Collection<LanguageSettingsStorage> newStateStorages = newLanguageSettingsState.values();
|
|
||||||
|
|
||||||
for (LanguageSettingsStorage lss : oldStateStorages) {
|
|
||||||
// Map<String, // languageId
|
|
||||||
// Map<String, // resource project path
|
|
||||||
// List<ICLanguageSettingEntry>>>
|
|
||||||
Map<String, Map<String, List<ICLanguageSettingEntry>>> mapInternal = lss.getMapInternal();
|
|
||||||
synchronized (mapInternal) {
|
|
||||||
for (Entry<String, Map<String, List<ICLanguageSettingEntry>>> entryLang : mapInternal.entrySet()) {
|
|
||||||
String langId = entryLang.getKey();
|
|
||||||
for (Entry<String, List<ICLanguageSettingEntry>> entryRc : entryLang.getValue().entrySet()) {
|
|
||||||
String rcName = entryRc.getKey();
|
|
||||||
IResource rc = (rcName != null) ? project.findMember(rcName) : project;
|
|
||||||
if (resources.contains(rc))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
List<ICLanguageSettingEntry> lsEntriesOld = entryRc.getValue();
|
|
||||||
List<ICLanguageSettingEntry> lsEntriesNew = getSettingEntries(newStateStorages, cfgDescription, rc, langId);
|
|
||||||
|
|
||||||
if (!lsEntriesNew.equals(lsEntriesOld) && !(lsEntriesOld==null && lsEntriesNew.size()==0)) {
|
|
||||||
resources.add(rc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (LanguageSettingsStorage lss : newStateStorages) {
|
|
||||||
// Map<String, // languageId
|
|
||||||
// Map<String, // resource project path
|
|
||||||
// List<ICLanguageSettingEntry>>>
|
|
||||||
Map<String, Map<String, List<ICLanguageSettingEntry>>> mapInternal = lss.getMapInternal();
|
|
||||||
synchronized (mapInternal) {
|
|
||||||
for (Entry<String, Map<String, List<ICLanguageSettingEntry>>> entryLang : mapInternal.entrySet()) {
|
|
||||||
String langId = entryLang.getKey();
|
|
||||||
for (Entry<String, List<ICLanguageSettingEntry>> entryRc : entryLang.getValue().entrySet()) {
|
|
||||||
String rcName = entryRc.getKey();
|
|
||||||
IResource rc = (rcName != null) ? project.findMember(rcName) : project;
|
|
||||||
if (resources.contains(rc))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
List<ICLanguageSettingEntry> lsEntriesNew = entryRc.getValue();
|
|
||||||
List<ICLanguageSettingEntry> lsEntriesOld = getSettingEntries(oldStateStorages, cfgDescription, rc, langId);
|
|
||||||
|
|
||||||
if (!lsEntriesOld.equals(lsEntriesNew) && !(lsEntriesNew==null && lsEntriesOld.size()==0)) {
|
|
||||||
resources.add(rc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return resources;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean checkBit(int flags, int bit) {
|
|
||||||
return (flags & bit) == bit;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<ICLanguageSettingEntry> getSettingEntries(Collection<LanguageSettingsStorage> stores, ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
|
||||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
|
||||||
List<String> alreadyAdded = new ArrayList<String>();
|
|
||||||
|
|
||||||
for (LanguageSettingsStorage store: stores) {
|
|
||||||
List<ICLanguageSettingEntry> providerEntries = getSettingEntriesUpResourceTree(store, cfgDescription, rc, languageId);
|
|
||||||
for (ICLanguageSettingEntry entry : providerEntries) {
|
|
||||||
if (entry!=null) {
|
|
||||||
String entryName = entry.getName();
|
|
||||||
// Only first entry is considered
|
|
||||||
// Entry flagged as "UNDEFINED" prevents adding entry with the same name down the line
|
|
||||||
if (!alreadyAdded.contains(entryName)) {
|
|
||||||
int flags = entry.getFlags();
|
|
||||||
if (!checkBit(flags, ICSettingEntry.UNDEFINED)) {
|
|
||||||
entries.add(entry);
|
|
||||||
}
|
|
||||||
alreadyAdded.add(entryName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<ICLanguageSettingEntry> getSettingEntriesUpResourceTree(LanguageSettingsStorage store, ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
|
||||||
Assert.isTrue( !(rc instanceof IWorkspaceRoot) );
|
|
||||||
if (store!=null) {
|
|
||||||
List<ICLanguageSettingEntry> entries = store.getSettingEntries(cfgDescription, rc, languageId);
|
|
||||||
if (entries!=null) {
|
|
||||||
return new ArrayList<ICLanguageSettingEntry>(entries);
|
|
||||||
}
|
|
||||||
if (rc!=null) {
|
|
||||||
IResource parentFolder = (rc instanceof IProject) ? null : rc.getParent();
|
|
||||||
if (parentFolder!=null) {
|
|
||||||
return getSettingEntriesUpResourceTree(store, cfgDescription, parentFolder, languageId);
|
|
||||||
}
|
|
||||||
// if out of parent resources - get default entries for the applicable language scope
|
|
||||||
entries = store.getSettingEntries(null, null, languageId);
|
|
||||||
if (entries!=null) {
|
|
||||||
return new ArrayList<ICLanguageSettingEntry>(entries);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ArrayList<ICLanguageSettingEntry>(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||||
import org.eclipse.cdt.internal.core.XmlUtil;
|
import org.eclipse.cdt.internal.core.XmlUtil;
|
||||||
import org.eclipse.cdt.internal.core.settings.model.CConfigurationSpecSettings;
|
import org.eclipse.cdt.internal.core.settings.model.CConfigurationSpecSettings;
|
||||||
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
|
|
||||||
import org.eclipse.cdt.internal.core.settings.model.IInternalCCfgInfo;
|
import org.eclipse.cdt.internal.core.settings.model.IInternalCCfgInfo;
|
||||||
import org.eclipse.core.filesystem.URIUtil;
|
import org.eclipse.core.filesystem.URIUtil;
|
||||||
import org.eclipse.core.resources.IContainer;
|
import org.eclipse.core.resources.IContainer;
|
||||||
|
@ -179,8 +178,6 @@ public class LanguageSettingsProvidersSerializer {
|
||||||
private String projectName = null;
|
private String projectName = null;
|
||||||
private Map<String /*cfg*/, LanguageSettingsDelta> deltaMap = new HashMap<String, LanguageSettingsDelta>();
|
private Map<String /*cfg*/, LanguageSettingsDelta> deltaMap = new HashMap<String, LanguageSettingsDelta>();
|
||||||
|
|
||||||
private IResource[] resources = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The act of creating event resets internal delta count in configuration state.
|
* The act of creating event resets internal delta count in configuration state.
|
||||||
* That implies that when the event is retrieved it must be fired or delta will go missing.
|
* That implies that when the event is retrieved it must be fired or delta will go missing.
|
||||||
|
@ -208,7 +205,6 @@ public class LanguageSettingsProvidersSerializer {
|
||||||
CCorePlugin.log(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, ss.getMessage(), new CoreException(ss)));
|
CCorePlugin.log(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, ss.getMessage(), new CoreException(ss)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,24 +213,7 @@ public class LanguageSettingsProvidersSerializer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getConfigurationDescriptionIds() {
|
public String[] getConfigurationDescriptionIds() {
|
||||||
String[] ids = deltaMap.keySet().toArray(new String[deltaMap.size()]);
|
return deltaMap.keySet().toArray(new String[deltaMap.size()]);
|
||||||
return ids;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IResource[] getResources(String cfgDescriptionId) {
|
|
||||||
if (resources == null) {
|
|
||||||
LanguageSettingsDelta delta = deltaMap.get(cfgDescriptionId);
|
|
||||||
if (delta == null) {
|
|
||||||
resources = new IResource[0];
|
|
||||||
} else {
|
|
||||||
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
|
|
||||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
|
||||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
|
||||||
resources = delta.getChangedResources(project, cfgDescription).toArray(new IResource[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return resources;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue