diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/JREsComboBlock.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/JREsComboBlock.java index 4285301d45..4d70f94568 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/JREsComboBlock.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/JREsComboBlock.java @@ -464,6 +464,7 @@ protected void fillWithWorkspaceJREs() { protected void fillWithWorkspaceProfiles() { fEnvironments.clear(); fEnvironments.addAll(JavaRuntime.getExecutionEnvironmentsManager().getSupportedExecutionEnvironments()); + Collections.reverse(fEnvironments); String[] names = new String[fEnvironments.size()]; Iterator iter = fEnvironments.iterator(); int i = 0; diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/EnvironmentsManager.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/EnvironmentsManager.java index 18df3a54de..45019757cf 100644 --- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/EnvironmentsManager.java +++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/EnvironmentsManager.java @@ -21,10 +21,9 @@ import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; import java.util.Map; import java.util.Set; +import java.util.SortedSet; import java.util.TreeSet; import javax.xml.parsers.DocumentBuilder; @@ -92,7 +91,7 @@ public class EnvironmentsManager implements IExecutionEnvironmentsManager, IVMIn */ private TreeSet fEnvironments = null; - private List supportedEnvironments; + private SortedSet supportedEnvironments; /** * List of access rule participants @@ -166,7 +165,7 @@ public synchronized IExecutionEnvironment[] getExecutionEnvironments() { } @Override - public synchronized List getSupportedExecutionEnvironments() { + public synchronized SortedSet getSupportedExecutionEnvironments() { initializeExtensions(); return supportedEnvironments; } @@ -260,20 +259,15 @@ private synchronized void initializeExtensions() { if (fEnvironments != null) { return; } + Comparator eeComparator = ((Comparator) (o1, o2) -> { + String compliance1 = getExecutionEnvironmentCompliance(o1); + String compliance2 = getExecutionEnvironmentCompliance(o2); + return JavaCore.compareJavaVersions(compliance1, compliance2); + }).thenComparing(IExecutionEnvironment::getId); + IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(LaunchingPlugin.ID_PLUGIN, JavaRuntime.EXTENSION_POINT_EXECUTION_ENVIRONMENTS); IConfigurationElement[] configs = extensionPoint.getConfigurationElements(); - fEnvironments = new TreeSet<>(new Comparator() { - @Override - public int compare(IExecutionEnvironment o1, IExecutionEnvironment o2) { - String compliance1 = getExecutionEnvironmentCompliance(o1); - String compliance2 = getExecutionEnvironmentCompliance(o2); - int result = JavaCore.compareJavaVersions(compliance1, compliance2); - if (result == 0) { - return o1.getId().compareTo(o2.getId()); - } - return result; - } - }); + fEnvironments = new TreeSet<>(eeComparator); fRuleParticipants = new LinkedHashSet<>(); fEnvironmentsMap = new HashMap<>(configs.length); fAnalyzers = new HashMap<>(configs.length); @@ -316,15 +310,14 @@ public int compare(IExecutionEnvironment o1, IExecutionEnvironment o2) { } } - List filtered = new LinkedList<>(); + SortedSet filtered = new TreeSet<>(eeComparator); for (IExecutionEnvironment environment : fEnvironments) { Map options = environment.getComplianceOptions(); if (options != null && JavaCore.isJavaSourceVersionSupportedByCompiler(options.get(JavaCore.COMPILER_COMPLIANCE))) { filtered.add(environment); } } - Collections.reverse(filtered); - supportedEnvironments = Collections.unmodifiableList(filtered); + supportedEnvironments = Collections.unmodifiableSortedSet(filtered); } /** diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/environments/IExecutionEnvironmentsManager.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/environments/IExecutionEnvironmentsManager.java index ba2a0ccfb5..712d2bb5e3 100644 --- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/environments/IExecutionEnvironmentsManager.java +++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/environments/IExecutionEnvironmentsManager.java @@ -13,7 +13,7 @@ *******************************************************************************/ package org.eclipse.jdt.launching.environments; -import java.util.List; +import java.util.SortedSet; import org.eclipse.jdt.core.JavaCore; @@ -36,7 +36,7 @@ public interface IExecutionEnvironmentsManager { public IExecutionEnvironment[] getExecutionEnvironments(); /** - * Returns all execution environments supported by Java projects, reverse sorted by their id. + * Returns all execution environments supported by Java projects, sorted by their id. * * @see IExecutionEnvironment#getId() * @see JavaCore#isJavaSourceVersionSupportedByCompiler(String) @@ -44,7 +44,7 @@ public interface IExecutionEnvironmentsManager { * @return all registered execution environments sorted by their id * @since 3.23 */ - public List getSupportedExecutionEnvironments(); + public SortedSet getSupportedExecutionEnvironments(); /** * Returns the execution environment associated with the given