|
43 | 43 | import com.github._1c_syntax.bsl.types.ConfigurationSource;
|
44 | 44 | import com.github._1c_syntax.bsl.types.ModuleType;
|
45 | 45 | import com.github._1c_syntax.utils.Lazy;
|
| 46 | +import edu.umd.cs.findbugs.annotations.NonNull; |
46 | 47 | import edu.umd.cs.findbugs.annotations.Nullable;
|
47 | 48 | import jakarta.annotation.PostConstruct;
|
| 49 | +import lombok.EqualsAndHashCode; |
48 | 50 | import lombok.Getter;
|
49 | 51 | import lombok.RequiredArgsConstructor;
|
50 | 52 | import lombok.Setter;
|
|
65 | 67 | import java.net.URI;
|
66 | 68 | import java.nio.charset.StandardCharsets;
|
67 | 69 | import java.util.Collections;
|
| 70 | +import java.util.Comparator; |
68 | 71 | import java.util.List;
|
69 | 72 | import java.util.Locale;
|
70 | 73 | import java.util.Optional;
|
71 | 74 | import java.util.concurrent.locks.ReentrantLock;
|
72 | 75 | import java.util.regex.Pattern;
|
73 |
| -import java.util.stream.Collectors; |
74 | 76 |
|
75 | 77 | import static java.util.Objects.requireNonNull;
|
76 | 78 | import static org.antlr.v4.runtime.Token.DEFAULT_CHANNEL;
|
|
79 | 81 | @Scope("prototype")
|
80 | 82 | @RequiredArgsConstructor
|
81 | 83 | @Slf4j
|
82 |
| -public class DocumentContext { |
| 84 | +@EqualsAndHashCode(onlyExplicitlyIncluded = true) |
| 85 | +public class DocumentContext implements Comparable<DocumentContext> { |
83 | 86 |
|
84 | 87 | private static final Pattern CONTENT_SPLIT_PATTERN = Pattern.compile("\r?\n|\r");
|
85 | 88 |
|
86 | 89 | @Getter
|
| 90 | + @EqualsAndHashCode.Include |
87 | 91 | private final URI uri;
|
88 | 92 |
|
89 | 93 | @Nullable
|
90 | 94 | private String content;
|
| 95 | + |
91 | 96 | @Getter
|
| 97 | + @EqualsAndHashCode.Include |
92 | 98 | private int version;
|
93 | 99 |
|
94 | 100 | @Setter(onMethod = @__({@Autowired}))
|
@@ -158,13 +164,13 @@ public List<Token> getTokens() {
|
158 | 164 | }
|
159 | 165 |
|
160 | 166 | public List<Token> getTokensFromDefaultChannel() {
|
161 |
| - return getTokens().stream().filter(token -> token.getChannel() == DEFAULT_CHANNEL).collect(Collectors.toList()); |
| 167 | + return getTokens().stream().filter(token -> token.getChannel() == DEFAULT_CHANNEL).toList(); |
162 | 168 | }
|
163 | 169 |
|
164 | 170 | public List<Token> getComments() {
|
165 | 171 | return getTokens().stream()
|
166 | 172 | .filter(token -> token.getType() == BSLLexer.LINE_COMMENT)
|
167 |
| - .collect(Collectors.toList()); |
| 173 | + .toList(); |
168 | 174 | }
|
169 | 175 |
|
170 | 176 | public String getText(Range range) {
|
@@ -429,4 +435,10 @@ private List<SDBLTokenizer> computeQueries() {
|
429 | 435 | return (new QueryComputer(this)).compute();
|
430 | 436 | }
|
431 | 437 |
|
| 438 | + @Override |
| 439 | + public int compareTo(@NonNull DocumentContext other) { |
| 440 | + return Comparator.comparing(DocumentContext::getUri) |
| 441 | + .thenComparing(DocumentContext::getVersion) |
| 442 | + .compare(this, other); |
| 443 | + } |
432 | 444 | }
|
0 commit comments