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.testFramework.LexerTestCase;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.EnumSet;
@@ -860,12 +861,12 @@ public class RegExpLexerTest extends LexerTestCase {
}
@Override
protected Lexer createLexer() {
protected @NotNull Lexer createLexer() {
return null;
}
@Override
protected String getDirPath() {
protected @NotNull String getDirPath() {
if (new File(getHomePath(), "community/RegExpSupport").isDirectory()) {
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.lexer.Lexer;
import com.intellij.testFramework.LexerTestCase;
import org.jetbrains.annotations.NotNull;
public class FileTemplateLexerTest extends LexerTestCase {
@@ -36,12 +37,12 @@ public class FileTemplateLexerTest extends LexerTestCase {
}
@Override
protected Lexer createLexer() {
protected @NotNull Lexer createLexer() {
return FileTemplateConfigurable.createDefaultLexer();
}
@Override
protected String getDirPath() {
protected @NotNull String getDirPath() {
return null;
}
}

View File

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

View File

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

View File

@@ -22,15 +22,15 @@ import java.util.Objects;
import java.util.stream.Collectors;
public abstract class LexerTestCase extends UsefulTestCase {
protected void doTest(String text) {
protected void doTest(@NotNull String text) {
doTest(text, null);
}
protected void doTest(String text, @Nullable String expected) {
protected void doTest(@NotNull String text, @Nullable String expected) {
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);
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);
}
@NotNull
protected String getPathToTestDataFile(String extension) {
protected String getPathToTestDataFile(@NotNull String extension) {
return IdeaTestExecutionPolicy.getHomePathWithPolicy() + "/" + getDirPath() + "/" + getTestName(true) + extension;
}
@@ -55,7 +55,7 @@ public abstract class LexerTestCase extends UsefulTestCase {
return ".txt";
}
protected void checkZeroState(String text, TokenSet tokenTypes) {
protected void checkZeroState(@NotNull String text, TokenSet tokenTypes) {
Lexer lexer = createLexer();
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());
}
@@ -123,7 +123,7 @@ public abstract class LexerTestCase extends UsefulTestCase {
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());
StringBuilder result = new StringBuilder();
IElementType tokenType;
@@ -147,11 +147,11 @@ public abstract class LexerTestCase extends UsefulTestCase {
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";
}
protected void doFileTest(String fileExt) {
protected void doFileTest(@NotNull String fileExt) {
doTest(loadTestDataFile("." + fileExt));
}
@@ -180,7 +180,7 @@ public abstract class LexerTestCase extends UsefulTestCase {
: 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
class GroovyLexerTest extends LexerTestCase {
@NotNull
@Override
protected Lexer createLexer() {
new GroovyLexer()
}
@NotNull
@Override
protected String getDirPath() {
TestUtils.testDataPath + "lexer"
@@ -35,13 +37,13 @@ class GroovyLexerTest extends LexerTestCase {
}
@Override
protected void doTest(@NonNls String text) {
protected void doTest(@NotNull @NonNls String text) {
super.doTest(text)
checkCorrectRestart(text)
}
@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())
def tokens = [["offset", "state", "text", "type"]]
def tokenType

View File

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

View File

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

View File

@@ -8,18 +8,18 @@ import org.jetbrains.annotations.NotNull;
public class ShOldLexerVersion3Test extends LexerTestCase {
@Override
protected Lexer createLexer() {
protected @NotNull Lexer createLexer() {
return new ShLexer();
}
@Override
protected String getDirPath() {
protected @NotNull String getDirPath() {
return PluginPathManager.getPluginHomePath("sh") + "/core/testData/oldLexer/v3";
}
@NotNull
@Override
protected String getPathToTestDataFile(String extension) {
protected String getPathToTestDataFile(@NotNull String extension) {
return getDirPath() + "/" + getTestName(true) + extension;
}
@@ -42,11 +42,11 @@ public class ShOldLexerVersion3Test extends LexerTestCase {
public void testSquareBracketArithmeticExpr() {
doFileTest("sh");
}
public void testArithmeticExpr() {
doFileTest("sh");
}
public void testLetExpressions() {
doFileTest("sh");
}
@@ -58,7 +58,7 @@ public class ShOldLexerVersion3Test extends LexerTestCase {
public void testIdentifier() {
doFileTest("sh");
}
public void testStrings() {
doFileTest("sh");
}
@@ -98,7 +98,7 @@ public class ShOldLexerVersion3Test extends LexerTestCase {
public void testVariable() {
doFileTest("sh");
}
public void testRedirect1() {
doFileTest("sh");
}
@@ -114,27 +114,27 @@ public class ShOldLexerVersion3Test extends LexerTestCase {
public void testParameterSubstitution() {
doFileTest("sh");
}
public void testWeirdStuff1() {
doFileTest("sh");
}
public void testCaseWhitespacePattern() {
doFileTest("sh");
}
public void testNestedCase() {
doFileTest("sh");
}
public void testBackquote1() {
doFileTest("sh");
}
public void testCasePattern() {
doFileTest("sh");
}
public void testAssignmentList() {
doFileTest("sh");
}
@@ -146,7 +146,7 @@ public class ShOldLexerVersion3Test extends LexerTestCase {
public void testNestedStatements() {
doFileTest("sh");
}
public void testV4Lexing() {
doFileTest("sh");
}
@@ -154,7 +154,7 @@ public class ShOldLexerVersion3Test extends LexerTestCase {
public void testParamExpansionNested() {
doFileTest("sh");
}
public void testParamExpansion() {
doFileTest("sh");
}
@@ -162,11 +162,11 @@ public class ShOldLexerVersion3Test extends LexerTestCase {
public void testArithmeticLiterals() {
doFileTest("sh");
}
public void testReadCommand() {
doFileTest("sh");
}
public void testUmlaut() {
doFileTest("sh");
}
@@ -218,7 +218,7 @@ public class ShOldLexerVersion3Test extends LexerTestCase {
public void testIssue272() {
doFileTest("sh");
}
public void testIssue300() {
doFileTest("sh");
}
@@ -238,7 +238,7 @@ public class ShOldLexerVersion3Test extends LexerTestCase {
public void testIssue320() {
doFileTest("sh");
}
public void testIssue325() {
doFileTest("sh");
}
@@ -246,19 +246,19 @@ public class ShOldLexerVersion3Test extends LexerTestCase {
public void testIssue327() {
doFileTest("sh");
}
public void testIssue330() {
doFileTest("sh");
}
public void testIssue330Var() {
doFileTest("sh");
}
public void testIssue341() {
doFileTest("sh");
}
public void testIssue343() {
doFileTest("sh");
}
@@ -266,7 +266,7 @@ public class ShOldLexerVersion3Test extends LexerTestCase {
public void testIssue354() {
doFileTest("sh");
}
public void testIssue389() {
doFileTest("sh");
}
@@ -274,7 +274,7 @@ public class ShOldLexerVersion3Test extends LexerTestCase {
public void testTrapLexing() {
doFileTest("sh");
}
public void testEvalLexing() {
doFileTest("sh");
}
@@ -286,7 +286,7 @@ public class ShOldLexerVersion3Test extends LexerTestCase {
public void testIssue367() {
doFileTest("sh");
}
public void testIssue418() {
doFileTest("sh");
}
@@ -302,7 +302,7 @@ public class ShOldLexerVersion3Test extends LexerTestCase {
public void testLineContinuation() {
doFileTest("sh");
}
public void testIssue358() {
doFileTest("sh");
}
@@ -330,11 +330,11 @@ public class ShOldLexerVersion3Test extends LexerTestCase {
public void testIssue458() {
doFileTest("sh");
}
public void testIssue469() {
doFileTest("sh");
}
public void testIssue474() {
doFileTest("sh");
}

View File

@@ -8,18 +8,18 @@ import com.intellij.openapi.application.PluginPathManager;
public class ShOldLexerVersion4Test extends LexerTestCase {
@Override
protected Lexer createLexer() {
protected @NotNull Lexer createLexer() {
return new ShLexer();
}
@Override
protected String getDirPath() {
protected @NotNull String getDirPath() {
return PluginPathManager.getPluginHomePath("sh") + "/core/testData/oldLexer/v4";
}
@NotNull
@Override
protected String getPathToTestDataFile(String extension) {
protected String getPathToTestDataFile(@NotNull String 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.openapi.application.PathManager;
import com.intellij.testFramework.LexerTestCase;
import org.jetbrains.annotations.NotNull;
public class XPath2LexerTest extends LexerTestCase {
@Override
protected Lexer createLexer() {
protected @NotNull Lexer createLexer() {
return XPathLexer.create(true);
}
@Override
protected String getDirPath() {
protected @NotNull String getDirPath() {
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.openapi.application.PathManager;
import com.intellij.testFramework.LexerTestCase;
import org.jetbrains.annotations.NotNull;
public class XPathLexerTest extends LexerTestCase {
@Override
protected Lexer createLexer() {
protected @NotNull Lexer createLexer() {
return XPathLexer.create(false);
}
@Override
protected String getDirPath() {
protected @NotNull String getDirPath() {
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.ex.PathManagerEx;
import com.intellij.testFramework.LexerTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class YAMLLexerTest extends LexerTestCase {
@Override
protected Lexer createLexer() {
protected @NotNull Lexer createLexer() {
return new YAMLFlexLexer();
}
@Override
protected void doTest(String text, @Nullable String expected) {
protected void doTest(@NotNull String text, @Nullable String expected) {
super.doTest(text, expected);
checkCorrectRestart(text);
}
@Override
protected String getDirPath() {
protected @NotNull String getDirPath() {
return (PathManagerEx.getCommunityHomePath() + "/plugins/yaml/testSrc/org/jetbrains/yaml/lexer/data/")
.substring(PathManager.getHomePath().length());
}

View File

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