[spelling] Nullability annotations for Tokenizer and Splitter APIs

GitOrigin-RevId: cab36ef200a7a979aafd9446f347c0a8bb1575e8
This commit is contained in:
Yuriy Artamonov
2025-03-23 14:27:00 +00:00
committed by intellij-monorepo-bot
parent fa26329b2b
commit ced3ae6cd3
12 changed files with 20 additions and 16 deletions
@@ -34,7 +34,7 @@ public final class CommentSplitter extends BaseSplitter {
}
@Override
public void split(@Nullable String text, @NotNull TextRange range, Consumer<TextRange> consumer) {
public void split(@Nullable String text, @NotNull TextRange range, @NotNull Consumer<TextRange> consumer) {
if (text == null || StringUtil.isEmpty(text)) {
return;
}
@@ -24,7 +24,7 @@ public class IdentifierSplitter extends BaseSplitter {
private static final @NonNls Pattern WORD_IN_QUOTES = Pattern.compile("'([^']*)'");
@Override
public void split(@Nullable String text, @NotNull TextRange range, Consumer<TextRange> consumer) {
public void split(@Nullable String text, @NotNull TextRange range, @NotNull Consumer<TextRange> consumer) {
if (text == null || range.getLength() < 1 || range.getStartOffset() < 0) {
return;
}
@@ -56,7 +56,7 @@ public class PlainTextSplitter extends BaseSplitter {
private static final Pattern JWT_PATTERN = Pattern.compile("[A-Za-z0-9+=/_\\-.]+");
@Override
public void split(@Nullable String text, @NotNull TextRange range, Consumer<TextRange> consumer) {
public void split(@Nullable String text, @NotNull TextRange range, @NotNull Consumer<TextRange> consumer) {
if (StringUtil.isEmpty(text)) {
return;
}
@@ -21,11 +21,12 @@ public final class PropertiesSplitter extends BaseSplitter {
private static final @NonNls Pattern WORD = Pattern.compile("\\p{L}*");
@Override
public void split(@Nullable String text, @NotNull TextRange range, Consumer<TextRange> consumer) {
public void split(@Nullable String text, @NotNull TextRange range, @NotNull Consumer<TextRange> consumer) {
if (text == null || StringUtil.isEmpty(text)) {
return;
}
final IdentifierSplitter splitter = IdentifierSplitter.getInstance();
var splitter = IdentifierSplitter.getInstance();
//noinspection IncorrectCancellationExceptionHandling custom exception handling
try {
Matcher matcher = WORD.matcher(newBombedCharSequence(text, range));
while (matcher.find()) {
@@ -7,5 +7,5 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface Splitter {
void split(@Nullable String text, @NotNull TextRange range, Consumer<TextRange> consumer);
void split(@Nullable String text, @NotNull TextRange range, @NotNull Consumer<TextRange> consumer);
}
@@ -32,7 +32,7 @@ public class TextSplitter extends BaseSplitter {
"(_|" + letter + ")*+" // more letters and underscores
);
@Override
public void split(@Nullable String text, @NotNull TextRange range, Consumer<TextRange> consumer) {
public void split(@Nullable String text, @NotNull TextRange range, @NotNull Consumer<TextRange> consumer) {
if (text == null || StringUtil.isEmpty(text)) {
return;
}
@@ -20,7 +20,7 @@ public final class WordSplitter extends BaseSplitter {
private static final @NonNls Pattern SPECIAL = Pattern.compile("&\\p{Alnum}{2};?|#\\p{Alnum}{3,6}|0x\\p{Alnum}?");
@Override
public void split(@Nullable String text, @NotNull TextRange range, Consumer<TextRange> consumer) {
public void split(@Nullable String text, @NotNull TextRange range, @NotNull Consumer<TextRange> consumer) {
if (text == null || range.getLength() <= 1) {
return;
}
@@ -7,7 +7,6 @@ import com.intellij.psi.PsiElement;
import com.intellij.spellchecker.inspections.PlainTextSplitter;
import org.jetbrains.annotations.NotNull;
public abstract class EscapeSequenceTokenizer<T extends PsiElement> extends Tokenizer<T> {
private static final Key<int[]> ESCAPE_OFFSETS = Key.create("escape.tokenizer.offsets");
@@ -20,7 +19,7 @@ public abstract class EscapeSequenceTokenizer<T extends PsiElement> extends Toke
}
@Override
public @NotNull TextRange getHighlightingRange(PsiElement element, int offset, TextRange range) {
public @NotNull TextRange getHighlightingRange(@NotNull PsiElement element, int offset, @NotNull TextRange range) {
final int[] offsets = element.getUserData(ESCAPE_OFFSETS);
if (offsets != null) {
int start = offsets[range.getStartOffset()];
@@ -54,7 +54,10 @@ public class SpellcheckingStrategy implements PossiblyDumbAware {
public static final Tokenizer<PsiElement> TEXT_TOKENIZER = new TokenizerBase<>(PlainTextSplitter.getInstance());
public Tokenizer getTokenizer(PsiElement element, Set<SpellCheckingInspection.SpellCheckingScope> scope) {
/**
* @see SpellcheckingStrategy#EMPTY_TOKENIZER
*/
public @NotNull Tokenizer getTokenizer(@NotNull PsiElement element, @NotNull Set<SpellCheckingInspection.SpellCheckingScope> scope) {
return getTokenizer(element);
}
@@ -9,7 +9,7 @@ public abstract class Tokenizer<T extends PsiElement> {
public abstract void tokenize(@NotNull T element, @NotNull TokenConsumer consumer);
public @NotNull TextRange getHighlightingRange(PsiElement element, int offset, TextRange textRange) {
public @NotNull TextRange getHighlightingRange(@NotNull PsiElement element, int offset, @NotNull TextRange textRange) {
return TextRange.from(offset + textRange.getStartOffset(), textRange.getLength());
}
}
@@ -1,13 +1,12 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.spellchecker.tokenizer;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiLanguageInjectionHost;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.intellij.spellchecker.inspections.Splitter;
import org.jetbrains.annotations.NotNull;
public class TokenizerBase<T extends PsiElement> extends Tokenizer<T> {
public static <T extends PsiElement> TokenizerBase<T> create(Splitter splitter) {
return new TokenizerBase<>(splitter);
@@ -26,9 +25,11 @@ public class TokenizerBase<T extends PsiElement> extends Tokenizer<T> {
@Override
public void tokenize(@NotNull T element, @NotNull TokenConsumer consumer) {
if (element instanceof PsiLanguageInjectionHost && InjectedLanguageUtil.hasInjections((PsiLanguageInjectionHost)element)) {
if (element instanceof PsiLanguageInjectionHost
&& InjectedLanguageManager.getInstance(element.getProject()).getInjectedPsiFiles(element) != null) {
return;
}
consumer.consumeToken(element, mySplitter);
}
}
@@ -89,7 +89,7 @@ public class XmlTokenizerBase<T extends PsiElement> extends Tokenizer<T> {
private @NotNull Splitter createExclusionAwareSplitter(List<TextRange> excludeRanges, int offset) {
return new Splitter() {
@Override
public void split(@Nullable String text, @NotNull TextRange range, Consumer<TextRange> consumer) {
public void split(@Nullable String text, @NotNull TextRange range, @NotNull Consumer<TextRange> consumer) {
mySplitter.split(text, range, tokenRange -> {
if (ContainerUtil.all(excludeRanges, excludeRange -> !excludeRange.intersects(tokenRange.shiftRight(offset)))) {
consumer.consume(tokenRange);