mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup parsing tests
GitOrigin-RevId: 71f5f773d752513d53d7a50a3b8136814061b6d1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
836412ee0c
commit
5ceb77bfce
+9
-6
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.parser;
|
||||
|
||||
import com.intellij.PathJavaTestUtil;
|
||||
@@ -59,7 +59,8 @@ public abstract class AbstractBasicJavaParsingTestCase extends ParsingTestCase {
|
||||
protected void doParserTest(BasicJavaParserUtil.@NotNull ParserWrapper parser) {
|
||||
String name = getTestName(false);
|
||||
try {
|
||||
doParserTest(loadFile(name + "." + myFileExt), parser);
|
||||
String text = loadFile(name + "." + myFileExt);
|
||||
doParserTest(text, parser);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -71,16 +72,18 @@ public abstract class AbstractBasicJavaParsingTestCase extends ParsingTestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkResult(@NotNull @TestDataFile String targetDataName, @NotNull PsiFile file) throws IOException {
|
||||
protected void checkResult(@NotNull @TestDataFile String targetDataName,
|
||||
@NotNull PsiFile file) throws IOException {
|
||||
if (myConfigurator.checkPsi()) {
|
||||
super.checkResult(targetDataName, file);
|
||||
}
|
||||
|
||||
doCheckResult(myFullDataPath, targetDataName + "_node.txt",
|
||||
DebugUtil.nodeTreeAsElementTypeToString(file.getNode(), !skipSpaces()).trim());
|
||||
String treeDump = DebugUtil.nodeTreeAsElementTypeToString(file.getNode(), !skipSpaces()).trim();
|
||||
doCheckResult(myFullDataPath, targetDataName + "_node.txt", treeDump);
|
||||
}
|
||||
|
||||
protected void doParserTest(String text, BasicJavaParserUtil.@NotNull ParserWrapper parser) {
|
||||
protected void doParserTest(@NotNull String text,
|
||||
BasicJavaParserUtil.@NotNull ParserWrapper parser) {
|
||||
String name = getTestName(false);
|
||||
myFile = myConfigurator.createPsiFile(this, name, text, parser);
|
||||
try {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.parser;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.java.frontback.psi.impl.syntax.JavaSyntaxDefinitionExtension;
|
||||
import com.intellij.lang.*;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.LanguageASTFactory;
|
||||
import com.intellij.lang.LanguageExtension;
|
||||
import com.intellij.lang.ParserDefinition;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.lang.java.JavaParserDefinition;
|
||||
import com.intellij.lang.java.parser.BasicJavaParserUtil;
|
||||
@@ -74,19 +77,16 @@ public class JavaParsingTestConfigurator implements AbstractBasicJavaParsingTest
|
||||
private static LanguageLevel LANGUAGE_LEVEL;
|
||||
|
||||
@Override
|
||||
public @NotNull PsiFile createPsiFile(@NotNull AbstractBasicJavaParsingTestCase thinJavaParsingTestCase, @NotNull String name, @NotNull String text, BasicJavaParserUtil.@NotNull ParserWrapper parser) {
|
||||
public @NotNull PsiFile createPsiFile(@NotNull AbstractBasicJavaParsingTestCase thinJavaParsingTestCase,
|
||||
@NotNull String name,
|
||||
@NotNull String text,
|
||||
BasicJavaParserUtil.@NotNull ParserWrapper parser) {
|
||||
TEST_PARSER = parser;
|
||||
|
||||
LightVirtualFile virtualFile = new LightVirtualFile(name + '.' + "java", JavaFileType.INSTANCE, text, -1);
|
||||
FileViewProvider viewProvider =
|
||||
new SingleRootFileViewProvider(PsiManager.getInstance(thinJavaParsingTestCase.getProject()), virtualFile, true);
|
||||
PsiJavaFileImpl file = new PsiJavaFileImpl(viewProvider) {
|
||||
@NotNull
|
||||
@Override
|
||||
protected FileElement createFileElement(@NotNull CharSequence text) {
|
||||
return new FileElement(myTestFileElementType, text);
|
||||
}
|
||||
};
|
||||
PsiManager psiManager = PsiManager.getInstance(thinJavaParsingTestCase.getProject());
|
||||
FileViewProvider viewProvider = new SingleRootFileViewProvider(psiManager, virtualFile, true);
|
||||
PsiJavaFileImpl file = new MyTestPsiJavaFileImpl(viewProvider);
|
||||
configure(file);
|
||||
return file;
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public class JavaParsingTestConfigurator implements AbstractBasicJavaParsingTest
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static class MyIFileElementType extends IFileElementType {
|
||||
private static final class MyIFileElementType extends IFileElementType {
|
||||
MyIFileElementType() {
|
||||
super("test.java.file", JavaLanguage.INSTANCE);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class JavaParsingTestConfigurator implements AbstractBasicJavaParsingTest
|
||||
}
|
||||
}
|
||||
|
||||
private static class JavaTestElementTypeConverterExtension implements ElementTypeConverterFactory {
|
||||
private static final class JavaTestElementTypeConverterExtension implements ElementTypeConverterFactory {
|
||||
private static final @NotNull ElementTypeConverter CONVERTER =
|
||||
ElementTypeConverterKt.elementTypeConverterOf(new Pair<>(mySyntaxElementType, myTestFileElementType));
|
||||
|
||||
@@ -139,4 +139,14 @@ public class JavaParsingTestConfigurator implements AbstractBasicJavaParsingTest
|
||||
return CONVERTER;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class MyTestPsiJavaFileImpl extends PsiJavaFileImpl {
|
||||
private MyTestPsiJavaFileImpl(@NotNull FileViewProvider viewProvider) { super(viewProvider); }
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected FileElement createFileElement(@NotNull CharSequence text) {
|
||||
return new FileElement(myTestFileElementType, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,7 +304,8 @@ public abstract class ParsingTestCase extends UsefulTestCase {
|
||||
protected void doTest(boolean checkResult, boolean ensureNoErrorElements) {
|
||||
String name = getTestName();
|
||||
try {
|
||||
parseFile(name, loadFile(name + "." + myFileExt));
|
||||
String text = loadFile(name + "." + myFileExt);
|
||||
parseFile(name, text);
|
||||
if (checkResult) {
|
||||
checkResult(name, myFile);
|
||||
if (ensureNoErrorElements) {
|
||||
@@ -320,7 +321,7 @@ public abstract class ParsingTestCase extends UsefulTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
protected PsiFile parseFile(String name, String text) {
|
||||
protected @NotNull PsiFile parseFile(@NotNull String name, @NotNull String text) {
|
||||
myFile = createPsiFile(name, text);
|
||||
assertEquals("light virtual file text mismatch", text, ((LightVirtualFile)myFile.getVirtualFile()).getContent().toString());
|
||||
assertEquals("virtual file text mismatch", text, LoadTextUtil.loadText(myFile.getVirtualFile()));
|
||||
@@ -546,14 +547,14 @@ public abstract class ParsingTestCase extends UsefulTestCase {
|
||||
|
||||
public static void doCheckResult(@NotNull String fullPath, @NotNull String targetDataName, @NotNull String actual) {
|
||||
String expectedFileName = fullPath + File.separatorChar + targetDataName;
|
||||
UsefulTestCase.assertSameLinesWithFile(expectedFileName, actual);
|
||||
assertSameLinesWithFile(expectedFileName, actual);
|
||||
}
|
||||
|
||||
protected static String toParseTreeText(@NotNull PsiElement file, boolean skipSpaces, boolean printRanges) {
|
||||
return DebugUtil.psiToString(file, !skipSpaces, printRanges);
|
||||
}
|
||||
|
||||
protected String loadFile(@NotNull @TestDataFile String name) throws IOException {
|
||||
protected @NotNull String loadFile(@NotNull @TestDataFile String name) throws IOException {
|
||||
return loadFileDefault(myFullDataPath, name);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user