void () { final PsiJavaFile file = (PsiJavaFile)myFixture.addFileToProject("a.java", "class A{}"); PsiClass aClass = file.getClasses()[0]; assertNotNull(aClass.getNode()); assertNotNull(PsiDocumentManager.getInstance(getProject()).getCachedDocument(file)); GCWatcher.tracking(PsiDocumentManager.getInstance(getProject()).getCachedDocument(file)).ensureCollected(); assertNull(PsiDocumentManager.getInstance(getProject()).getCachedDocument(file)); aClass.add(JavaPsiFacade.getElementFactory(getProject()).createMethodFromText("void foo(){}", null)); assertNotNull(PsiDocumentManager.getInstance(getProject()).getCachedDocument(file)); PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting(); assertTrue(file.getText(), file.getText().contains("foo() {\n")); } public void testAfterPsiModificationPsiDocumentStampsAreSame() { PsiJavaFile file = (PsiJavaFile)myFixture.addFileToProject("a.java", "class A{public static void foo() { }}"); PsiClass aClass = file.getClasses()[0]; GCWatcher.tracking(aClass.getNode()).ensureCollected(); PsiKeyword kw = assertInstanceOf(aClass.getMethods()[0].getModifierList().getFirstChild(), PsiKeyword.class); kw.delete(); Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file); assertNotNull(document); assertTrue(document.getModificationStamp() != file.getVirtualFile().getModificationStamp()); assertEquals(document.getModificationStamp(), file.getViewProvider().getModificationStamp()); FileDocumentManager.getInstance().saveDocument(document); assertEquals(file.getText(), LoadTextUtil.loadText(file.getVirtualFile()).toString()); } public void testPsiClassMethodsCantBeModified() { PsiClass psiClass = myFixture.addClass("class Foo { " + "Foo() {} " + "void bar() {} " + "void goo() {} " + "void goo42() {} " + "}"); PsiMethod[] golden = psiClass.getMethods().clone(); PsiMethod[] mutated = psiClass.getMethods(); mutated[0] = mutated[1]; mutated[2] = null; assertOrderedEquals(psiClass.getMethods(), golden); } public void testRecoverAfterPsiDocSyncError() throws IOException { VirtualFile vFile = myFixture.addFileToProject("a.java", "class A{}").getVirtualFile(); try { myFixture.findClass("A").replace(JavaPsiFacade.getElementFactory(getProject()).createClassFromText("class B {\r\n}", null)); fail("Should fail"); } catch (Throwable e) { assertTrue(e.getMessage(), e.getMessage().contains("Wrong line separators")); } assertEquals("class A{}", getPsiManager().findFile(vFile).getText()); VfsUtil.saveText(vFile, "class C {}"); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); PsiClass c = myFixture.findClass("C"); assertNotNull(c); assertEquals(vFile, c.getContainingFile().getVirtualFile()); } public void testResolveCacheInvalidatedOnFilePropertyChange() { VirtualFile foo = myFixture.addFileToProject("Foo.java", "class Foo {}").getVirtualFile(); PsiClass bar = myFixture.addClass("class Bar extends Foo {}"); assertEquals("Foo", bar.getSuperClass().getName()); PsiUtilCore.ensureValid(bar.getSuperClass()); PushedFilePropertiesUpdater.getInstance(getProject()).filePropertiesChanged(foo, Conditions.alwaysTrue()); assertEquals("Foo", bar.getSuperClass().getName()); PsiUtilCore.ensureValid(bar.getSuperClass()); } public void testLoadingNodeDuringCommitWithoutReparse_Stress() { // it's a stress test to disable test checks that load file content prematurely (AbstractFileViewProvider.checkLengthConsistency) PsiFile file = myFixture.addFileToProject("a.java", "class Foo {}"); myFixture.getPsiManager().addPsiTreeChangeListener(new PsiTreeChangeAdapter() { @Override public void childrenChanged(@NotNull PsiTreeChangeEvent event) { PsiElement parent = event.getParent(); if (parent == file) { assertNotNull(file.getNode()); } } }, getTestRootDisposable()); WriteCommandAction.runWriteCommandAction(getProject(), () -> { Document document = file.getViewProvider().getDocument(); document.insertString(0, " "); PsiDocumentManager.getInstance(getProject()).commitDocument(document); }); assertEquals(" class Foo {}", file.getText()); } public void testGenericLightMethodBuilderEquivalence() { Factory<PsiMethod> createMethod = () -> { LightMethodBuilder method = new LightMethodBuilder(getPsiManager(), "foo"); LightTypeParameterBuilder typeParam = new LightTypeParameterBuilder("T", method, 0); method.addTypeParameter(typeParam); PsiClassType tType = JavaPsiFacade.getElementFactory(getProject()).createType(typeParam); method.setMethodReturnType(tType); method.addParameter("p", tType); return method; }; assertTrue(getPsiManager().areElementsEquivalent(createMethod.create(), createMethod.create())); } public void testFoundPackageIsValid() { assertTrue(myFixture.findPackage("org.apache").isValid()); } }