mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-17 21:25:58 +02:00
LanguageSettingsStorage as a public class
This commit is contained in:
parent
7250f46995
commit
57bd8abd27
11 changed files with 561 additions and 464 deletions
|
@ -16,6 +16,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
|
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
|
||||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsBroadcastingProvider;
|
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsBroadcastingProvider;
|
||||||
|
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsStorage;
|
||||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||||
import org.eclipse.cdt.core.settings.model.ICFileDescription;
|
import org.eclipse.cdt.core.settings.model.ICFileDescription;
|
||||||
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
|
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
|
||||||
|
@ -27,6 +28,9 @@ import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of language settings provider for CDT Managed Build System.
|
||||||
|
*/
|
||||||
public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsBroadcastingProvider {
|
public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsBroadcastingProvider {
|
||||||
@Override
|
@Override
|
||||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||||
|
@ -90,7 +94,6 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId,
|
public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId,
|
||||||
List<ICLanguageSettingEntry> entries) {
|
List<ICLanguageSettingEntry> entries) {
|
||||||
|
|
||||||
|
@ -123,4 +126,25 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LanguageSettingsStorage copyStorage() {
|
||||||
|
class PretendStorage extends LanguageSettingsStorage {
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public LanguageSettingsStorage clone() throws CloneNotSupportedException {
|
||||||
|
throw new CloneNotSupportedException();
|
||||||
|
// return this;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
// Note that this always triggers change event even if nothing changed in MBS
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new PretendStorage();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,17 +8,19 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Andrew Gvozdev - initial API and implementation
|
* Andrew Gvozdev - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.core.language.settings.providers;
|
package org.eclipse.cdt.core.language.settings.providers;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||||
|
import org.eclipse.cdt.internal.core.language.settings.providers.ILanguageSettingsChangeEvent;
|
||||||
|
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* This interface is to be implemented by providers which want to broadcast the changes in their setting entries
|
||||||
|
* by {@link LanguageSettingsProvidersSerializer#notifyLanguageSettingsChangeListeners(ILanguageSettingsChangeEvent)}
|
||||||
*/
|
*/
|
||||||
public interface ILanguageSettingsBroadcastingProvider extends ILanguageSettingsProvider {
|
public interface ILanguageSettingsBroadcastingProvider extends ILanguageSettingsProvider {
|
||||||
@Override
|
@Override
|
||||||
|
@ -28,5 +30,12 @@ public interface ILanguageSettingsBroadcastingProvider extends ILanguageSettings
|
||||||
@Override
|
@Override
|
||||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId);
|
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId);
|
||||||
|
|
||||||
public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List<ICLanguageSettingEntry> entries);
|
/**
|
||||||
|
* Return a copy of internal storage. This should be a deep copy/clone of the storage.
|
||||||
|
* It is used to calculate the delta and being kept in the last state object of configuration
|
||||||
|
* description to compare to a new state later.
|
||||||
|
*
|
||||||
|
* @return a copy of internal storage.
|
||||||
|
*/
|
||||||
|
public LanguageSettingsStorage copyStorage();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,29 @@ public interface ILanguageSettingsEditableProvider extends ILanguageSettingsBroa
|
||||||
public String getName();
|
public String getName();
|
||||||
@Override
|
@Override
|
||||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId);
|
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId);
|
||||||
@Override
|
|
||||||
|
/**
|
||||||
|
* Sets language settings entries for the provider.
|
||||||
|
*
|
||||||
|
* @param cfgDescription - configuration description.
|
||||||
|
* @param rc - resource such as file or folder.
|
||||||
|
* @param languageId - language id. If {@code null}, then entries are considered to be defined for
|
||||||
|
* any language.
|
||||||
|
* @param entries - language settings entries to set.
|
||||||
|
*/
|
||||||
public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List<ICLanguageSettingEntry> entries);
|
public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List<ICLanguageSettingEntry> entries);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shallow clone of the provider. "Shallow" is defined here as the exact copy except that
|
||||||
|
* the copy will have zero language settings entries.
|
||||||
|
*
|
||||||
|
* @return shallow copy of the provider.
|
||||||
|
* @throws CloneNotSupportedException in case {@link #clone()} throws the exception.
|
||||||
|
*/
|
||||||
public ILanguageSettingsEditableProvider cloneShallow() throws CloneNotSupportedException;
|
public ILanguageSettingsEditableProvider cloneShallow() throws CloneNotSupportedException;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see Object#clone()
|
||||||
|
*/
|
||||||
public ILanguageSettingsEditableProvider clone() throws CloneNotSupportedException;
|
public ILanguageSettingsEditableProvider clone() throws CloneNotSupportedException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ import java.util.List;
|
||||||
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
|
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
|
||||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsStorage;
|
|
||||||
import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages;
|
import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,11 @@ package org.eclipse.cdt.core.language.settings.providers;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||||
import org.eclipse.cdt.internal.core.XmlUtil;
|
import org.eclipse.cdt.internal.core.XmlUtil;
|
||||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsStorage;
|
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsSerializableStorage;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
@ -27,6 +28,8 @@ import org.w3c.dom.NodeList;
|
||||||
/**
|
/**
|
||||||
* This class is the base class for language settings providers able to serialize
|
* This class is the base class for language settings providers able to serialize
|
||||||
* into XML storage.
|
* into XML storage.
|
||||||
|
* Although this class has setter methods, it is not editable in UI by design.
|
||||||
|
* Implement {@link ILanguageSettingsEditableProvider} interface for that.
|
||||||
*
|
*
|
||||||
* TODO - more JavaDoc, info and hints about class hierarchy
|
* TODO - more JavaDoc, info and hints about class hierarchy
|
||||||
*
|
*
|
||||||
|
@ -46,7 +49,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr
|
||||||
/** Tells if language settings entries are persisted with the project or in workspace area while serializing. */
|
/** Tells if language settings entries are persisted with the project or in workspace area while serializing. */
|
||||||
private boolean storeEntriesInProjectArea = false;
|
private boolean storeEntriesInProjectArea = false;
|
||||||
|
|
||||||
private LanguageSettingsStorage fStorage = new LanguageSettingsStorage();
|
private LanguageSettingsSerializableStorage fStorage = new LanguageSettingsSerializableStorage();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor. This constructor has to be always followed with setting id and name of the provider.
|
* Default constructor. This constructor has to be always followed with setting id and name of the provider.
|
||||||
|
@ -158,7 +161,6 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr
|
||||||
* the language scope. See {@link #getLanguageScope()}
|
* the language scope. See {@link #getLanguageScope()}
|
||||||
* @param entries - language settings entries to set.
|
* @param entries - language settings entries to set.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List<ICLanguageSettingEntry> entries) {
|
public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List<ICLanguageSettingEntry> entries) {
|
||||||
String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null;
|
String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null;
|
||||||
fStorage.setSettingEntries(rcProjectPath, languageId, entries);
|
fStorage.setSettingEntries(rcProjectPath, languageId, entries);
|
||||||
|
@ -321,7 +323,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr
|
||||||
if (languageScope!=null)
|
if (languageScope!=null)
|
||||||
clone.languageScope = new ArrayList<String>(languageScope);
|
clone.languageScope = new ArrayList<String>(languageScope);
|
||||||
|
|
||||||
clone.fStorage = new LanguageSettingsStorage();
|
clone.fStorage = new LanguageSettingsSerializableStorage();
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +341,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr
|
||||||
@Override
|
@Override
|
||||||
protected LanguageSettingsSerializableProvider clone() throws CloneNotSupportedException {
|
protected LanguageSettingsSerializableProvider clone() throws CloneNotSupportedException {
|
||||||
LanguageSettingsSerializableProvider clone = cloneShallowInternal();
|
LanguageSettingsSerializableProvider clone = cloneShallowInternal();
|
||||||
clone.fStorage = fStorage.cloneStorage();
|
clone.fStorage = fStorage.clone();
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,10 +412,13 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* @noreference This method is not intended to be referenced by clients.
|
public LanguageSettingsStorage copyStorage() {
|
||||||
*/
|
try {
|
||||||
public LanguageSettingsStorage getStorageInternal() {
|
return fStorage.clone();
|
||||||
return fStorage;
|
} catch (CloneNotSupportedException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,234 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2011, 2011 Andrew Gvozdev 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
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Andrew Gvozdev - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.core.language.settings.providers;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
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.cdt.internal.core.parser.util.WeakHashSet;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
|
||||||
|
public class LanguageSettingsStorage implements Cloneable {
|
||||||
|
/**
|
||||||
|
* Storage to keep settings entries. Note that it is not necessary to keep configuration in the maps
|
||||||
|
* as the configuration is always the one provider belongs to.
|
||||||
|
*/
|
||||||
|
protected Map<String, // languageId
|
||||||
|
Map<String, // resource project path
|
||||||
|
List<ICLanguageSettingEntry>>> fStorage = new HashMap<String, Map<String, List<ICLanguageSettingEntry>>>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pool of LSE lists implemented as WeakHashSet. That allows to gain memory savings
|
||||||
|
* at the expense of CPU time. WeakHashSet handles garbage collection when a list is not
|
||||||
|
* referenced anywhere else. See JavaDoc {@link java.lang.ref.WeakReference} about weak reference objects.
|
||||||
|
*/
|
||||||
|
private static WeakHashSet<List<ICLanguageSettingEntry>> listPool = new WeakHashSet<List<ICLanguageSettingEntry>>() {
|
||||||
|
@Override
|
||||||
|
public synchronized List<ICLanguageSettingEntry> add(List<ICLanguageSettingEntry> list) {
|
||||||
|
return super.add(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
* <br> Note that this list is <b>unmodifiable</b>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||||
|
List<ICLanguageSettingEntry> entries = null;
|
||||||
|
Map<String, List<ICLanguageSettingEntry>> langMap = fStorage.get(languageId);
|
||||||
|
if (langMap!=null) {
|
||||||
|
String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null;
|
||||||
|
entries = langMap.get(rcProjectPath);
|
||||||
|
}
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some providers may collect entries in pretty much random order. For the purposes of
|
||||||
|
* predictability, UI usability and efficient storage the entries are sorted by kinds
|
||||||
|
* and secondary by name for kinds where the secondary order is not significant.
|
||||||
|
*
|
||||||
|
* @param entries - list of entries to sort.
|
||||||
|
* @return - sorted entries.
|
||||||
|
*/
|
||||||
|
private List<ICLanguageSettingEntry> sortEntries(List<ICLanguageSettingEntry> entries) {
|
||||||
|
List<ICLanguageSettingEntry> sortedEntries = new ArrayList<ICLanguageSettingEntry>(entries);
|
||||||
|
Collections.sort(sortedEntries, new Comparator<ICLanguageSettingEntry>(){
|
||||||
|
/**
|
||||||
|
* This comparator sorts by kinds first and the macros are sorted additionally by name.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int compare(ICLanguageSettingEntry entry0, ICLanguageSettingEntry entry1) {
|
||||||
|
int kind0 = entry0.getKind();
|
||||||
|
int kind1 = entry1.getKind();
|
||||||
|
if (kind0==ICSettingEntry.MACRO && kind1==ICSettingEntry.MACRO) {
|
||||||
|
return entry0.getName().compareTo(entry1.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return kind0 - kind1;
|
||||||
|
}});
|
||||||
|
|
||||||
|
return sortedEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void setSettingEntries(String rcProjectPath, String languageId, List<ICLanguageSettingEntry> entries) {
|
||||||
|
synchronized (fStorage) {
|
||||||
|
if (entries!=null) {
|
||||||
|
Map<String, List<ICLanguageSettingEntry>> langMap = fStorage.get(languageId);
|
||||||
|
if (langMap==null) {
|
||||||
|
langMap = new HashMap<String, List<ICLanguageSettingEntry>>();
|
||||||
|
fStorage.put(languageId, langMap);
|
||||||
|
}
|
||||||
|
List<ICLanguageSettingEntry> sortedEntries = getPooledList(sortEntries(entries), false);
|
||||||
|
langMap.put(rcProjectPath, sortedEntries);
|
||||||
|
} else {
|
||||||
|
// do not keep nulls in the tables
|
||||||
|
Map<String, List<ICLanguageSettingEntry>> langMap = fStorage.get(languageId);
|
||||||
|
if (langMap!=null) {
|
||||||
|
langMap.remove(rcProjectPath);
|
||||||
|
if (langMap.size()==0) {
|
||||||
|
fStorage.remove(languageId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@code true} if the provider does not keep any settings yet or {@code false} if there are some.
|
||||||
|
*/
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return fStorage.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear all the entries for all configurations, all resources and all languages.
|
||||||
|
*/
|
||||||
|
public void clear() {
|
||||||
|
synchronized (fStorage) {
|
||||||
|
fStorage.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the equal list of entries from the pool to conserve the memory.
|
||||||
|
*
|
||||||
|
* @param entries - list of entries to pool.
|
||||||
|
* @param copy - specify {@code true} to copy the list in order to prevent
|
||||||
|
* back-door modification on the original list changes.
|
||||||
|
* @return returns the list of entries from the pool.
|
||||||
|
*/
|
||||||
|
private static List<ICLanguageSettingEntry> getPooledList(List<ICLanguageSettingEntry> entries, boolean copy) {
|
||||||
|
if (entries == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
List<ICLanguageSettingEntry> pooledList = listPool.get(entries);
|
||||||
|
if (pooledList != null) {
|
||||||
|
return pooledList;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entries.size() == 0) {
|
||||||
|
return getPooledEmptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (copy) {
|
||||||
|
entries = new ArrayList<ICLanguageSettingEntry>(entries);
|
||||||
|
}
|
||||||
|
pooledList = Collections.unmodifiableList(entries);
|
||||||
|
return listPool.add(pooledList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the equal list of entries from the pool to conserve the memory.
|
||||||
|
*
|
||||||
|
* @param entries - list of entries to pool.
|
||||||
|
* @return returns the list of entries from the pool.
|
||||||
|
*/
|
||||||
|
public static List<ICLanguageSettingEntry> getPooledList(List<ICLanguageSettingEntry> entries) {
|
||||||
|
return getPooledList(entries, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the empty immutable list which is pooled. Use this call rather than creating
|
||||||
|
* new empty array to ensure that operator '==' can be used instead of deep equals().
|
||||||
|
*/
|
||||||
|
public static List<ICLanguageSettingEntry> getPooledEmptyList() {
|
||||||
|
List<ICLanguageSettingEntry> pooledEmptyList = Collections.emptyList();
|
||||||
|
return listPool.add(pooledEmptyList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clone storage for the entries. Copies references for lists of entries as a whole.
|
||||||
|
* Note that is OK as the lists kept in storage are unmodifiable.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public LanguageSettingsStorage clone() throws CloneNotSupportedException {
|
||||||
|
LanguageSettingsStorage storageClone = (LanguageSettingsStorage) super.clone();
|
||||||
|
storageClone.fStorage = new HashMap<String, Map<String, List<ICLanguageSettingEntry>>>();
|
||||||
|
synchronized (fStorage) {
|
||||||
|
Set<Entry<String, Map<String, List<ICLanguageSettingEntry>>>> entrySetLang = fStorage.entrySet();
|
||||||
|
for (Entry<String, Map<String, List<ICLanguageSettingEntry>>> entryLang : entrySetLang) {
|
||||||
|
String langId = entryLang.getKey();
|
||||||
|
Map<String, List<ICLanguageSettingEntry>> mapRc = entryLang.getValue();
|
||||||
|
Map<String, List<ICLanguageSettingEntry>> mapRcClone = new HashMap<String, List<ICLanguageSettingEntry>>();
|
||||||
|
Set<Entry<String, List<ICLanguageSettingEntry>>> entrySetRc = mapRc.entrySet();
|
||||||
|
for (Entry<String, List<ICLanguageSettingEntry>> entryRc : entrySetRc) {
|
||||||
|
String rcProjectPath = entryRc.getKey();
|
||||||
|
List<ICLanguageSettingEntry> lsEntries = entryRc.getValue();
|
||||||
|
// don't need to clone entries, they are from the LSE pool
|
||||||
|
mapRcClone.put(rcProjectPath, lsEntries);
|
||||||
|
}
|
||||||
|
storageClone.fStorage.put(langId, mapRcClone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return storageClone;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((fStorage == null) ? 0 : fStorage.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
LanguageSettingsStorage other = (LanguageSettingsStorage) obj;
|
||||||
|
if (fStorage == null) {
|
||||||
|
if (other.fStorage != null)
|
||||||
|
return false;
|
||||||
|
} else if (!fStorage.equals(other.fStorage))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -12,6 +12,8 @@ package org.eclipse.cdt.internal.core.language.settings.providers;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsStorage;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class currently is a placeholder holding old and new states.
|
* This class currently is a placeholder holding old and new states.
|
||||||
|
@ -21,10 +23,10 @@ public class LanguageSettingsDelta {
|
||||||
// maps need to be ordered by providers
|
// maps need to be ordered by providers
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private LinkedHashMap<String, // providerId
|
private LinkedHashMap<String, // providerId
|
||||||
LanguageSettingsStorage> oldLanguageSettingsState;
|
LanguageSettingsStorage> oldLanguageSettingsState;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private LinkedHashMap<String, // providerId
|
private LinkedHashMap<String, // providerId
|
||||||
LanguageSettingsStorage> newLanguageSettingsState;
|
LanguageSettingsStorage> newLanguageSettingsState;
|
||||||
|
|
||||||
public LanguageSettingsDelta(LinkedHashMap<String, LanguageSettingsStorage> oldState, LinkedHashMap<String, LanguageSettingsStorage> newState) {
|
public LanguageSettingsDelta(LinkedHashMap<String, LanguageSettingsStorage> oldState, LinkedHashMap<String, LanguageSettingsStorage> newState) {
|
||||||
oldLanguageSettingsState = oldState;
|
oldLanguageSettingsState = oldState;
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditabl
|
||||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider;
|
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider;
|
||||||
|
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsStorage;
|
||||||
import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport;
|
import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport;
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.LanguageManager;
|
import org.eclipse.cdt.core.model.LanguageManager;
|
||||||
|
@ -338,7 +339,7 @@ public class LanguageSettingsProvidersSerializer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<LanguageSettingsChangeEvent> createLanguageSettingsChangeEvents(List<LanguageSettingsSerializableProvider> serializableProviders) {
|
private static List<LanguageSettingsChangeEvent> createLanguageSettingsChangeEvents(List<LanguageSettingsSerializableProvider> serializableProviders) {
|
||||||
List<LanguageSettingsChangeEvent> events = new ArrayList<LanguageSettingsProvidersSerializer.LanguageSettingsChangeEvent>();
|
List<LanguageSettingsChangeEvent> events = new ArrayList<LanguageSettingsChangeEvent>();
|
||||||
|
|
||||||
List<String> serializableIds = new ArrayList<String>();
|
List<String> serializableIds = new ArrayList<String>();
|
||||||
for (LanguageSettingsSerializableProvider provider : serializableProviders) {
|
for (LanguageSettingsSerializableProvider provider : serializableProviders) {
|
||||||
|
|
|
@ -0,0 +1,225 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2011, 2011 Andrew Gvozdev 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
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Andrew Gvozdev - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.language.settings.providers;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsStorage;
|
||||||
|
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||||
|
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||||
|
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||||
|
import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer;
|
||||||
|
import org.eclipse.cdt.internal.core.XmlUtil;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
public class LanguageSettingsSerializableStorage extends LanguageSettingsStorage {
|
||||||
|
private static final String ELEM_LANGUAGE = "language"; //$NON-NLS-1$
|
||||||
|
private static final String ATTR_LANGUAGE_ID = "id"; //$NON-NLS-1$
|
||||||
|
private static final String ELEM_RESOURCE = "resource"; //$NON-NLS-1$
|
||||||
|
private static final String ATTR_PROJECT_PATH = "project-relative-path"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
private static final String ELEM_ENTRY = "entry"; //$NON-NLS-1$
|
||||||
|
private static final String ATTR_KIND = "kind"; //$NON-NLS-1$
|
||||||
|
private static final String ATTR_NAME = "name"; //$NON-NLS-1$
|
||||||
|
private static final String ATTR_VALUE = "value"; //$NON-NLS-1$
|
||||||
|
private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize the provider entries under parent XML element.
|
||||||
|
* @param elementProvider - element where to serialize the entries.
|
||||||
|
*/
|
||||||
|
public void serializeEntries(Element elementProvider) {
|
||||||
|
synchronized (fStorage) {
|
||||||
|
for (Entry<String, Map<String, List<ICLanguageSettingEntry>>> entryLang : fStorage.entrySet()) {
|
||||||
|
serializeLanguage(elementProvider, entryLang);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize the provider entries for a given language list.
|
||||||
|
*/
|
||||||
|
private void serializeLanguage(Element parentElement, Entry<String, Map<String, List<ICLanguageSettingEntry>>> entryLang) {
|
||||||
|
String langId = entryLang.getKey();
|
||||||
|
if (langId!=null) {
|
||||||
|
Element elementLanguage = XmlUtil.appendElement(parentElement, ELEM_LANGUAGE, new String[] {ATTR_LANGUAGE_ID, langId});
|
||||||
|
parentElement = elementLanguage;
|
||||||
|
}
|
||||||
|
for (Entry<String, List<ICLanguageSettingEntry>> entryRc : entryLang.getValue().entrySet()) {
|
||||||
|
serializeResource(parentElement, entryRc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize the provider entries for a given resource list.
|
||||||
|
*/
|
||||||
|
private void serializeResource(Element parentElement, Entry<String, List<ICLanguageSettingEntry>> entryRc) {
|
||||||
|
String rcProjectPath = entryRc.getKey();
|
||||||
|
if (rcProjectPath!=null) {
|
||||||
|
Element elementRc = XmlUtil.appendElement(parentElement, ELEM_RESOURCE, new String[] {ATTR_PROJECT_PATH, rcProjectPath});
|
||||||
|
parentElement = elementRc;
|
||||||
|
}
|
||||||
|
serializeSettingEntries(parentElement, entryRc.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize given settings entries.
|
||||||
|
*/
|
||||||
|
private void serializeSettingEntries(Element parentElement, List<ICLanguageSettingEntry> settingEntries) {
|
||||||
|
for (ICLanguageSettingEntry entry : settingEntries) {
|
||||||
|
Element elementSettingEntry = XmlUtil.appendElement(parentElement, ELEM_ENTRY, new String[] {
|
||||||
|
ATTR_KIND, LanguageSettingEntriesSerializer.kindToString(entry.getKind()),
|
||||||
|
ATTR_NAME, entry.getName(),
|
||||||
|
});
|
||||||
|
switch(entry.getKind()) {
|
||||||
|
case ICSettingEntry.MACRO:
|
||||||
|
elementSettingEntry.setAttribute(ATTR_VALUE, entry.getValue());
|
||||||
|
break;
|
||||||
|
// case ICLanguageSettingEntry.LIBRARY_FILE:
|
||||||
|
// // TODO: sourceAttachment fields may need to be covered
|
||||||
|
// break;
|
||||||
|
}
|
||||||
|
int flags = entry.getFlags();
|
||||||
|
if (flags!=0) {
|
||||||
|
// Element elementFlag =
|
||||||
|
XmlUtil.appendElement(elementSettingEntry, ELEM_FLAG, new String[] {
|
||||||
|
ATTR_VALUE, LanguageSettingEntriesSerializer.composeFlagsString(entry.getFlags())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load provider entries from XML provider element.
|
||||||
|
* @param providerNode - parent XML element <provider> where entries are defined.
|
||||||
|
*/
|
||||||
|
public void loadEntries(Element providerNode) {
|
||||||
|
List<ICLanguageSettingEntry> settings = new ArrayList<ICLanguageSettingEntry>();
|
||||||
|
NodeList nodes = providerNode.getChildNodes();
|
||||||
|
for (int i=0;i<nodes.getLength();i++) {
|
||||||
|
Node elementNode = nodes.item(i);
|
||||||
|
if(elementNode.getNodeType() != Node.ELEMENT_NODE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (ELEM_LANGUAGE.equals(elementNode.getNodeName())) {
|
||||||
|
loadLanguageElement(elementNode, null);
|
||||||
|
} else if (ELEM_RESOURCE.equals(elementNode.getNodeName())) {
|
||||||
|
loadResourceElement(elementNode, null, null);
|
||||||
|
} else if (ELEM_ENTRY.equals(elementNode.getNodeName())) {
|
||||||
|
ICLanguageSettingEntry entry = loadSettingEntry(elementNode);
|
||||||
|
if (entry!=null) {
|
||||||
|
settings.add(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// set settings
|
||||||
|
if (settings.size()>0) {
|
||||||
|
setSettingEntries(null, null, settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a setting entry from XML element.
|
||||||
|
*/
|
||||||
|
private ICLanguageSettingEntry loadSettingEntry(Node parentElement) {
|
||||||
|
String settingKind = XmlUtil.determineAttributeValue(parentElement, ATTR_KIND);
|
||||||
|
String settingName = XmlUtil.determineAttributeValue(parentElement, ATTR_NAME);
|
||||||
|
|
||||||
|
NodeList flagNodes = parentElement.getChildNodes();
|
||||||
|
int flags = 0;
|
||||||
|
for (int i=0;i<flagNodes.getLength();i++) {
|
||||||
|
Node flagNode = flagNodes.item(i);
|
||||||
|
if(flagNode.getNodeType() != Node.ELEMENT_NODE || !ELEM_FLAG.equals(flagNode.getNodeName()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String settingFlags = XmlUtil.determineAttributeValue(flagNode, ATTR_VALUE);
|
||||||
|
int bitFlag = LanguageSettingEntriesSerializer.composeFlags(settingFlags);
|
||||||
|
flags |= bitFlag;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
String settingValue = null;
|
||||||
|
int kind = LanguageSettingEntriesSerializer.stringToKind(settingKind);
|
||||||
|
if (kind == ICSettingEntry.MACRO)
|
||||||
|
settingValue = XmlUtil.determineAttributeValue(parentElement, ATTR_VALUE);
|
||||||
|
ICLanguageSettingEntry entry = (ICLanguageSettingEntry) CDataUtil.createEntry(kind, settingName, settingValue, null, flags);
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load entries defined in language element.
|
||||||
|
*/
|
||||||
|
private void loadLanguageElement(Node parentNode, String cfgId) {
|
||||||
|
String langId = XmlUtil.determineAttributeValue(parentNode, ATTR_LANGUAGE_ID);
|
||||||
|
if (langId.length()==0) {
|
||||||
|
langId=null;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ICLanguageSettingEntry> settings = new ArrayList<ICLanguageSettingEntry>();
|
||||||
|
NodeList nodes = parentNode.getChildNodes();
|
||||||
|
for (int i=0;i<nodes.getLength();i++) {
|
||||||
|
Node elementNode = nodes.item(i);
|
||||||
|
if(elementNode.getNodeType() != Node.ELEMENT_NODE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (ELEM_RESOURCE.equals(elementNode.getNodeName())) {
|
||||||
|
loadResourceElement(elementNode, cfgId, langId);
|
||||||
|
} else if (ELEM_ENTRY.equals(elementNode.getNodeName())) {
|
||||||
|
ICLanguageSettingEntry entry = loadSettingEntry(elementNode);
|
||||||
|
if (entry!=null) {
|
||||||
|
settings.add(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// set settings
|
||||||
|
if (settings.size()>0) {
|
||||||
|
setSettingEntries(null, langId, settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load entries defined in resource element.
|
||||||
|
*/
|
||||||
|
private void loadResourceElement(Node parentNode, String cfgId, String langId) {
|
||||||
|
String rcProjectPath = XmlUtil.determineAttributeValue(parentNode, ATTR_PROJECT_PATH);
|
||||||
|
|
||||||
|
List<ICLanguageSettingEntry> settings = new ArrayList<ICLanguageSettingEntry>();
|
||||||
|
NodeList nodes = parentNode.getChildNodes();
|
||||||
|
for (int i=0;i<nodes.getLength();i++) {
|
||||||
|
Node elementNode = nodes.item(i);
|
||||||
|
if(elementNode.getNodeType() != Node.ELEMENT_NODE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (ELEM_ENTRY.equals(elementNode.getNodeName())) {
|
||||||
|
ICLanguageSettingEntry entry = loadSettingEntry(elementNode);
|
||||||
|
if (entry!=null) {
|
||||||
|
settings.add(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set settings
|
||||||
|
if (settings.size()>0) {
|
||||||
|
setSettingEntries(rcProjectPath, langId, settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LanguageSettingsSerializableStorage clone() throws CloneNotSupportedException {
|
||||||
|
return (LanguageSettingsSerializableStorage) super.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,419 +0,0 @@
|
||||||
package org.eclipse.cdt.internal.core.language.settings.providers;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
|
||||||
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.cdt.core.settings.model.util.CDataUtil;
|
|
||||||
import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer;
|
|
||||||
import org.eclipse.cdt.internal.core.XmlUtil;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.util.WeakHashSet;
|
|
||||||
import org.eclipse.core.resources.IResource;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
public class LanguageSettingsStorage {
|
|
||||||
private static final String ELEM_LANGUAGE = "language"; //$NON-NLS-1$
|
|
||||||
private static final String ATTR_LANGUAGE_ID = "id"; //$NON-NLS-1$
|
|
||||||
private static final String ELEM_RESOURCE = "resource"; //$NON-NLS-1$
|
|
||||||
private static final String ATTR_PROJECT_PATH = "project-relative-path"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
private static final String ELEM_ENTRY = "entry"; //$NON-NLS-1$
|
|
||||||
private static final String ATTR_KIND = "kind"; //$NON-NLS-1$
|
|
||||||
private static final String ATTR_NAME = "name"; //$NON-NLS-1$
|
|
||||||
private static final String ATTR_VALUE = "value"; //$NON-NLS-1$
|
|
||||||
private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Storage to keep settings entries. Note that it is not necessary to keep configuration in the maps
|
|
||||||
* as the configuration is always the one provider belongs to.
|
|
||||||
*/
|
|
||||||
private Map<String, // languageId
|
|
||||||
Map<String, // resource project path
|
|
||||||
List<ICLanguageSettingEntry>>> fStorage = new HashMap<String, Map<String, List<ICLanguageSettingEntry>>>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pool of LSE lists implemented as WeakHashSet. That allows to gain memory savings
|
|
||||||
* at the expense of CPU time. WeakHashSet handles garbage collection when a list is not
|
|
||||||
* referenced anywhere else. See JavaDoc {@link java.lang.ref.WeakReference} about weak reference objects.
|
|
||||||
*/
|
|
||||||
private static WeakHashSet<List<ICLanguageSettingEntry>> listPool = new WeakHashSet<List<ICLanguageSettingEntry>>() {
|
|
||||||
@Override
|
|
||||||
public synchronized List<ICLanguageSettingEntry> add(List<ICLanguageSettingEntry> list) {
|
|
||||||
return super.add(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
* <br> Note that this list is <b>unmodifiable</b>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
|
||||||
List<ICLanguageSettingEntry> entries = null;
|
|
||||||
Map<String, List<ICLanguageSettingEntry>> langMap = fStorage.get(languageId);
|
|
||||||
if (langMap!=null) {
|
|
||||||
String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null;
|
|
||||||
entries = langMap.get(rcProjectPath);
|
|
||||||
}
|
|
||||||
return entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Some providers may collect entries in pretty much random order. For the purposes of
|
|
||||||
* predictability, UI usability and efficient storage the entries are sorted by kinds
|
|
||||||
* and secondary by name for kinds where the secondary order is not significant.
|
|
||||||
*
|
|
||||||
* @param entries - list of entries to sort.
|
|
||||||
* @return - sorted entries.
|
|
||||||
*/
|
|
||||||
private List<ICLanguageSettingEntry> sortEntries(List<ICLanguageSettingEntry> entries) {
|
|
||||||
List<ICLanguageSettingEntry> sortedEntries = new ArrayList<ICLanguageSettingEntry>(entries);
|
|
||||||
Collections.sort(sortedEntries, new Comparator<ICLanguageSettingEntry>(){
|
|
||||||
/**
|
|
||||||
* This comparator sorts by kinds first and the macros are sorted additionally by name.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int compare(ICLanguageSettingEntry entry0, ICLanguageSettingEntry entry1) {
|
|
||||||
int kind0 = entry0.getKind();
|
|
||||||
int kind1 = entry1.getKind();
|
|
||||||
if (kind0==ICSettingEntry.MACRO && kind1==ICSettingEntry.MACRO) {
|
|
||||||
return entry0.getName().compareTo(entry1.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
return kind0 - kind1;
|
|
||||||
}});
|
|
||||||
|
|
||||||
return sortedEntries;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void setSettingEntries(String rcProjectPath, String languageId, List<ICLanguageSettingEntry> entries) {
|
|
||||||
synchronized (fStorage) {
|
|
||||||
if (entries!=null) {
|
|
||||||
Map<String, List<ICLanguageSettingEntry>> langMap = fStorage.get(languageId);
|
|
||||||
if (langMap==null) {
|
|
||||||
langMap = new HashMap<String, List<ICLanguageSettingEntry>>();
|
|
||||||
fStorage.put(languageId, langMap);
|
|
||||||
}
|
|
||||||
List<ICLanguageSettingEntry> sortedEntries = getPooledList(sortEntries(entries), false);
|
|
||||||
langMap.put(rcProjectPath, sortedEntries);
|
|
||||||
} else {
|
|
||||||
// do not keep nulls in the tables
|
|
||||||
Map<String, List<ICLanguageSettingEntry>> langMap = fStorage.get(languageId);
|
|
||||||
if (langMap!=null) {
|
|
||||||
langMap.remove(rcProjectPath);
|
|
||||||
if (langMap.size()==0) {
|
|
||||||
fStorage.remove(languageId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {@code true} if the provider does not keep any settings yet or {@code false} if there are some.
|
|
||||||
*/
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return fStorage.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear all the entries for all configurations, all resources and all languages.
|
|
||||||
*/
|
|
||||||
public void clear() {
|
|
||||||
synchronized (fStorage) {
|
|
||||||
fStorage.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serialize the provider entries under parent XML element.
|
|
||||||
* @param elementProvider - element where to serialize the entries.
|
|
||||||
*/
|
|
||||||
public void serializeEntries(Element elementProvider) {
|
|
||||||
synchronized (fStorage) {
|
|
||||||
for (Entry<String, Map<String, List<ICLanguageSettingEntry>>> entryLang : fStorage.entrySet()) {
|
|
||||||
serializeLanguage(elementProvider, entryLang);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serialize the provider entries for a given language list.
|
|
||||||
*/
|
|
||||||
private void serializeLanguage(Element parentElement, Entry<String, Map<String, List<ICLanguageSettingEntry>>> entryLang) {
|
|
||||||
String langId = entryLang.getKey();
|
|
||||||
if (langId!=null) {
|
|
||||||
Element elementLanguage = XmlUtil.appendElement(parentElement, ELEM_LANGUAGE, new String[] {ATTR_LANGUAGE_ID, langId});
|
|
||||||
parentElement = elementLanguage;
|
|
||||||
}
|
|
||||||
for (Entry<String, List<ICLanguageSettingEntry>> entryRc : entryLang.getValue().entrySet()) {
|
|
||||||
serializeResource(parentElement, entryRc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serialize the provider entries for a given resource list.
|
|
||||||
*/
|
|
||||||
private void serializeResource(Element parentElement, Entry<String, List<ICLanguageSettingEntry>> entryRc) {
|
|
||||||
String rcProjectPath = entryRc.getKey();
|
|
||||||
if (rcProjectPath!=null) {
|
|
||||||
Element elementRc = XmlUtil.appendElement(parentElement, ELEM_RESOURCE, new String[] {ATTR_PROJECT_PATH, rcProjectPath});
|
|
||||||
parentElement = elementRc;
|
|
||||||
}
|
|
||||||
serializeSettingEntries(parentElement, entryRc.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serialize given settings entries.
|
|
||||||
*/
|
|
||||||
private void serializeSettingEntries(Element parentElement, List<ICLanguageSettingEntry> settingEntries) {
|
|
||||||
for (ICLanguageSettingEntry entry : settingEntries) {
|
|
||||||
Element elementSettingEntry = XmlUtil.appendElement(parentElement, ELEM_ENTRY, new String[] {
|
|
||||||
ATTR_KIND, LanguageSettingEntriesSerializer.kindToString(entry.getKind()),
|
|
||||||
ATTR_NAME, entry.getName(),
|
|
||||||
});
|
|
||||||
switch(entry.getKind()) {
|
|
||||||
case ICSettingEntry.MACRO:
|
|
||||||
elementSettingEntry.setAttribute(ATTR_VALUE, entry.getValue());
|
|
||||||
break;
|
|
||||||
// case ICLanguageSettingEntry.LIBRARY_FILE:
|
|
||||||
// // TODO: sourceAttachment fields may need to be covered
|
|
||||||
// break;
|
|
||||||
}
|
|
||||||
int flags = entry.getFlags();
|
|
||||||
if (flags!=0) {
|
|
||||||
// Element elementFlag =
|
|
||||||
XmlUtil.appendElement(elementSettingEntry, ELEM_FLAG, new String[] {
|
|
||||||
ATTR_VALUE, LanguageSettingEntriesSerializer.composeFlagsString(entry.getFlags())
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load provider entries from XML provider element.
|
|
||||||
* @param providerNode - parent XML element <provider> where entries are defined.
|
|
||||||
*/
|
|
||||||
public void loadEntries(Element providerNode) {
|
|
||||||
List<ICLanguageSettingEntry> settings = new ArrayList<ICLanguageSettingEntry>();
|
|
||||||
NodeList nodes = providerNode.getChildNodes();
|
|
||||||
for (int i=0;i<nodes.getLength();i++) {
|
|
||||||
Node elementNode = nodes.item(i);
|
|
||||||
if(elementNode.getNodeType() != Node.ELEMENT_NODE)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (ELEM_LANGUAGE.equals(elementNode.getNodeName())) {
|
|
||||||
loadLanguageElement(elementNode, null);
|
|
||||||
} else if (ELEM_RESOURCE.equals(elementNode.getNodeName())) {
|
|
||||||
loadResourceElement(elementNode, null, null);
|
|
||||||
} else if (ELEM_ENTRY.equals(elementNode.getNodeName())) {
|
|
||||||
ICLanguageSettingEntry entry = loadSettingEntry(elementNode);
|
|
||||||
if (entry!=null) {
|
|
||||||
settings.add(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// set settings
|
|
||||||
if (settings.size()>0) {
|
|
||||||
setSettingEntries(null, null, settings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load a setting entry from XML element.
|
|
||||||
*/
|
|
||||||
private ICLanguageSettingEntry loadSettingEntry(Node parentElement) {
|
|
||||||
String settingKind = XmlUtil.determineAttributeValue(parentElement, ATTR_KIND);
|
|
||||||
String settingName = XmlUtil.determineAttributeValue(parentElement, ATTR_NAME);
|
|
||||||
|
|
||||||
NodeList flagNodes = parentElement.getChildNodes();
|
|
||||||
int flags = 0;
|
|
||||||
for (int i=0;i<flagNodes.getLength();i++) {
|
|
||||||
Node flagNode = flagNodes.item(i);
|
|
||||||
if(flagNode.getNodeType() != Node.ELEMENT_NODE || !ELEM_FLAG.equals(flagNode.getNodeName()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
String settingFlags = XmlUtil.determineAttributeValue(flagNode, ATTR_VALUE);
|
|
||||||
int bitFlag = LanguageSettingEntriesSerializer.composeFlags(settingFlags);
|
|
||||||
flags |= bitFlag;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
String settingValue = null;
|
|
||||||
int kind = LanguageSettingEntriesSerializer.stringToKind(settingKind);
|
|
||||||
if (kind == ICSettingEntry.MACRO)
|
|
||||||
settingValue = XmlUtil.determineAttributeValue(parentElement, ATTR_VALUE);
|
|
||||||
ICLanguageSettingEntry entry = (ICLanguageSettingEntry) CDataUtil.createEntry(kind, settingName, settingValue, null, flags);
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load entries defined in language element.
|
|
||||||
*/
|
|
||||||
private void loadLanguageElement(Node parentNode, String cfgId) {
|
|
||||||
String langId = XmlUtil.determineAttributeValue(parentNode, ATTR_LANGUAGE_ID);
|
|
||||||
if (langId.length()==0) {
|
|
||||||
langId=null;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ICLanguageSettingEntry> settings = new ArrayList<ICLanguageSettingEntry>();
|
|
||||||
NodeList nodes = parentNode.getChildNodes();
|
|
||||||
for (int i=0;i<nodes.getLength();i++) {
|
|
||||||
Node elementNode = nodes.item(i);
|
|
||||||
if(elementNode.getNodeType() != Node.ELEMENT_NODE)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (ELEM_RESOURCE.equals(elementNode.getNodeName())) {
|
|
||||||
loadResourceElement(elementNode, cfgId, langId);
|
|
||||||
} else if (ELEM_ENTRY.equals(elementNode.getNodeName())) {
|
|
||||||
ICLanguageSettingEntry entry = loadSettingEntry(elementNode);
|
|
||||||
if (entry!=null) {
|
|
||||||
settings.add(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// set settings
|
|
||||||
if (settings.size()>0) {
|
|
||||||
setSettingEntries(null, langId, settings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load entries defined in resource element.
|
|
||||||
*/
|
|
||||||
private void loadResourceElement(Node parentNode, String cfgId, String langId) {
|
|
||||||
String rcProjectPath = XmlUtil.determineAttributeValue(parentNode, ATTR_PROJECT_PATH);
|
|
||||||
|
|
||||||
List<ICLanguageSettingEntry> settings = new ArrayList<ICLanguageSettingEntry>();
|
|
||||||
NodeList nodes = parentNode.getChildNodes();
|
|
||||||
for (int i=0;i<nodes.getLength();i++) {
|
|
||||||
Node elementNode = nodes.item(i);
|
|
||||||
if(elementNode.getNodeType() != Node.ELEMENT_NODE)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (ELEM_ENTRY.equals(elementNode.getNodeName())) {
|
|
||||||
ICLanguageSettingEntry entry = loadSettingEntry(elementNode);
|
|
||||||
if (entry!=null) {
|
|
||||||
settings.add(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set settings
|
|
||||||
if (settings.size()>0) {
|
|
||||||
setSettingEntries(rcProjectPath, langId, settings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the equal list of entries from the pool to conserve the memory.
|
|
||||||
*
|
|
||||||
* @param entries - list of entries to pool.
|
|
||||||
* @param copy - specify {@code true} to copy the list in order to prevent
|
|
||||||
* back-door modification on the original list changes.
|
|
||||||
* @return returns the list of entries from the pool.
|
|
||||||
*/
|
|
||||||
private static List<ICLanguageSettingEntry> getPooledList(List<ICLanguageSettingEntry> entries, boolean copy) {
|
|
||||||
if (entries == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
List<ICLanguageSettingEntry> pooledList = listPool.get(entries);
|
|
||||||
if (pooledList != null) {
|
|
||||||
return pooledList;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entries.size() == 0) {
|
|
||||||
return getPooledEmptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (copy) {
|
|
||||||
entries = new ArrayList<ICLanguageSettingEntry>(entries);
|
|
||||||
}
|
|
||||||
pooledList = Collections.unmodifiableList(entries);
|
|
||||||
return listPool.add(pooledList);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the equal list of entries from the pool to conserve the memory.
|
|
||||||
*
|
|
||||||
* @param entries - list of entries to pool.
|
|
||||||
* @return returns the list of entries from the pool.
|
|
||||||
*/
|
|
||||||
public static List<ICLanguageSettingEntry> getPooledList(List<ICLanguageSettingEntry> entries) {
|
|
||||||
return getPooledList(entries, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the empty immutable list which is pooled. Use this call rather than creating
|
|
||||||
* new empty array to ensure that operator '==' can be used instead of deep equals().
|
|
||||||
*/
|
|
||||||
public static List<ICLanguageSettingEntry> getPooledEmptyList() {
|
|
||||||
List<ICLanguageSettingEntry> pooledEmptyList = Collections.emptyList();
|
|
||||||
return listPool.add(pooledEmptyList);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clone storage for the entries. Copies references for lists of entries as a whole.
|
|
||||||
* Note that is OK as the lists kept in storage are unmodifiable.
|
|
||||||
*/
|
|
||||||
public LanguageSettingsStorage cloneStorage() {
|
|
||||||
LanguageSettingsStorage storageClone = new LanguageSettingsStorage();
|
|
||||||
synchronized (fStorage) {
|
|
||||||
Set<Entry<String, Map<String, List<ICLanguageSettingEntry>>>> entrySetLang = fStorage.entrySet();
|
|
||||||
for (Entry<String, Map<String, List<ICLanguageSettingEntry>>> entryLang : entrySetLang) {
|
|
||||||
String langId = entryLang.getKey();
|
|
||||||
Map<String, List<ICLanguageSettingEntry>> mapRc = entryLang.getValue();
|
|
||||||
Map<String, List<ICLanguageSettingEntry>> mapRcClone = new HashMap<String, List<ICLanguageSettingEntry>>();
|
|
||||||
Set<Entry<String, List<ICLanguageSettingEntry>>> entrySetRc = mapRc.entrySet();
|
|
||||||
for (Entry<String, List<ICLanguageSettingEntry>> entryRc : entrySetRc) {
|
|
||||||
String rcProjectPath = entryRc.getKey();
|
|
||||||
List<ICLanguageSettingEntry> lsEntries = entryRc.getValue();
|
|
||||||
// don't need to clone entries, they are from the LSE pool
|
|
||||||
mapRcClone.put(rcProjectPath, lsEntries);
|
|
||||||
}
|
|
||||||
storageClone.fStorage.put(langId, mapRcClone);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return storageClone;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((fStorage == null) ? 0 : fStorage.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (obj == null)
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
LanguageSettingsStorage other = (LanguageSettingsStorage) obj;
|
|
||||||
if (fStorage == null) {
|
|
||||||
if (other.fStorage != null)
|
|
||||||
return false;
|
|
||||||
} else if (!fStorage.equals(other.fStorage))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -23,9 +23,10 @@ import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsBroadcastingProvider;
|
||||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider;
|
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsStorage;
|
||||||
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
||||||
import org.eclipse.cdt.core.settings.model.ICBuildSetting;
|
import org.eclipse.cdt.core.settings.model.ICBuildSetting;
|
||||||
import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference;
|
import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference;
|
||||||
|
@ -45,7 +46,6 @@ import org.eclipse.cdt.internal.core.cdtvariables.StorableCdtVariables;
|
||||||
import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager;
|
import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager;
|
||||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsDelta;
|
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsDelta;
|
||||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsStorage;
|
|
||||||
import org.eclipse.cdt.utils.envvar.StorableEnvironment;
|
import org.eclipse.cdt.utils.envvar.StorableEnvironment;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.QualifiedName;
|
import org.eclipse.core.runtime.QualifiedName;
|
||||||
|
@ -196,8 +196,12 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
|
||||||
|
|
||||||
fLanguageSettingsProviders = LanguageSettingsProvidersSerializer.cloneProviders(base.getLanguageSettingProviders());
|
fLanguageSettingsProviders = LanguageSettingsProvidersSerializer.cloneProviders(base.getLanguageSettingProviders());
|
||||||
for (String providerId : base.lspPersistedState.keySet()) {
|
for (String providerId : base.lspPersistedState.keySet()) {
|
||||||
LanguageSettingsStorage clone = base.lspPersistedState.get(providerId).cloneStorage();
|
try {
|
||||||
lspPersistedState.put(providerId, clone);
|
LanguageSettingsStorage clone = base.lspPersistedState.get(providerId).clone();
|
||||||
|
lspPersistedState.put(providerId, clone);
|
||||||
|
} catch (CloneNotSupportedException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1035,29 +1039,22 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
|
||||||
*/
|
*/
|
||||||
public LanguageSettingsDelta dropDelta() {
|
public LanguageSettingsDelta dropDelta() {
|
||||||
LanguageSettingsDelta languageSettingsDelta = null;
|
LanguageSettingsDelta languageSettingsDelta = null;
|
||||||
// newState gets shallow map first
|
LinkedHashMap<String, LanguageSettingsStorage> newState = new LinkedHashMap<String, LanguageSettingsStorage>();
|
||||||
LinkedHashMap<String, LanguageSettingsStorage> newStateShallow = new LinkedHashMap<String, LanguageSettingsStorage>();
|
|
||||||
for (ILanguageSettingsProvider provider : fLanguageSettingsProviders) {
|
for (ILanguageSettingsProvider provider : fLanguageSettingsProviders) {
|
||||||
if (LanguageSettingsManager.isWorkspaceProvider(provider)) {
|
if (LanguageSettingsManager.isWorkspaceProvider(provider)) {
|
||||||
provider = LanguageSettingsManager.getRawProvider(provider);
|
provider = LanguageSettingsManager.getRawProvider(provider);
|
||||||
}
|
}
|
||||||
if (provider instanceof LanguageSettingsSerializableProvider) {
|
if (provider instanceof ILanguageSettingsBroadcastingProvider) {
|
||||||
LanguageSettingsStorage store = ((LanguageSettingsSerializableProvider) provider).getStorageInternal();
|
LanguageSettingsStorage store = ((ILanguageSettingsBroadcastingProvider) provider).copyStorage();
|
||||||
if (!store.isEmpty()) {
|
// avoid triggering event if empty provider was added
|
||||||
newStateShallow.put(provider.getId(), store);
|
if (store != null && !store.isEmpty()) {
|
||||||
|
newState.put(provider.getId(), store);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!newStateShallow.equals(lspPersistedState)) {
|
if (!newState.equals(lspPersistedState)) {
|
||||||
// do deep copy if the state needs to be saved
|
languageSettingsDelta = new LanguageSettingsDelta(lspPersistedState, newState);
|
||||||
LinkedHashMap<String, LanguageSettingsStorage> newStateDeep = new LinkedHashMap<String, LanguageSettingsStorage>();
|
lspPersistedState = newState;
|
||||||
for (Entry<String, LanguageSettingsStorage> entry : newStateShallow.entrySet()) {
|
|
||||||
String providerId = entry.getKey();
|
|
||||||
LanguageSettingsStorage store = entry.getValue();
|
|
||||||
newStateDeep.put(providerId, store.cloneStorage());
|
|
||||||
}
|
|
||||||
languageSettingsDelta = new LanguageSettingsDelta(lspPersistedState, newStateDeep);
|
|
||||||
lspPersistedState = newStateDeep;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return languageSettingsDelta;
|
return languageSettingsDelta;
|
||||||
|
|
Loading…
Add table
Reference in a new issue