LexerTestCase: add missing @NotNull annotations to improve interoperability with Kotlin

GitOrigin-RevId: e98b6523585f4659687abca687c8b42618dfd8bc
This commit is contained in:
Piotr Tomiak
2023-07-12 15:44:52 +02:00
committed by intellij-monorepo-bot
parent 7616e0109a
commit 1d3e210cc4
14 changed files with 80 additions and 70 deletions

View File

@@ -3,6 +3,7 @@ package org.intellij.lang.regexp;
import com.intellij.lexer.Lexer; import com.intellij.lexer.Lexer;
import com.intellij.testFramework.LexerTestCase; import com.intellij.testFramework.LexerTestCase;
import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.util.EnumSet; import java.util.EnumSet;
@@ -860,12 +861,12 @@ public class RegExpLexerTest extends LexerTestCase {
} }
@Override @Override
protected Lexer createLexer() { protected @NotNull Lexer createLexer() {
return null; return null;
} }
@Override @Override
protected String getDirPath() { protected @NotNull String getDirPath() {
if (new File(getHomePath(), "community/RegExpSupport").isDirectory()) { if (new File(getHomePath(), "community/RegExpSupport").isDirectory()) {
return "/community/RegExpSupport/testData/lexer"; return "/community/RegExpSupport/testData/lexer";
} }

View File

@@ -18,6 +18,7 @@ package com.intellij.java.ide.fileTemplates.impl;
import com.intellij.ide.fileTemplates.impl.FileTemplateConfigurable; import com.intellij.ide.fileTemplates.impl.FileTemplateConfigurable;
import com.intellij.lexer.Lexer; import com.intellij.lexer.Lexer;
import com.intellij.testFramework.LexerTestCase; import com.intellij.testFramework.LexerTestCase;
import org.jetbrains.annotations.NotNull;
public class FileTemplateLexerTest extends LexerTestCase { public class FileTemplateLexerTest extends LexerTestCase {
@@ -36,12 +37,12 @@ public class FileTemplateLexerTest extends LexerTestCase {
} }
@Override @Override
protected Lexer createLexer() { protected @NotNull Lexer createLexer() {
return FileTemplateConfigurable.createDefaultLexer(); return FileTemplateConfigurable.createDefaultLexer();
} }
@Override @Override
protected String getDirPath() { protected @NotNull String getDirPath() {
return null; return null;
} }
} }

View File

@@ -5,6 +5,7 @@ import com.intellij.lang.java.JavaParserDefinition;
import com.intellij.lexer.Lexer; import com.intellij.lexer.Lexer;
import com.intellij.pom.java.LanguageLevel; import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.LexerTestCase; import com.intellij.testFramework.LexerTestCase;
import org.jetbrains.annotations.NotNull;
public class JavaLexerTest extends LexerTestCase { public class JavaLexerTest extends LexerTestCase {
public void testClassicNumericLiterals() { public void testClassicNumericLiterals() {
@@ -426,7 +427,7 @@ public class JavaLexerTest extends LexerTestCase {
} }
@Override @Override
protected Lexer createLexer() { protected @NotNull Lexer createLexer() {
if (getTestName(false).endsWith("JDK21_Preview")) { if (getTestName(false).endsWith("JDK21_Preview")) {
return JavaParserDefinition.createLexer(LanguageLevel.JDK_21_PREVIEW); return JavaParserDefinition.createLexer(LanguageLevel.JDK_21_PREVIEW);
} }
@@ -434,7 +435,7 @@ public class JavaLexerTest extends LexerTestCase {
} }
@Override @Override
protected String getDirPath() { protected @NotNull String getDirPath() {
return ""; return "";
} }
} }

View File

@@ -2,18 +2,19 @@ package com.intellij.json;
import com.intellij.lexer.Lexer; import com.intellij.lexer.Lexer;
import com.intellij.testFramework.LexerTestCase; import com.intellij.testFramework.LexerTestCase;
import org.jetbrains.annotations.NotNull;
/** /**
* @author Konstantin.Ulitin * @author Konstantin.Ulitin
*/ */
public class JsonLexerTest extends LexerTestCase { public class JsonLexerTest extends LexerTestCase {
@Override @Override
protected Lexer createLexer() { protected @NotNull Lexer createLexer() {
return new JsonLexer(); return new JsonLexer();
} }
@Override @Override
protected String getDirPath() { protected @NotNull String getDirPath() {
return null; return null;
} }

View File

@@ -22,15 +22,15 @@ import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public abstract class LexerTestCase extends UsefulTestCase { public abstract class LexerTestCase extends UsefulTestCase {
protected void doTest(String text) { protected void doTest(@NotNull String text) {
doTest(text, null); doTest(text, null);
} }
protected void doTest(String text, @Nullable String expected) { protected void doTest(@NotNull String text, @Nullable String expected) {
doTest(text, expected, createLexer()); doTest(text, expected, createLexer());
} }
protected void doTest(String text, @Nullable String expected, @NotNull Lexer lexer) { protected void doTest(@NotNull String text, @Nullable String expected, @NotNull Lexer lexer) {
String result = printTokens(lexer, text, 0); String result = printTokens(lexer, text, 0);
if (expected != null) { if (expected != null) {
@@ -41,12 +41,12 @@ public abstract class LexerTestCase extends UsefulTestCase {
} }
} }
protected String printTokens(Lexer lexer, CharSequence text, int start) { protected String printTokens(@NotNull Lexer lexer, @NotNull CharSequence text, int start) {
return printTokens(text, start, lexer); return printTokens(text, start, lexer);
} }
@NotNull @NotNull
protected String getPathToTestDataFile(String extension) { protected String getPathToTestDataFile(@NotNull String extension) {
return IdeaTestExecutionPolicy.getHomePathWithPolicy() + "/" + getDirPath() + "/" + getTestName(true) + extension; return IdeaTestExecutionPolicy.getHomePathWithPolicy() + "/" + getDirPath() + "/" + getTestName(true) + extension;
} }
@@ -55,7 +55,7 @@ public abstract class LexerTestCase extends UsefulTestCase {
return ".txt"; return ".txt";
} }
protected void checkZeroState(String text, TokenSet tokenTypes) { protected void checkZeroState(@NotNull String text, TokenSet tokenTypes) {
Lexer lexer = createLexer(); Lexer lexer = createLexer();
lexer.start(text); lexer.start(text);
@@ -71,7 +71,7 @@ public abstract class LexerTestCase extends UsefulTestCase {
} }
} }
protected String printTokens(String text, int start) { protected String printTokens(@NotNull String text, int start) {
return printTokens(text, start, createLexer()); return printTokens(text, start, createLexer());
} }
@@ -123,7 +123,7 @@ public abstract class LexerTestCase extends UsefulTestCase {
return allTokens; return allTokens;
} }
public static String printTokens(CharSequence text, int start, Lexer lexer) { public static String printTokens(@NotNull CharSequence text, int start, @NotNull Lexer lexer) {
lexer.start(text, start, text.length()); lexer.start(text, start, text.length());
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
IElementType tokenType; IElementType tokenType;
@@ -147,11 +147,11 @@ public abstract class LexerTestCase extends UsefulTestCase {
return result.toString(); return result.toString();
} }
public static String printSingleToken(CharSequence fileText, IElementType tokenType, int start, int end) { public static String printSingleToken(@NotNull CharSequence fileText, @NotNull IElementType tokenType, int start, int end) {
return tokenType + " ('" + getTokenText(tokenType, fileText, start, end) + "')\n"; return tokenType + " ('" + getTokenText(tokenType, fileText, start, end) + "')\n";
} }
protected void doFileTest(String fileExt) { protected void doFileTest(@NotNull String fileExt) {
doTest(loadTestDataFile("." + fileExt)); doTest(loadTestDataFile("." + fileExt));
} }
@@ -180,7 +180,7 @@ public abstract class LexerTestCase extends UsefulTestCase {
: StringUtil.replace(sequence.subSequence(start, end).toString(), "\n", "\\n"); : StringUtil.replace(sequence.subSequence(start, end).toString(), "\n", "\\n");
} }
protected abstract Lexer createLexer(); protected abstract @NotNull Lexer createLexer();
protected abstract String getDirPath(); protected abstract @NotNull String getDirPath();
} }

View File

@@ -13,11 +13,13 @@ import org.jetbrains.plugins.groovy.util.TestUtils
@CompileStatic @CompileStatic
class GroovyLexerTest extends LexerTestCase { class GroovyLexerTest extends LexerTestCase {
@NotNull
@Override @Override
protected Lexer createLexer() { protected Lexer createLexer() {
new GroovyLexer() new GroovyLexer()
} }
@NotNull
@Override @Override
protected String getDirPath() { protected String getDirPath() {
TestUtils.testDataPath + "lexer" TestUtils.testDataPath + "lexer"
@@ -35,13 +37,13 @@ class GroovyLexerTest extends LexerTestCase {
} }
@Override @Override
protected void doTest(@NonNls String text) { protected void doTest(@NotNull @NonNls String text) {
super.doTest(text) super.doTest(text)
checkCorrectRestart(text) checkCorrectRestart(text)
} }
@Override @Override
protected String printTokens(Lexer lexer, CharSequence text, int start) { protected String printTokens(@NotNull Lexer lexer, @NotNull CharSequence text, int start) {
lexer.start(text, start, text.length()) lexer.start(text, start, text.length())
def tokens = [["offset", "state", "text", "type"]] def tokens = [["offset", "state", "text", "type"]]
def tokenType def tokenType

View File

@@ -4,6 +4,7 @@ import com.intellij.lexer.Lexer;
import com.intellij.testFramework.LexerTestCase; import com.intellij.testFramework.LexerTestCase;
import com.jetbrains.performancePlugin.TestUtil; import com.jetbrains.performancePlugin.TestUtil;
import com.jetbrains.performancePlugin.lang.IJPerfFileType; import com.jetbrains.performancePlugin.lang.IJPerfFileType;
import org.jetbrains.annotations.NotNull;
public class IJPerfLexerTest extends LexerTestCase { public class IJPerfLexerTest extends LexerTestCase {
@@ -60,12 +61,12 @@ public class IJPerfLexerTest extends LexerTestCase {
} }
@Override @Override
protected Lexer createLexer() { protected @NotNull Lexer createLexer() {
return new IJPerfLexerAdapter(); return new IJPerfLexerAdapter();
} }
@Override @Override
protected String getDirPath() { protected @NotNull String getDirPath() {
return TestUtil.getDataSubPath("lexer"); return TestUtil.getDataSubPath("lexer");
} }
} }

View File

@@ -11,18 +11,18 @@ import java.util.List;
public class ShFileLexerTest extends LexerTestCase { public class ShFileLexerTest extends LexerTestCase {
@Override @Override
protected Lexer createLexer() { protected @NotNull Lexer createLexer() {
return new ShLexer(); return new ShLexer();
} }
@Override @Override
protected String getDirPath() { protected @NotNull String getDirPath() {
return PluginPathManager.getPluginHomePath("sh") + "/core/testData/lexer"; return PluginPathManager.getPluginHomePath("sh") + "/core/testData/lexer";
} }
@NotNull @NotNull
@Override @Override
protected String getPathToTestDataFile(String extension) { protected String getPathToTestDataFile(@NotNull String extension) {
return getDirPath() + "/" + getTestName(true) + extension; return getDirPath() + "/" + getTestName(true) + extension;
} }
@@ -55,7 +55,7 @@ public class ShFileLexerTest extends LexerTestCase {
public void testIdea278953() { doFileTest("sh"); } // IDEA-278953 public void testIdea278953() { doFileTest("sh"); } // IDEA-278953
@Override @Override
protected void doFileTest(String fileExt) { protected void doFileTest(@NotNull String fileExt) {
super.doFileTest(fileExt); super.doFileTest(fileExt);
String text = loadTestDataFile("." + fileExt); String text = loadTestDataFile("." + fileExt);
checkCorrectRestart(text); checkCorrectRestart(text);

View File

@@ -8,18 +8,18 @@ import org.jetbrains.annotations.NotNull;
public class ShOldLexerVersion3Test extends LexerTestCase { public class ShOldLexerVersion3Test extends LexerTestCase {
@Override @Override
protected Lexer createLexer() { protected @NotNull Lexer createLexer() {
return new ShLexer(); return new ShLexer();
} }
@Override @Override
protected String getDirPath() { protected @NotNull String getDirPath() {
return PluginPathManager.getPluginHomePath("sh") + "/core/testData/oldLexer/v3"; return PluginPathManager.getPluginHomePath("sh") + "/core/testData/oldLexer/v3";
} }
@NotNull @NotNull
@Override @Override
protected String getPathToTestDataFile(String extension) { protected String getPathToTestDataFile(@NotNull String extension) {
return getDirPath() + "/" + getTestName(true) + extension; return getDirPath() + "/" + getTestName(true) + extension;
} }

View File

@@ -8,18 +8,18 @@ import com.intellij.openapi.application.PluginPathManager;
public class ShOldLexerVersion4Test extends LexerTestCase { public class ShOldLexerVersion4Test extends LexerTestCase {
@Override @Override
protected Lexer createLexer() { protected @NotNull Lexer createLexer() {
return new ShLexer(); return new ShLexer();
} }
@Override @Override
protected String getDirPath() { protected @NotNull String getDirPath() {
return PluginPathManager.getPluginHomePath("sh") + "/core/testData/oldLexer/v4"; return PluginPathManager.getPluginHomePath("sh") + "/core/testData/oldLexer/v4";
} }
@NotNull @NotNull
@Override @Override
protected String getPathToTestDataFile(String extension) { protected String getPathToTestDataFile(@NotNull String extension) {
return getDirPath() + "/" + getTestName(true) + extension; return getDirPath() + "/" + getTestName(true) + extension;
} }

View File

@@ -18,15 +18,16 @@ package org.intellij.lang.xpath;
import com.intellij.lexer.Lexer; import com.intellij.lexer.Lexer;
import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.PathManager;
import com.intellij.testFramework.LexerTestCase; import com.intellij.testFramework.LexerTestCase;
import org.jetbrains.annotations.NotNull;
public class XPath2LexerTest extends LexerTestCase { public class XPath2LexerTest extends LexerTestCase {
@Override @Override
protected Lexer createLexer() { protected @NotNull Lexer createLexer() {
return XPathLexer.create(true); return XPathLexer.create(true);
} }
@Override @Override
protected String getDirPath() { protected @NotNull String getDirPath() {
return TestBase.getTestDataPath("xpath2/parsing/lexer").substring(PathManager.getHomePath().length()); return TestBase.getTestDataPath("xpath2/parsing/lexer").substring(PathManager.getHomePath().length());
} }

View File

@@ -18,15 +18,16 @@ package org.intellij.lang.xpath;
import com.intellij.lexer.Lexer; import com.intellij.lexer.Lexer;
import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.PathManager;
import com.intellij.testFramework.LexerTestCase; import com.intellij.testFramework.LexerTestCase;
import org.jetbrains.annotations.NotNull;
public class XPathLexerTest extends LexerTestCase { public class XPathLexerTest extends LexerTestCase {
@Override @Override
protected Lexer createLexer() { protected @NotNull Lexer createLexer() {
return XPathLexer.create(false); return XPathLexer.create(false);
} }
@Override @Override
protected String getDirPath() { protected @NotNull String getDirPath() {
return TestBase.getTestDataPath("xpath/parsing/lexer").substring(PathManager.getHomePath().length()); return TestBase.getTestDataPath("xpath/parsing/lexer").substring(PathManager.getHomePath().length());
} }

View File

@@ -5,22 +5,23 @@ import com.intellij.lexer.Lexer;
import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.ex.PathManagerEx; import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.testFramework.LexerTestCase; import com.intellij.testFramework.LexerTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class YAMLLexerTest extends LexerTestCase { public class YAMLLexerTest extends LexerTestCase {
@Override @Override
protected Lexer createLexer() { protected @NotNull Lexer createLexer() {
return new YAMLFlexLexer(); return new YAMLFlexLexer();
} }
@Override @Override
protected void doTest(String text, @Nullable String expected) { protected void doTest(@NotNull String text, @Nullable String expected) {
super.doTest(text, expected); super.doTest(text, expected);
checkCorrectRestart(text); checkCorrectRestart(text);
} }
@Override @Override
protected String getDirPath() { protected @NotNull String getDirPath() {
return (PathManagerEx.getCommunityHomePath() + "/plugins/yaml/testSrc/org/jetbrains/yaml/lexer/data/") return (PathManagerEx.getCommunityHomePath() + "/plugins/yaml/testSrc/org/jetbrains/yaml/lexer/data/")
.substring(PathManager.getHomePath().length()); .substring(PathManager.getHomePath().length());
} }

View File

@@ -15,17 +15,17 @@ import java.io.IOException;
public class XmlLexerTest extends LexerTestCase { public class XmlLexerTest extends LexerTestCase {
@Override @Override
protected Lexer createLexer() { protected @NotNull Lexer createLexer() {
return new XmlLexer(); return new XmlLexer();
} }
@Override @Override
protected String getDirPath() { protected @NotNull String getDirPath() {
return "/xml/tests/testData/lexer/xml"; return "/xml/tests/testData/lexer/xml";
} }
@Override @Override
protected @NotNull String getPathToTestDataFile(String extension) { protected @NotNull String getPathToTestDataFile(@NotNull String extension) {
return PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/') + "/" + getDirPath() + "/" + getTestName(true) + extension; return PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/') + "/" + getDirPath() + "/" + getTestName(true) + extension;
} }