Skip to content

Commit

Permalink
Make PreferencesService default default lookup order more immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Dec 9, 2023
1 parent ec54909 commit ba89e4c
Showing 1 changed file with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public class PreferencesService implements IPreferencesService {
private static final String MATCH_TYPE_PREFIX = "prefix"; //$NON-NLS-1$

// the order of search scopes when people don't have a specific order set
private static String[] DEFAULT_DEFAULT_LOOKUP_ORDER = new String[] { //
private static List<String> DEFAULT_DEFAULT_LOOKUP_ORDER = List.of( //
InstanceScope.SCOPE, //
ConfigurationScope.SCOPE, //
DefaultScope.SCOPE };
DefaultScope.SCOPE);
private static final char EXPORT_ROOT_PREFIX = '!';
private static final char BUNDLE_VERSION_PREFIX = '@';
private static final float EXPORT_VERSION = 3;
Expand Down Expand Up @@ -565,10 +565,12 @@ public String[] getLookupOrder(String qualifier, String key) {
String[] order = getDefaultLookupOrder(qualifier, key);
// if there wasn't an exact match based on both qualifier and simple name
// then do a lookup based only on the qualifier
if (order == null && key != null)
if (order == null && key != null) {
order = getDefaultLookupOrder(qualifier, null);
if (order == null)
order = DEFAULT_DEFAULT_LOOKUP_ORDER;
}
if (order == null) {
order = DEFAULT_DEFAULT_LOOKUP_ORDER.toArray(String[]::new); // prevent mutations of the original
}
return order;
}

Expand Down Expand Up @@ -1095,11 +1097,25 @@ public IStatus validateVersions(IPath path) {
return result;
}

/*
* Prepend the given scope to the default search order to use when there is
* nothing else set. Clients should not call this method because it is in an
* internal class and has been created solely for use by the
* org.eclipse.core.resources bundle in response to this bug:
* https://bugs.eclipse.org/330320
*/
public void prependScopeToDefaultDefaultLookupOrder(String firstScope) {
List<String> scopes = new ArrayList<>(DEFAULT_DEFAULT_LOOKUP_ORDER);
scopes.add(0, firstScope);
DEFAULT_DEFAULT_LOOKUP_ORDER = List.copyOf(scopes);
}

/*
* Return the default search lookup order for when nothing is set.
*/
@Deprecated(forRemoval = true)
public String[] getDefaultDefaultLookupOrder() {
return DEFAULT_DEFAULT_LOOKUP_ORDER;
return DEFAULT_DEFAULT_LOOKUP_ORDER.toArray(String[]::new);
}

/*
Expand All @@ -1108,10 +1124,9 @@ public String[] getDefaultDefaultLookupOrder() {
* created solely for use by the org.eclipse.core.resources bundle in response
* to this bug: https://bugs.eclipse.org/330320
*/
@Deprecated(forRemoval = true)
public void setDefaultDefaultLookupOrder(String[] order) {
// shouldn't happen but let's protect against an NPE.
if (order == null)
order = new String[0];
DEFAULT_DEFAULT_LOOKUP_ORDER = order;
DEFAULT_DEFAULT_LOOKUP_ORDER = List.of(order);
}
}

0 comments on commit ba89e4c

Please sign in to comment.