|
1 | 1 | /* |
2 | | - * Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
43 | 43 | import com.sun.source.tree.Scope; |
44 | 44 | import com.sun.source.tree.Tree; |
45 | 45 | import com.sun.source.tree.Tree.Kind; |
46 | | -import static com.sun.source.tree.Tree.Kind.METHOD; |
47 | 46 | import com.sun.source.tree.TypeParameterTree; |
48 | 47 | import com.sun.source.tree.VariableTree; |
49 | 48 | import com.sun.source.tree.YieldTree; |
|
81 | 80 | import java.util.List; |
82 | 81 | import java.util.Objects; |
83 | 82 | import java.util.function.Predicate; |
| 83 | +import java.util.TreeSet; |
84 | 84 |
|
85 | 85 | import javax.lang.model.element.Element; |
86 | 86 | import javax.lang.model.element.ElementKind; |
|
114 | 114 | import java.util.NoSuchElementException; |
115 | 115 | import java.util.Optional; |
116 | 116 | import java.util.Set; |
117 | | -import java.util.concurrent.Callable; |
118 | 117 | import java.util.concurrent.ExecutorService; |
119 | 118 | import java.util.concurrent.Executors; |
120 | 119 | import java.util.function.BiConsumer; |
|
149 | 148 | import javax.tools.StandardLocation; |
150 | 149 |
|
151 | 150 | import jdk.jshell.ExpressionToTypeInfo.ExpressionInfo; |
152 | | -import static jdk.jshell.Util.REPL_DOESNOTMATTER_CLASS_NAME; |
153 | 151 | import static jdk.jshell.SourceCodeAnalysis.Completeness.DEFINITELY_INCOMPLETE; |
154 | 152 | import static jdk.jshell.TreeDissector.printType; |
155 | 153 |
|
156 | 154 | import static java.util.stream.Collectors.joining; |
157 | | -import static javax.lang.model.element.ElementKind.CONSTRUCTOR; |
158 | | -import static javax.lang.model.element.ElementKind.MODULE; |
159 | | -import static javax.lang.model.element.ElementKind.PACKAGE; |
160 | 155 |
|
161 | 156 | import javax.lang.model.type.IntersectionType; |
162 | 157 | import javax.lang.model.util.Elements; |
@@ -815,7 +810,7 @@ public List<Highlight> highlights(String snippet) { |
815 | 810 | }; |
816 | 811 | String wrappedCode = codeWrap.wrapped(); |
817 | 812 | return this.proc.taskFactory.analyze(codeWrap, task -> { |
818 | | - List<Highlight> result = new ArrayList<>(); |
| 813 | + TreeSet<Highlight> result = new TreeSet<>(Comparator.comparing(Highlight::start).thenComparing(Highlight::end)); |
819 | 814 | CompilationUnitTree cut = task.cuTrees().iterator().next(); |
820 | 815 | Trees trees = task.trees(); |
821 | 816 | SourcePositions sp = trees.getSourcePositions(); |
@@ -1050,8 +1045,7 @@ private Token findTokensBefore(long pos, TokenKind... expectedKinds) { |
1050 | 1045 | } |
1051 | 1046 | }.scan(cut, null); |
1052 | 1047 | result.removeIf(h -> h.start() == h.end()); |
1053 | | - Collections.sort(result, (h1, h2) -> h1.start() - h2.start()); |
1054 | | - return result; |
| 1048 | + return new ArrayList<>(result); |
1055 | 1049 | }); |
1056 | 1050 | } |
1057 | 1051 |
|
|
0 commit comments