mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 14:15:23 +02:00
Using of pooled list refined
This commit is contained in:
parent
d0407361a8
commit
e95e3a02b7
4 changed files with 178 additions and 118 deletions
|
@ -1,12 +1,12 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) and others.
|
||||
* Copyright (c) 2009, 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 (Quoin Inc.) - initial API and implementation
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
@ -18,7 +18,6 @@ import java.util.List;
|
|||
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
/**
|
||||
|
@ -131,6 +130,7 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas
|
|||
* @param languageId - language id. If {@code null}, then entries defined for
|
||||
* the language scope are returned. See {@link #getLanguageScope()}
|
||||
*/
|
||||
@Override
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
if (languageScope==null) {
|
||||
if (entries==null)
|
||||
|
|
|
@ -70,9 +70,9 @@ public class LanguageSettingsProvidersSerializer {
|
|||
private static final String ELEM_CONFIGURATION = "configuration"; //$NON-NLS-1$
|
||||
private static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$
|
||||
private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; //$NON-NLS-1$
|
||||
|
||||
|
||||
private static ILock serializingLock = Job.getJobManager().newLock();
|
||||
|
||||
|
||||
/** Cache of globally available providers to be consumed by calling clients */
|
||||
private static Map<String, ILanguageSettingsProvider> rawGlobalWorkspaceProviders = new HashMap<String, ILanguageSettingsProvider>();
|
||||
private static Map<String, ILanguageSettingsProvider> globalWorkspaceProviders = new HashMap<String, ILanguageSettingsProvider>();
|
||||
|
@ -82,7 +82,7 @@ public class LanguageSettingsProvidersSerializer {
|
|||
private static class ListenerAssociation {
|
||||
private ICListenerRegisterer listener;
|
||||
private ICConfigurationDescription cfgDescription;
|
||||
|
||||
|
||||
public ListenerAssociation(ICListenerRegisterer li, ICConfigurationDescription cfgd) {
|
||||
listener = li;
|
||||
cfgDescription = cfgd;
|
||||
|
@ -149,7 +149,7 @@ public class LanguageSettingsProvidersSerializer {
|
|||
private int getProjectCount() {
|
||||
return projectCount;
|
||||
}
|
||||
|
||||
|
||||
private synchronized int incrementProjectCount() {
|
||||
projectCount++;
|
||||
return projectCount;
|
||||
|
@ -159,7 +159,7 @@ public class LanguageSettingsProvidersSerializer {
|
|||
projectCount--;
|
||||
return projectCount;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerListener(ICConfigurationDescription cfgDescription) {
|
||||
// keep in mind that rawProvider can change
|
||||
|
@ -186,7 +186,7 @@ public class LanguageSettingsProvidersSerializer {
|
|||
private static class LanguageSettingsChangeEvent implements ILanguageSettingsChangeEvent {
|
||||
private String projectName = null;
|
||||
private Map<String /*cfg*/, LanguageSettingsDelta> deltaMap = new HashMap<String, LanguageSettingsDelta>();
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -315,7 +315,7 @@ public class LanguageSettingsProvidersSerializer {
|
|||
|
||||
List<ICListenerRegisterer> oldListeners = selectListeners(rawGlobalWorkspaceProviders.values());
|
||||
List<ICListenerRegisterer> newListeners = selectListeners(rawProviders);
|
||||
|
||||
|
||||
for (ICListenerRegisterer oldListener : oldListeners) {
|
||||
if (!isObjectInTheList(newListeners, oldListener)) {
|
||||
LanguageSettingsWorkspaceProvider wspProvider = (LanguageSettingsWorkspaceProvider) globalWorkspaceProviders.get(((ILanguageSettingsProvider)oldListener).getId());
|
||||
|
@ -324,7 +324,7 @@ public class LanguageSettingsProvidersSerializer {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (ICListenerRegisterer newListener : newListeners) {
|
||||
if (!isObjectInTheList(oldListeners, newListener)) {
|
||||
LanguageSettingsWorkspaceProvider wspProvider = (LanguageSettingsWorkspaceProvider) globalWorkspaceProviders.get(((ILanguageSettingsProvider)newListener).getId());
|
||||
|
@ -333,13 +333,13 @@ public class LanguageSettingsProvidersSerializer {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rawGlobalWorkspaceProviders = rawWorkspaceProviders;
|
||||
}
|
||||
|
||||
private static List<LanguageSettingsChangeEvent> createLanguageLettingsChangeEvents(List<LanguageSettingsSerializable> serializableProviders) {
|
||||
List<LanguageSettingsChangeEvent> events = new ArrayList<LanguageSettingsProvidersSerializer.LanguageSettingsChangeEvent>();
|
||||
|
||||
|
||||
List<String> serializableIds = new ArrayList<String>();
|
||||
for (LanguageSettingsSerializable provider : serializableProviders) {
|
||||
serializableIds.add(provider.getId());
|
||||
|
@ -366,15 +366,15 @@ projects:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
public static void serializeLanguageSettingsWorkspace() throws CoreException {
|
||||
LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace()");
|
||||
|
||||
|
||||
URI uriStoreWsp = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
|
||||
List<LanguageSettingsSerializable> serializableWorkspaceProviders = new ArrayList<LanguageSettingsSerializable>();
|
||||
for (ILanguageSettingsProvider provider : rawGlobalWorkspaceProviders.values()) {
|
||||
|
@ -402,11 +402,11 @@ projects:
|
|||
Document doc = XmlUtil.newDocument();
|
||||
Element rootElement = XmlUtil.appendElement(doc, ELEM_PLUGIN);
|
||||
Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, new String[] {ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID});
|
||||
|
||||
|
||||
for (LanguageSettingsSerializable provider : serializableWorkspaceProviders) {
|
||||
provider.serialize(elementExtension);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
serializingLock.acquire();
|
||||
XmlUtil.serializeXml(doc, uriStoreWsp);
|
||||
|
@ -537,7 +537,7 @@ projects:
|
|||
public static void serializeLanguageSettings(ICProjectDescription prjDescription) throws CoreException {
|
||||
IProject project = prjDescription.getProject();
|
||||
LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettings() for " + project);
|
||||
|
||||
|
||||
try {
|
||||
// Document to store in project area
|
||||
Document docStorePrj = XmlUtil.newDocument();
|
||||
|
@ -548,7 +548,7 @@ projects:
|
|||
|
||||
// The project store should not be absent. Absent store means legacy project, not 0 providers.
|
||||
IFile fileStorePrj = getStoreInProjectArea(project);
|
||||
|
||||
|
||||
URI uriStoreWsp = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
|
||||
LanguageSettingsChangeEvent event = null;
|
||||
|
||||
|
@ -567,7 +567,7 @@ projects:
|
|||
} else {
|
||||
new java.io.File(uriStoreWsp).delete();
|
||||
}
|
||||
|
||||
|
||||
// manufacture the event only if serialization was successful
|
||||
event = new LanguageSettingsChangeEvent(prjDescription);
|
||||
} finally {
|
||||
|
@ -884,7 +884,7 @@ projects:
|
|||
}
|
||||
return listeners;
|
||||
}
|
||||
|
||||
|
||||
private static List<ICListenerRegisterer> selectListeners(Collection<ILanguageSettingsProvider> values) {
|
||||
List<ICListenerRegisterer> listeners = new ArrayList<ICListenerRegisterer>();
|
||||
for (ILanguageSettingsProvider provider : values) {
|
||||
|
@ -913,7 +913,7 @@ projects:
|
|||
}
|
||||
return associations;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unregister listeners which are not used anymore and register new listeners.
|
||||
* The method is used when project description is applied to workspace.
|
||||
|
@ -928,10 +928,10 @@ projects:
|
|||
|
||||
assertConsistency(oldPrjDescription); // TODO - remove me
|
||||
assertConsistency(newPrjDescription); // TODO - remove me
|
||||
|
||||
|
||||
List<ICListenerRegisterer> oldListeners = getListeners(oldPrjDescription);
|
||||
List<ListenerAssociation> newAssociations = getListenersAssociations(newPrjDescription);
|
||||
|
||||
|
||||
for (ICListenerRegisterer oldListener : oldListeners) {
|
||||
if (!isListenerInTheListOfAssociations(newAssociations, oldListener)) {
|
||||
int count = 0;
|
||||
|
@ -948,7 +948,7 @@ projects:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (ListenerAssociation newListenerAssociation : newAssociations) {
|
||||
ICListenerRegisterer newListener = newListenerAssociation.listener;
|
||||
if (!isObjectInTheList(oldListeners, newListener)) {
|
||||
|
@ -966,12 +966,12 @@ projects:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deep clone of a list of language settings providers.
|
||||
*
|
||||
*
|
||||
* @param baseProviders - list of providers to clone.
|
||||
* @return newly cloned list.
|
||||
*/
|
||||
|
@ -991,19 +991,19 @@ projects:
|
|||
}
|
||||
return new ArrayList<ILanguageSettingsProvider>(newProviders);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a listener that will be notified of changes in language settings.
|
||||
*
|
||||
*
|
||||
* @param listener the ILanguageMappingChangeListener to add
|
||||
*/
|
||||
public static void registerLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) {
|
||||
fLanguageSettingsChangeListeners.add(listener);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes a language settings change listener.
|
||||
*
|
||||
*
|
||||
* @param listener the ILanguageMappingChangeListener to remove.
|
||||
*/
|
||||
public static void unregisterLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) {
|
||||
|
@ -1012,7 +1012,7 @@ projects:
|
|||
|
||||
/**
|
||||
* Notifies all language settings change listeners of a change.
|
||||
*
|
||||
*
|
||||
* @param event the ILanguageSettingsChangeEvent event to be broadcast.
|
||||
*/
|
||||
public static void notifyLanguageSettingsChangeListeners(ILanguageSettingsChangeEvent event) {
|
||||
|
@ -1025,17 +1025,17 @@ projects:
|
|||
}
|
||||
}
|
||||
|
||||
private static List<ICLanguageSettingEntry> safeGetSettingEntries(ILanguageSettingsProvider provider,
|
||||
private static List<ICLanguageSettingEntry> getSettingEntriesPooled(ILanguageSettingsProvider provider,
|
||||
ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
|
||||
|
||||
try {
|
||||
return provider.getSettingEntries(cfgDescription, rc, languageId);
|
||||
return LanguageSettingsStorage.getPooledList(provider.getSettingEntries(cfgDescription, rc, languageId));
|
||||
} catch (Throwable e) {
|
||||
String cfgId = cfgDescription!=null ? cfgDescription.getId() : null;
|
||||
String msg = "Exception in provider "+provider.getId()+": getSettingEntries("+cfgId+", "+rc+", "+languageId+")";
|
||||
CCorePlugin.log(msg, e);
|
||||
// return empty array to prevent climbing up the resource tree
|
||||
return new ArrayList<ICLanguageSettingEntry>(0);
|
||||
// return empty list to prevent getting potentially non-empty list from up the resource tree
|
||||
return LanguageSettingsStorage.getPooledEmptyList();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1044,21 +1044,21 @@ projects:
|
|||
* for the given configuration description, resource and language.
|
||||
* This method reaches to the parent folder of the resource recursively
|
||||
* in case the resource does not define the entries for the given provider.
|
||||
*
|
||||
*
|
||||
* @param provider - language settings provider.
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id.
|
||||
*
|
||||
* @return the list of setting entries. Never returns {@code null}
|
||||
*
|
||||
* @return the list of setting entries which is unmodifiable. Never returns {@code null}
|
||||
* although individual providers mandated to return {@code null} if no settings defined.
|
||||
*/
|
||||
public static List<ICLanguageSettingEntry> getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
Assert.isTrue( !(rc instanceof IWorkspaceRoot) );
|
||||
if (provider!=null) {
|
||||
List<ICLanguageSettingEntry> entries = safeGetSettingEntries(provider, cfgDescription, rc, languageId);
|
||||
List<ICLanguageSettingEntry> entries = getSettingEntriesPooled(provider, cfgDescription, rc, languageId);
|
||||
if (entries!=null) {
|
||||
return new ArrayList<ICLanguageSettingEntry>(entries);
|
||||
return entries;
|
||||
}
|
||||
if (rc!=null) {
|
||||
IResource parentFolder = (rc instanceof IProject) ? null : rc.getParent();
|
||||
|
@ -1066,21 +1066,21 @@ projects:
|
|||
return getSettingEntriesUpResourceTree(provider, cfgDescription, parentFolder, languageId);
|
||||
}
|
||||
// if out of parent resources - get default entries for the applicable language scope
|
||||
entries = safeGetSettingEntries(provider, null, null, languageId);
|
||||
entries = getSettingEntriesPooled(provider, null, null, languageId);
|
||||
if (entries!=null) {
|
||||
return new ArrayList<ICLanguageSettingEntry>(entries);
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<ICLanguageSettingEntry>(0);
|
||||
|
||||
return LanguageSettingsStorage.getPooledEmptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds for the provider a nice looking resource tree to present hierarchical view to the user.
|
||||
* Note that it is not advisable to "compact" the tree because of potential loss of information
|
||||
* which is especially important during partial or incremental builds.
|
||||
*
|
||||
*
|
||||
* @param provider - language settings provider to build the tree for.
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param languageId - language ID.
|
||||
|
@ -1095,17 +1095,17 @@ projects:
|
|||
}
|
||||
if (members==null)
|
||||
return;
|
||||
|
||||
|
||||
for (IResource rc : members) {
|
||||
if (rc instanceof IContainer) {
|
||||
buildResourceTree(provider, cfgDescription, languageId, (IContainer) rc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int rcNumber = members.length;
|
||||
|
||||
|
||||
Map<List<ICLanguageSettingEntry>, Integer> listMap = new HashMap<List<ICLanguageSettingEntry>, Integer>();
|
||||
|
||||
|
||||
// on the first pass find majority entries
|
||||
List<ICLanguageSettingEntry> majorityEntries = null;
|
||||
List<ICLanguageSettingEntry> candidate = null;
|
||||
|
@ -1123,26 +1123,26 @@ projects:
|
|||
count = 0;
|
||||
}
|
||||
count++;
|
||||
|
||||
|
||||
if (count>candidateCount) {
|
||||
candidateCount = count;
|
||||
candidate = entries;
|
||||
}
|
||||
|
||||
|
||||
listMap.put(entries, count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (candidateCount > rcNumber/2) {
|
||||
majorityEntries = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (majorityEntries!=null) {
|
||||
provider.setSettingEntries(cfgDescription, folder, languageId, majorityEntries);
|
||||
}
|
||||
|
||||
|
||||
// second pass - assign the entries to the folders
|
||||
for (IResource rc : members) {
|
||||
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, rc, languageId);
|
||||
|
@ -1178,7 +1178,7 @@ projects:
|
|||
* for the given configuration description, resource and language. This is a
|
||||
* combined list for all providers taking into account settings of parent folder
|
||||
* if settings for the given resource are not defined.
|
||||
*
|
||||
*
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id.
|
||||
|
@ -1190,15 +1190,15 @@ projects:
|
|||
* @param isLocal - {@code true} if "local" entries should be provided and
|
||||
* {@code false} for "system" entries. This makes sense for include paths where
|
||||
* [#include "..."] is "local" and [#include <...>] is system.
|
||||
*
|
||||
*
|
||||
* @return the list of setting entries found.
|
||||
*/
|
||||
private static List<ICLanguageSettingEntry> getSettingEntriesByKind(ICConfigurationDescription cfgDescription,
|
||||
IResource rc, String languageId, int kind, boolean checkLocality, boolean isLocal) {
|
||||
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
List<String> alreadyAdded = new ArrayList<String>();
|
||||
|
||||
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
for (ILanguageSettingsProvider provider: providers) {
|
||||
List<ICLanguageSettingEntry> providerEntries = getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId);
|
||||
|
@ -1221,7 +1221,7 @@ projects:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
@ -1231,7 +1231,7 @@ projects:
|
|||
* combined list for all providers taking into account settings of parent folder
|
||||
* if settings for the given resource are not defined. For include paths both
|
||||
* local (#include "...") and system (#include <...>) entries are returned.
|
||||
*
|
||||
*
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id.
|
||||
|
@ -1239,7 +1239,7 @@ projects:
|
|||
* {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag
|
||||
* and it is possible to specify composite kind.
|
||||
* Use {@link ICSettingEntry#ALL} to get all kinds.
|
||||
*
|
||||
*
|
||||
* @return the list of setting entries.
|
||||
*/
|
||||
public static List<ICLanguageSettingEntry> getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) {
|
||||
|
@ -1247,11 +1247,11 @@ projects:
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the list of "system" (such as [#include <...>]) setting entries of a certain kind
|
||||
* Returns the list of "system" (such as [#include <...>]) setting entries of a certain kind
|
||||
* for the given configuration description, resource and language. This is a
|
||||
* combined list for all providers taking into account settings of parent folder
|
||||
* if settings for the given resource are not defined.
|
||||
*
|
||||
*
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id.
|
||||
|
@ -1259,7 +1259,7 @@ projects:
|
|||
* {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag
|
||||
* and it is possible to specify composite kind.
|
||||
* Use {@link ICSettingEntry#ALL} to get all kinds.
|
||||
*
|
||||
*
|
||||
* @return the list of setting entries.
|
||||
*/
|
||||
public static List<ICLanguageSettingEntry> getSystemSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) {
|
||||
|
@ -1267,11 +1267,11 @@ projects:
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the list of "local" (such as [#include "..."]) setting entries of a certain kind
|
||||
* Returns the list of "local" (such as [#include "..."]) setting entries of a certain kind
|
||||
* for the given configuration description, resource and language. This is a
|
||||
* combined list for all providers taking into account settings of parent folder
|
||||
* if settings for the given resource are not defined.
|
||||
*
|
||||
*
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id.
|
||||
|
@ -1279,7 +1279,7 @@ projects:
|
|||
* {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag
|
||||
* and it is possible to specify composite kind.
|
||||
* Use {@link ICSettingEntry#ALL} to get all kinds.
|
||||
*
|
||||
*
|
||||
* @return the list of setting entries.
|
||||
*/
|
||||
public static List<ICLanguageSettingEntry> getLocalSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) {
|
||||
|
|
|
@ -55,8 +55,8 @@ public class LanguageSettingsStorage {
|
|||
};
|
||||
|
||||
/**
|
||||
* <br> Note that this list is <b>unmodifiable</b>. To modify the list copy it, change and use
|
||||
* {@link #setSettingEntries(ICConfigurationDescription, IResource, String, List)}.
|
||||
* TODO
|
||||
* <br> Note that this list is <b>unmodifiable</b>.
|
||||
*
|
||||
*/
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
|
@ -98,7 +98,7 @@ public class LanguageSettingsStorage {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public void setSettingEntries(String rcProjectPath, String languageId, List<ICLanguageSettingEntry> entries) {
|
||||
synchronized (fStorage) {
|
||||
|
@ -108,7 +108,7 @@ public class LanguageSettingsStorage {
|
|||
langMap = new HashMap<String, List<ICLanguageSettingEntry>>();
|
||||
fStorage.put(languageId, langMap);
|
||||
}
|
||||
List<ICLanguageSettingEntry> sortedEntries = listPool.add(Collections.unmodifiableList(sortEntries(entries)));
|
||||
List<ICLanguageSettingEntry> sortedEntries = getPooledList(sortEntries(entries), false);
|
||||
langMap.put(rcProjectPath, sortedEntries);
|
||||
} else {
|
||||
// do not keep nulls in the tables
|
||||
|
@ -129,7 +129,7 @@ public class LanguageSettingsStorage {
|
|||
public boolean isEmpty() {
|
||||
return fStorage.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear all the entries for all configurations, all resources and all languages.
|
||||
*/
|
||||
|
@ -239,20 +239,20 @@ public class LanguageSettingsStorage {
|
|||
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)
|
||||
|
@ -319,6 +319,53 @@ public class LanguageSettingsStorage {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
|
|
@ -79,11 +79,11 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
private Tree treeEntries;
|
||||
private TreeViewer treeEntriesViewer;
|
||||
private static String currentLanguageId = null;
|
||||
|
||||
|
||||
private Button builtInCheckBox;
|
||||
private Button enableProvidersCheckBox;
|
||||
private StatusMessageLine fStatusLine;
|
||||
|
||||
|
||||
private Page_LanguageSettingsProviders masterPropertyPage = null;
|
||||
|
||||
private static final int BUTTON_ADD = 0;
|
||||
|
@ -105,15 +105,15 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
|
||||
private Map<String, List<ILanguageSettingsProvider>> initialProvidersMap = new HashMap<String, List<ILanguageSettingsProvider>>();
|
||||
private boolean initialEnablement =false;
|
||||
|
||||
|
||||
private class EntriesTreeLabelProvider extends LanguageSettingsProvidersLabelProvider {
|
||||
@Override
|
||||
protected String[] getOverlayKeys(ILanguageSettingsProvider provider) {
|
||||
String[] overlayKeys = super.getOverlayKeys(provider);
|
||||
|
||||
|
||||
// if (LanguageSettingsManager.isWorkspaceProvider(provider))
|
||||
// provider = LanguageSettingsManager.getRawWorkspaceProvider(provider.getId());
|
||||
//
|
||||
//
|
||||
if (currentLanguageId != null) {
|
||||
IResource rc = getResource();
|
||||
List<ICLanguageSettingEntry> entries = getSettingEntries(provider);
|
||||
|
@ -131,7 +131,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO
|
||||
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
||||
List<ILanguageSettingsProvider> initialProviders = initialProvidersMap.get(cfgDescription.getId());
|
||||
|
@ -140,7 +140,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
}
|
||||
return overlayKeys;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Image getImage(Object element) {
|
||||
if (element instanceof ICLanguageSettingEntry) {
|
||||
|
@ -165,21 +165,30 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
return super.getText(element);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Content provider for setting entries tree.
|
||||
*/
|
||||
private class EntriesTreeContentProvider implements ITreeContentProvider {
|
||||
@Override
|
||||
public Object[] getElements(Object inputElement) {
|
||||
return getChildren(inputElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getChildren(Object parentElement) {
|
||||
if (parentElement instanceof Object[])
|
||||
return (Object[]) parentElement;
|
||||
|
||||
if (parentElement instanceof ILanguageSettingsProvider) {
|
||||
ILanguageSettingsProvider lsProvider = (ILanguageSettingsProvider)parentElement;
|
||||
List<ICLanguageSettingEntry> entriesList = getSettingEntriesUpResourceTree(lsProvider);
|
||||
if (entriesList == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// convert to modifiable list
|
||||
entriesList = new ArrayList<ICLanguageSettingEntry>(entriesList);
|
||||
|
||||
if (builtInCheckBox.getSelection()==false) {
|
||||
for (Iterator<ICLanguageSettingEntry> iter = entriesList.iterator(); iter.hasNext();) {
|
||||
|
@ -189,26 +198,28 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entriesList!=null) {
|
||||
return entriesList.toArray();
|
||||
}
|
||||
return entriesList.toArray();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParent(Object element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChildren(Object element) {
|
||||
Object[] children = getChildren(element);
|
||||
return children!=null && children.length>0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
|
@ -323,6 +334,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
columnLanguages.setToolTipText(Messages.AbstractLangsListTab_Languages);
|
||||
|
||||
treeLanguages.addPaintListener(new PaintListener() {
|
||||
@Override
|
||||
public void paintControl(PaintEvent e) {
|
||||
int x = treeLanguages.getBounds().width - 5;
|
||||
if (columnLanguages.getWidth() != x)
|
||||
|
@ -340,6 +352,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
|
||||
final TreeColumn treeCol = new TreeColumn(treeEntries, SWT.NONE);
|
||||
treeEntries.addPaintListener(new PaintListener() {
|
||||
@Override
|
||||
public void paintControl(PaintEvent e) {
|
||||
int x = treeEntries.getClientArea().width;
|
||||
if (treeCol.getWidth() != x)
|
||||
|
@ -355,7 +368,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
treeEntriesViewer = new TreeViewer(treeEntries);
|
||||
treeEntriesViewer.setContentProvider(new EntriesTreeContentProvider());
|
||||
treeEntriesViewer.setLabelProvider(new EntriesTreeLabelProvider());
|
||||
|
||||
|
||||
treeEntriesViewer.setUseHashlookup(true);
|
||||
|
||||
treeEntries.addSelectionListener(new SelectionAdapter() {
|
||||
|
@ -387,7 +400,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
initialEnablement = ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(page.getProject());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void createControls(Composite parent) {
|
||||
super.createControls(parent);
|
||||
|
@ -395,7 +408,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
GridData gd = (GridData) usercomp.getLayoutData();
|
||||
// Discourage settings entry table from trying to show all its items at once, see bug 264330
|
||||
gd.heightHint =1;
|
||||
|
||||
|
||||
if (page instanceof Page_LanguageSettingsProviders) {
|
||||
masterPropertyPage = (Page_LanguageSettingsProviders) page;
|
||||
}
|
||||
|
@ -404,7 +417,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
|
||||
// SashForms for each mode
|
||||
createShowEntriesSashForm();
|
||||
|
||||
|
||||
// Status line
|
||||
fStatusLine = new StatusMessageLine(usercomp, SWT.LEFT, 2);
|
||||
|
||||
|
@ -451,7 +464,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
gd.horizontalSpan = 2;
|
||||
gd.grabExcessVerticalSpace = true;
|
||||
sashFormEntries.setLayoutData(gd);
|
||||
|
||||
|
||||
GridLayout layout = new GridLayout();
|
||||
sashFormEntries.setLayout(layout);
|
||||
|
||||
|
@ -466,7 +479,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
treeLanguages.setEnabled(enable);
|
||||
treeEntries.setEnabled(enable);
|
||||
builtInCheckBox.setEnabled(enable);
|
||||
|
||||
|
||||
buttoncomp.setEnabled(enable);
|
||||
|
||||
if (enable) {
|
||||
|
@ -475,7 +488,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
disableButtons();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void disableButtons() {
|
||||
buttonSetEnabled(BUTTON_ADD, false);
|
||||
buttonSetEnabled(BUTTON_EDIT, false);
|
||||
|
@ -499,24 +512,24 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
|
||||
boolean isProviderEditable = provider instanceof ILanguageSettingsEditableProvider;
|
||||
// boolean isUserProvider = provider instanceof UserLanguageSettingsProvider;
|
||||
|
||||
|
||||
boolean canAdd = isProviderEditable;
|
||||
boolean canEdit = isProviderEditable && isEntrySelected;
|
||||
boolean canDelete = isProviderEditable && isEntrySelected;
|
||||
boolean canClear = isProviderEditable && isProviderSelected && entries!=null && entries.size()>0;
|
||||
|
||||
|
||||
boolean canMoveUp = false;
|
||||
boolean canMoveDown = false;
|
||||
if (isProviderEditable && isEntrySelected && entries!=null) {
|
||||
int last = entries.size()-1;
|
||||
int pos = getExactIndex(entries, entry);
|
||||
|
||||
|
||||
if (pos>=0 && pos<=last) {
|
||||
canMoveUp = pos!=0;
|
||||
canMoveDown = pos!=last;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
buttonSetText(BUTTON_DELETE, isProviderSelected ? CLEAR_STR : DEL_STR);
|
||||
|
||||
buttonSetEnabled(BUTTON_ADD, canAdd);
|
||||
|
@ -525,7 +538,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
|
||||
buttonSetEnabled(BUTTON_MOVE_UP, canMoveUp);
|
||||
buttonSetEnabled(BUTTON_MOVE_DOWN, canMoveDown);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -655,13 +668,13 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
private void addEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry) {
|
||||
if (provider!=null && entry != null) {
|
||||
String providerId = provider.getId();
|
||||
|
||||
|
||||
List<ICLanguageSettingEntry> entries = getWritableEntries(provider);
|
||||
ICLanguageSettingEntry selectedEntry = getSelectedEntry();
|
||||
int pos = getExactIndex(entries, selectedEntry);
|
||||
entries.add(pos+1, entry);
|
||||
saveEntries(provider, entries);
|
||||
|
||||
|
||||
updateTreeEntries();
|
||||
selectItem(providerId, entry);
|
||||
updateButtons();
|
||||
|
@ -692,7 +705,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
||||
IResource rc = getResource();
|
||||
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(cfgDescription, rc, currentLanguageId);
|
||||
if (entries==null) {
|
||||
if (entries == null) {
|
||||
entries = getSettingEntriesUpResourceTree(provider);
|
||||
}
|
||||
entries = new ArrayList<ICLanguageSettingEntry>(entries);
|
||||
|
@ -718,7 +731,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param selectedProvider
|
||||
* @return
|
||||
|
@ -768,16 +781,16 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
private void deleteEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry) {
|
||||
if (provider!=null && entry != null) {
|
||||
String providerId = provider.getId();
|
||||
|
||||
|
||||
List<ICLanguageSettingEntry> entries = getWritableEntries(provider);
|
||||
int pos = getExactIndex(getSettingEntriesUpResourceTree(provider), entry);
|
||||
int pos = getExactIndex(entries, entry);
|
||||
entries.remove(entry);
|
||||
saveEntries(provider, entries);
|
||||
|
||||
|
||||
if (pos>=entries.size())
|
||||
pos = entries.size()-1;
|
||||
ICLanguageSettingEntry nextEntry = pos>=0 ? entries.get(pos) : null;
|
||||
|
||||
|
||||
updateTreeEntries();
|
||||
selectItem(providerId, nextEntry);
|
||||
updateButtons();
|
||||
|
@ -789,7 +802,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
String providerId = provider.getId();
|
||||
List<ICLanguageSettingEntry> empty = new ArrayList<ICLanguageSettingEntry>();
|
||||
saveEntries(provider, empty);
|
||||
|
||||
|
||||
updateTreeEntries();
|
||||
selectItem(providerId, null);
|
||||
updateButtons();
|
||||
|
@ -810,13 +823,13 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
private void moveEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry, boolean up) {
|
||||
if (provider!=null && entry != null) {
|
||||
String providerId = provider.getId();
|
||||
|
||||
|
||||
List<ICLanguageSettingEntry> entries = getWritableEntries(provider);
|
||||
int pos = getExactIndex(entries, entry);
|
||||
int newPos = up ? pos-1 : pos+1;
|
||||
Collections.swap(entries, pos, newPos);
|
||||
saveEntries(provider, entries);
|
||||
|
||||
|
||||
updateTreeEntries();
|
||||
selectItem(providerId, entry);
|
||||
updateButtons();
|
||||
|
@ -923,7 +936,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
} else {
|
||||
setAllVisible(true, null);
|
||||
}
|
||||
|
||||
|
||||
updateTreeLanguages(rcDes);
|
||||
updateTreeEntries();
|
||||
if (masterPropertyPage!=null) {
|
||||
|
@ -950,7 +963,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
|||
IResource rc = getResource();
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
List<ILanguageSettingsProvider> writableProviders = new ArrayList<ILanguageSettingsProvider>(providers.size());
|
||||
|
||||
|
||||
providers: for (ILanguageSettingsProvider provider : providers) {
|
||||
ILanguageSettingsEditableProvider writableProvider = null;
|
||||
if (provider instanceof ILanguageSettingsEditableProvider) {
|
||||
|
@ -997,7 +1010,7 @@ providers: for (ILanguageSettingsProvider provider : providers) {
|
|||
List<ILanguageSettingsProvider> providers = srcCfgDescription.getLanguageSettingProviders();
|
||||
destCfgDescription.setLanguageSettingProviders(providers);
|
||||
}
|
||||
|
||||
|
||||
if (!page.isForPrefs()) {
|
||||
ICConfigurationDescription sd = srcRcDescription.getConfiguration();
|
||||
ICConfigurationDescription dd = destRcDescription.getConfiguration();
|
||||
|
@ -1038,7 +1051,7 @@ providers: for (ILanguageSettingsProvider provider : providers) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue