Skip to content

Commit

Permalink
DocumentContext сделан Comparable
Browse files Browse the repository at this point in the history
Т.к. он используется как ключ Map, класс обязан имплементировать Comparable
  • Loading branch information
nixel2007 committed Jan 19, 2025
1 parent df086dc commit d5c952a
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
import com.github._1c_syntax.bsl.types.ConfigurationSource;
import com.github._1c_syntax.bsl.types.ModuleType;
import com.github._1c_syntax.utils.Lazy;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import jakarta.annotation.PostConstruct;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
Expand All @@ -65,12 +67,12 @@
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static java.util.Objects.requireNonNull;
import static org.antlr.v4.runtime.Token.DEFAULT_CHANNEL;
Expand All @@ -79,16 +81,20 @@
@Scope("prototype")
@RequiredArgsConstructor
@Slf4j
public class DocumentContext {
@EqualsAndHashCode
public class DocumentContext implements Comparable<DocumentContext> {

private static final Pattern CONTENT_SPLIT_PATTERN = Pattern.compile("\r?\n|\r");

@Getter
@EqualsAndHashCode.Include
private final URI uri;

@Nullable
private String content;

@Getter
@EqualsAndHashCode.Include
private int version;

@Setter(onMethod = @__({@Autowired}))
Expand Down Expand Up @@ -158,13 +164,13 @@ public List<Token> getTokens() {
}

public List<Token> getTokensFromDefaultChannel() {
return getTokens().stream().filter(token -> token.getChannel() == DEFAULT_CHANNEL).collect(Collectors.toList());
return getTokens().stream().filter(token -> token.getChannel() == DEFAULT_CHANNEL).toList();
}

public List<Token> getComments() {
return getTokens().stream()
.filter(token -> token.getType() == BSLLexer.LINE_COMMENT)
.collect(Collectors.toList());
.toList();
}

public String getText(Range range) {
Expand Down Expand Up @@ -429,4 +435,10 @@ private List<SDBLTokenizer> computeQueries() {
return (new QueryComputer(this)).compute();
}

@Override
public int compareTo(@NonNull DocumentContext other) {
return Comparator.comparing(DocumentContext::getUri)
.thenComparing(DocumentContext::getVersion)
.compare(this, other);
}
}

0 comments on commit d5c952a

Please sign in to comment.