From 1d3e210cc4afe5e3892c5ff5fb87f2eedfd39547 Mon Sep 17 00:00:00 2001 From: Piotr Tomiak Date: Wed, 12 Jul 2023 15:44:52 +0200 Subject: [PATCH] LexerTestCase: add missing @NotNull annotations to improve interoperability with Kotlin GitOrigin-RevId: e98b6523585f4659687abca687c8b42618dfd8bc --- .../intellij/lang/regexp/RegExpLexerTest.java | 5 +- .../impl/FileTemplateLexerTest.java | 5 +- .../intellij/java/lexer/JavaLexerTest.java | 5 +- .../test/com/intellij/json/JsonLexerTest.java | 5 +- .../intellij/testFramework/LexerTestCase.java | 24 ++++---- .../groovy/lang/parser/GroovyLexerTest.groovy | 6 +- .../lang/lexer/IJPerfLexerTest.java | 5 +- .../intellij/sh/lexer/ShFileLexerTest.java | 8 +-- .../sh/lexer/ShOldLexerVersion3Test.java | 58 +++++++++---------- .../sh/lexer/ShOldLexerVersion4Test.java | 6 +- .../intellij/lang/xpath/XPath2LexerTest.java | 5 +- .../intellij/lang/xpath/XPathLexerTest.java | 5 +- .../jetbrains/yaml/lexer/YAMLLexerTest.java | 7 ++- .../src/com/intellij/xml/XmlLexerTest.java | 6 +- 14 files changed, 80 insertions(+), 70 deletions(-) diff --git a/RegExpSupport/test/org/intellij/lang/regexp/RegExpLexerTest.java b/RegExpSupport/test/org/intellij/lang/regexp/RegExpLexerTest.java index acac6b724794..53acde55f290 100644 --- a/RegExpSupport/test/org/intellij/lang/regexp/RegExpLexerTest.java +++ b/RegExpSupport/test/org/intellij/lang/regexp/RegExpLexerTest.java @@ -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"; } diff --git a/java/java-tests/testSrc/com/intellij/java/ide/fileTemplates/impl/FileTemplateLexerTest.java b/java/java-tests/testSrc/com/intellij/java/ide/fileTemplates/impl/FileTemplateLexerTest.java index 0c87924d473f..2ffc2bc4b47d 100644 --- a/java/java-tests/testSrc/com/intellij/java/ide/fileTemplates/impl/FileTemplateLexerTest.java +++ b/java/java-tests/testSrc/com/intellij/java/ide/fileTemplates/impl/FileTemplateLexerTest.java @@ -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; } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/lexer/JavaLexerTest.java b/java/java-tests/testSrc/com/intellij/java/lexer/JavaLexerTest.java index 8eacdca8b50b..935e8a8ddc55 100644 --- a/java/java-tests/testSrc/com/intellij/java/lexer/JavaLexerTest.java +++ b/java/java-tests/testSrc/com/intellij/java/lexer/JavaLexerTest.java @@ -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 ""; } } \ No newline at end of file diff --git a/json/tests/test/com/intellij/json/JsonLexerTest.java b/json/tests/test/com/intellij/json/JsonLexerTest.java index 4b1d4cc4628b..c76d22f7f4a2 100644 --- a/json/tests/test/com/intellij/json/JsonLexerTest.java +++ b/json/tests/test/com/intellij/json/JsonLexerTest.java @@ -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; } diff --git a/platform/testFramework/src/com/intellij/testFramework/LexerTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LexerTestCase.java index 18ffa24012b8..db18e707b13e 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LexerTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LexerTestCase.java @@ -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(); } \ No newline at end of file diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/GroovyLexerTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/GroovyLexerTest.groovy index 825779182be5..4c3ed76acfc7 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/GroovyLexerTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/GroovyLexerTest.groovy @@ -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 diff --git a/plugins/performanceTesting/testSrc/com/jetbrains/performancePlugin/lang/lexer/IJPerfLexerTest.java b/plugins/performanceTesting/testSrc/com/jetbrains/performancePlugin/lang/lexer/IJPerfLexerTest.java index 0ac3ca174809..945ce31078c2 100644 --- a/plugins/performanceTesting/testSrc/com/jetbrains/performancePlugin/lang/lexer/IJPerfLexerTest.java +++ b/plugins/performanceTesting/testSrc/com/jetbrains/performancePlugin/lang/lexer/IJPerfLexerTest.java @@ -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"); } } \ No newline at end of file diff --git a/plugins/sh/core/tests/com/intellij/sh/lexer/ShFileLexerTest.java b/plugins/sh/core/tests/com/intellij/sh/lexer/ShFileLexerTest.java index c939645bafdd..b0a0b7fa70fd 100644 --- a/plugins/sh/core/tests/com/intellij/sh/lexer/ShFileLexerTest.java +++ b/plugins/sh/core/tests/com/intellij/sh/lexer/ShFileLexerTest.java @@ -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); diff --git a/plugins/sh/core/tests/com/intellij/sh/lexer/ShOldLexerVersion3Test.java b/plugins/sh/core/tests/com/intellij/sh/lexer/ShOldLexerVersion3Test.java index 72eb4765a5f2..03da00f20df7 100644 --- a/plugins/sh/core/tests/com/intellij/sh/lexer/ShOldLexerVersion3Test.java +++ b/plugins/sh/core/tests/com/intellij/sh/lexer/ShOldLexerVersion3Test.java @@ -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"); } diff --git a/plugins/sh/core/tests/com/intellij/sh/lexer/ShOldLexerVersion4Test.java b/plugins/sh/core/tests/com/intellij/sh/lexer/ShOldLexerVersion4Test.java index 4b28e9aacb0e..728694f812f9 100644 --- a/plugins/sh/core/tests/com/intellij/sh/lexer/ShOldLexerVersion4Test.java +++ b/plugins/sh/core/tests/com/intellij/sh/lexer/ShOldLexerVersion4Test.java @@ -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; } diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2LexerTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2LexerTest.java index e0dabc060786..6e7c948770a3 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2LexerTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2LexerTest.java @@ -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()); } diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathLexerTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathLexerTest.java index daf8b7edb02b..213a2098fc2e 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathLexerTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathLexerTest.java @@ -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()); } diff --git a/plugins/yaml/testSrc/org/jetbrains/yaml/lexer/YAMLLexerTest.java b/plugins/yaml/testSrc/org/jetbrains/yaml/lexer/YAMLLexerTest.java index eedaf60e8bc4..74883f76d258 100644 --- a/plugins/yaml/testSrc/org/jetbrains/yaml/lexer/YAMLLexerTest.java +++ b/plugins/yaml/testSrc/org/jetbrains/yaml/lexer/YAMLLexerTest.java @@ -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()); } diff --git a/xml/tests/src/com/intellij/xml/XmlLexerTest.java b/xml/tests/src/com/intellij/xml/XmlLexerTest.java index 3114b49e7f20..3b04d0ad05de 100644 --- a/xml/tests/src/com/intellij/xml/XmlLexerTest.java +++ b/xml/tests/src/com/intellij/xml/XmlLexerTest.java @@ -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; }