mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PsiTestUtil.checkStubsMatchText
This commit is contained in:
-45
@@ -37,20 +37,13 @@ import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.psi.impl.DebugUtil;
|
||||
import com.intellij.psi.impl.source.PsiFileImpl;
|
||||
import com.intellij.psi.search.FilenameIndex;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.stubs.StubTree;
|
||||
import com.intellij.testFramework.CompilerTester;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.testFramework.TestDataProvider;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import slowCheck.Generator;
|
||||
|
||||
import java.io.File;
|
||||
@@ -164,42 +157,4 @@ public abstract class AbstractApplyAndRevertTestCase extends PlatformTestCase {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
protected void checkPsiWellFormed(PsiFile file) {
|
||||
PsiFile copy = PsiFileFactory.getInstance(myProject).createFileFromText(file.getName(), file.getLanguage(), file.getText());
|
||||
assertEquals(DebugUtil.psiTreeToString(copy, false), DebugUtil.psiTreeToString(file, false));
|
||||
|
||||
Document document = file.getViewProvider().getDocument();
|
||||
if (!PsiDocumentManager.getInstance(myProject).isCommitted(document)) {
|
||||
PsiDocumentManager.getInstance(myProject).commitDocument(document);
|
||||
checkPsiWellFormed(file);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void checkStubPsiWellFormed(@NotNull PsiFile file) {
|
||||
Project project = file.getProject();
|
||||
|
||||
StubTree tree = getStubTree(file);
|
||||
StubTree copyTree = getStubTree(
|
||||
PsiFileFactory.getInstance(project).createFileFromText(file.getName(), file.getLanguage(), file.getText()));
|
||||
if (tree == null || copyTree == null) return;
|
||||
|
||||
assertEquals(DebugUtil.stubTreeToString(copyTree.getRoot()), DebugUtil.stubTreeToString(tree.getRoot()));
|
||||
|
||||
Document document = file.getViewProvider().getDocument();
|
||||
assert document != null;
|
||||
if (!PsiDocumentManager.getInstance(project).isCommitted(document)) {
|
||||
PsiDocumentManager.getInstance(project).commitDocument(document);
|
||||
checkStubPsiWellFormed(file);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static StubTree getStubTree(PsiFile file) {
|
||||
if (!(file instanceof PsiFileImpl)) return null;
|
||||
if (((PsiFileImpl)file).getElementTypeForStubBuilder() == null) return null;
|
||||
|
||||
StubTree tree = ((PsiFileImpl)file).getStubTree();
|
||||
return tree != null ? tree : ((PsiFileImpl)file).calcStubTree();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -24,6 +24,7 @@ import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -147,7 +148,7 @@ public class ApplyRandomIntentionsTest extends AbstractApplyAndRevertTestCase {
|
||||
assertFalse("Document is left blocked by PSI", documentManager.isDocumentBlockedByPsi(document));
|
||||
checkNoForeignDocuments(document, documentManager.getUncommittedDocuments());
|
||||
checkNoForeignDocuments(document, FileDocumentManager.getInstance().getUnsavedDocuments());
|
||||
checkStubPsiWellFormed(psiFile);
|
||||
PsiTestUtil.checkStubsMatchText(psiFile);
|
||||
if (psiFile.textMatches(currentFileText)) {
|
||||
fail("No change was performed: " + currentFileText);
|
||||
}
|
||||
|
||||
+2
-1
@@ -29,6 +29,7 @@ import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -94,7 +95,7 @@ public class CompletionConsistencyTest extends AbstractApplyAndRevertTestCase {
|
||||
|
||||
try {
|
||||
performCompletion(editor, i == 0, invocation, leaf);
|
||||
checkStubPsiWellFormed(psiFile);
|
||||
PsiTestUtil.checkStubsMatchText(psiFile);
|
||||
}
|
||||
finally {
|
||||
LookupManager.getInstance(myProject).hideActiveLookup();
|
||||
|
||||
@@ -15,8 +15,12 @@
|
||||
*/
|
||||
package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.openapi.application.*;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.RunResult;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.module.ModifiableModuleModel;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
@@ -37,6 +41,8 @@ import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.psi.impl.DebugUtil;
|
||||
import com.intellij.psi.impl.source.PsiFileImpl;
|
||||
import com.intellij.psi.stubs.StubTree;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
@@ -395,4 +401,35 @@ public class PsiTestUtil {
|
||||
sdkModificator.commitChanges();
|
||||
return clone;
|
||||
}
|
||||
|
||||
public static void checkStubsMatchText(@NotNull PsiFile file) {
|
||||
Project project = file.getProject();
|
||||
|
||||
StubTree tree = getStubTree(file);
|
||||
StubTree copyTree = getStubTree(
|
||||
PsiFileFactory.getInstance(project).createFileFromText(file.getName(), file.getLanguage(), file.getText()));
|
||||
if (tree == null || copyTree == null) return;
|
||||
|
||||
String fromText = DebugUtil.stubTreeToString(copyTree.getRoot());
|
||||
String fromPsi = DebugUtil.stubTreeToString(tree.getRoot());
|
||||
if (!fromText.equals(fromPsi)) {
|
||||
Assert.assertEquals("Re-created from text:\n" + fromText, "Stubs from PSI structure:\n" + fromPsi);
|
||||
}
|
||||
|
||||
Document document = file.getViewProvider().getDocument();
|
||||
assert document != null;
|
||||
if (!PsiDocumentManager.getInstance(project).isCommitted(document)) {
|
||||
PsiDocumentManager.getInstance(project).commitDocument(document);
|
||||
checkStubsMatchText(file);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static StubTree getStubTree(PsiFile file) {
|
||||
if (!(file instanceof PsiFileImpl)) return null;
|
||||
if (((PsiFileImpl)file).getElementTypeForStubBuilder() == null) return null;
|
||||
|
||||
StubTree tree = ((PsiFileImpl)file).getStubTree();
|
||||
return tree != null ? tree : ((PsiFileImpl)file).calcStubTree();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user