Skip to content

Commit

Permalink
Return a SortedSet in EEManager's getSupportedExecutionEnvironments()
Browse files Browse the repository at this point in the history
And don't reverse the EE order to be consistent with existing methods.
  • Loading branch information
HannesWell authored and iloveeclipse committed Aug 22, 2024
1 parent 49f2240 commit 1f509a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> iter = fEnvironments.iterator();
int i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,7 +91,7 @@ public class EnvironmentsManager implements IExecutionEnvironmentsManager, IVMIn
*/
private TreeSet<IExecutionEnvironment> fEnvironments = null;

private List<IExecutionEnvironment> supportedEnvironments;
private SortedSet<IExecutionEnvironment> supportedEnvironments;

/**
* List of access rule participants
Expand Down Expand Up @@ -166,7 +165,7 @@ public synchronized IExecutionEnvironment[] getExecutionEnvironments() {
}

@Override
public synchronized List<IExecutionEnvironment> getSupportedExecutionEnvironments() {
public synchronized SortedSet<IExecutionEnvironment> getSupportedExecutionEnvironments() {
initializeExtensions();
return supportedEnvironments;
}
Expand Down Expand Up @@ -260,20 +259,15 @@ private synchronized void initializeExtensions() {
if (fEnvironments != null) {
return;
}
Comparator<IExecutionEnvironment> eeComparator = ((Comparator<IExecutionEnvironment>) (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<IExecutionEnvironment>() {
@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);
Expand Down Expand Up @@ -316,15 +310,14 @@ public int compare(IExecutionEnvironment o1, IExecutionEnvironment o2) {
}
}

List<IExecutionEnvironment> filtered = new LinkedList<>();
SortedSet<IExecutionEnvironment> filtered = new TreeSet<>(eeComparator);
for (IExecutionEnvironment environment : fEnvironments) {
Map<String, String> 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*******************************************************************************/
package org.eclipse.jdt.launching.environments;

import java.util.List;
import java.util.SortedSet;

import org.eclipse.jdt.core.JavaCore;

Expand All @@ -36,15 +36,15 @@ public interface IExecutionEnvironmentsManager {
public IExecutionEnvironment[] getExecutionEnvironments();

/**
* Returns all execution environments supported by Java projects, <b>reverse</b> sorted by their id.
* Returns all execution environments supported by Java projects, sorted by their id.
*
* @see IExecutionEnvironment#getId()
* @see JavaCore#isJavaSourceVersionSupportedByCompiler(String)
*
* @return all registered execution environments sorted by their id
* @since 3.23
*/
public List<IExecutionEnvironment> getSupportedExecutionEnvironments();
public SortedSet<IExecutionEnvironment> getSupportedExecutionEnvironments();

/**
* Returns the execution environment associated with the given
Expand Down

0 comments on commit 1f509a5

Please sign in to comment.