当前位置: 首页>>代码示例>>Java>>正文


Java PlatformTestUtil.tryGcSoftlyReachableObjects方法代码示例

本文整理汇总了Java中com.intellij.testFramework.PlatformTestUtil.tryGcSoftlyReachableObjects方法的典型用法代码示例。如果您正苦于以下问题:Java PlatformTestUtil.tryGcSoftlyReachableObjects方法的具体用法?Java PlatformTestUtil.tryGcSoftlyReachableObjects怎么用?Java PlatformTestUtil.tryGcSoftlyReachableObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.testFramework.PlatformTestUtil的用法示例。


在下文中一共展示了PlatformTestUtil.tryGcSoftlyReachableObjects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testASTBecomesInvalidOnExternalChange

import com.intellij.testFramework.PlatformTestUtil; //导入方法依赖的package包/类
public void testASTBecomesInvalidOnExternalChange() {
  final String text = "class A{}";
  final PsiJavaFile file = (PsiJavaFile)myFixture.addFileToProject("a.java", text);
  PsiElement leaf = file.findElementAt(5);

  PlatformTestUtil.tryGcSoftlyReachableObjects();
  assertNull(PsiDocumentManager.getInstance(getProject()).getCachedDocument(file));

  new WriteCommandAction.Simple(getProject()) {
    @Override
    protected void run() throws Throwable {
      VfsUtil.saveText(file.getVirtualFile(), text + "   ");
    }
  }.execute();

  assertTrue(file.isValid());
  assertFalse(leaf.isValid());
  assertNotSame(leaf, file.findElementAt(5));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:MiscPsiTest.java

示例2: testPsiModificationNotAffectingDocument

import com.intellij.testFramework.PlatformTestUtil; //导入方法依赖的package包/类
public void testPsiModificationNotAffectingDocument() {
  final PsiJavaFile file = (PsiJavaFile)myFixture.addFileToProject("a.java", "class A{public static void foo() { }}");

  PsiClass aClass = file.getClasses()[0];
  //noinspection ResultOfMethodCallIgnored
  aClass.getNode();
  PlatformTestUtil.tryGcSoftlyReachableObjects();

  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());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:MiscPsiTest.java

示例3: testClassShouldNotAppearWithoutEvents_WithoutPsi

import com.intellij.testFramework.PlatformTestUtil; //导入方法依赖的package包/类
public void testClassShouldNotAppearWithoutEvents_WithoutPsi() throws IOException {
  final GlobalSearchScope allScope = GlobalSearchScope.allScope(getProject());
  final JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject());
  final PsiManager psiManager = PsiManager.getInstance(getProject());
  final PsiModificationTracker tracker = psiManager.getModificationTracker();

  final VirtualFile file = myFixture.getTempDirFixture().createFile("Foo.java", "");
  final Document document = FileDocumentManager.getInstance().getDocument(file);
  assertNotNull(document);
  assertNull(facade.findClass("Foo", allScope));
  long count1 = tracker.getJavaStructureModificationCount();

  PlatformTestUtil.tryGcSoftlyReachableObjects();
  assertNull(PsiDocumentManager.getInstance(getProject()).getCachedPsiFile(document));

  document.insertString(0, "class Foo {}");

  assertFalse(count1 == tracker.getJavaStructureModificationCount());
  assertTrue(PsiDocumentManager.getInstance(getProject()).isCommitted(document));
  assertNotNull(facade.findClass("Foo", allScope));

  PsiJavaFile psiFile = (PsiJavaFile)psiManager.findFile(file);
  assertSize(1, psiFile.getClasses());
  assertEquals("class Foo {}", psiFile.getText());
  assertEquals("class Foo {}", psiFile.getNode().getText());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:PsiModificationTrackerTest.java

示例4: testClassShouldNotDisappearWithoutEvents_NoDocument

import com.intellij.testFramework.PlatformTestUtil; //导入方法依赖的package包/类
public void testClassShouldNotDisappearWithoutEvents_NoDocument() throws IOException {
  PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
  final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject());

  final VirtualFile file = myFixture.addFileToProject("Foo.java", "class Foo {}").getVirtualFile();
  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  long count1 = tracker.getJavaStructureModificationCount();

  // gc softly-referenced file and document
  PlatformTestUtil.tryGcSoftlyReachableObjects();
  assertNull(FileDocumentManager.getInstance().getCachedDocument(file));
  assertNull(psiManager.getFileManager().getCachedPsiFile(file));

  VfsUtil.saveText(file, "");
  assertNull(FileDocumentManager.getInstance().getCachedDocument(file));

  assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  assertFalse(count1 == tracker.getJavaStructureModificationCount());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:PsiModificationTrackerTest.java

示例5: testClassShouldNotDisappearWithoutEvents_VirtualFileDeleted

import com.intellij.testFramework.PlatformTestUtil; //导入方法依赖的package包/类
public void testClassShouldNotDisappearWithoutEvents_VirtualFileDeleted() throws IOException {
  PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
  final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject());

  final VirtualFile file = myFixture.addFileToProject("Foo.java", "class Foo {}").getVirtualFile();
  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  long count1 = tracker.getJavaStructureModificationCount();

  // gc softly-referenced file and document
  PlatformTestUtil.tryGcSoftlyReachableObjects();
  assertNull(FileDocumentManager.getInstance().getCachedDocument(file));
  assertNull(psiManager.getFileManager().getCachedPsiFile(file));
  file.delete(this);

  assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  assertFalse(count1 == tracker.getJavaStructureModificationCount());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:PsiModificationTrackerTest.java

示例6: testClassShouldNotDisappearWithoutEvents_ParentVirtualDirectoryDeleted

import com.intellij.testFramework.PlatformTestUtil; //导入方法依赖的package包/类
public void testClassShouldNotDisappearWithoutEvents_ParentVirtualDirectoryDeleted() throws IOException {
  PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
  final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject());

  final VirtualFile file = myFixture.addFileToProject("foo/Foo.java", "package foo; class Foo {}").getVirtualFile();
  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", GlobalSearchScope.allScope(getProject())));
  long count1 = tracker.getJavaStructureModificationCount();

  // gc softly-referenced file and document
  PlatformTestUtil.tryGcSoftlyReachableObjects();
  assertNull(FileDocumentManager.getInstance().getCachedDocument(file));
  assertNull(psiManager.getFileManager().getCachedPsiFile(file));
  file.getParent().delete(this);

  assertNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", GlobalSearchScope.allScope(getProject())));
  assertFalse(count1 == tracker.getJavaStructureModificationCount());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:PsiModificationTrackerTest.java

示例7: testLanguageLevelChange

import com.intellij.testFramework.PlatformTestUtil; //导入方法依赖的package包/类
public void testLanguageLevelChange() {
  //noinspection unused
  PsiFile psiFile = myFixture.addFileToProject("Foo.java", "class Foo {}");
  GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());

  PlatformTestUtil.tryGcSoftlyReachableObjects();

  PsiClass psiClass = JavaPsiFacade.getInstance(getProject()).findClass("Foo", scope);
  assertNotNull(psiClass);

  long count = PsiManager.getInstance(getProject()).getModificationTracker().getJavaStructureModificationCount();

  IdeaTestUtil.setModuleLanguageLevel(myFixture.getModule(), LanguageLevel.JDK_1_3);

  assertTrue(count != PsiManager.getInstance(getProject()).getModificationTracker().getJavaStructureModificationCount());

  psiClass = (JavaPsiFacade.getInstance(getProject()).findClass("Foo", scope));
  assertNotNull(psiClass);
  assertTrue(psiClass.isValid());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:PsiModificationTrackerTest.java

示例8: test

import com.intellij.testFramework.PlatformTestUtil; //导入方法依赖的package包/类
public void test() throws IOException {

    File dir = Files.createTempDir();
    try {
      assertNotNull(FileResourceRepository.get(dir));
      // We shouldn't clear it out immediately on GC *eligibility*:
      System.gc();
      assertNotNull(FileResourceRepository.getCached(dir));
      // However, in low memory conditions we should:
      try {
        PlatformTestUtil.tryGcSoftlyReachableObjects();
      } catch (Throwable t) {
        // The above method can throw java.lang.OutOfMemoryError; that's fine for this test
      }
      System.gc();
      assertNull(FileResourceRepository.getCached(dir));
    }
    finally {
      FileUtil.delete(dir);
    }
  }
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:FileResourceRepositoryTest.java

示例9: testClassShouldNotAppearWithoutEvents_WithPsi

import com.intellij.testFramework.PlatformTestUtil; //导入方法依赖的package包/类
public void testClassShouldNotAppearWithoutEvents_WithPsi() throws IOException {
  final VirtualFile file = myFixture.getTempDirFixture().createFile("Foo.java", "");
  final Document document = FileDocumentManager.getInstance().getDocument(file);
  assertNotNull(document);
  assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  PsiManager psiManager = PsiManager.getInstance(getProject());
  PsiModificationTracker tracker = psiManager.getModificationTracker();
  long count1 = tracker.getJavaStructureModificationCount();
  PsiJavaFile psiFile = (PsiJavaFile)psiManager.findFile(file);

  document.insertString(0, "class Foo {}");

  assertEquals(count1, tracker.getJavaStructureModificationCount()); // no PSI changes yet
  //so the class should not exist
  assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  assertSize(0, psiFile.getClasses());
  assertEquals("", psiManager.findFile(file).getText());
  PlatformTestUtil.tryGcSoftlyReachableObjects();

  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();

  assertFalse(count1 == tracker.getJavaStructureModificationCount());
  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  assertEquals("class Foo {}", psiManager.findFile(file).getText());
  assertEquals("class Foo {}", psiManager.findFile(file).getNode().getText());
  assertSize(1, psiFile.getClasses());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:PsiModificationTrackerTest.java

示例10: testClassShouldNotDisappearWithoutEvents

import com.intellij.testFramework.PlatformTestUtil; //导入方法依赖的package包/类
public void testClassShouldNotDisappearWithoutEvents() throws IOException {
  PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
  long count0 = tracker.getJavaStructureModificationCount();

  final VirtualFile file = myFixture.addFileToProject("Foo.java", "class Foo {}").getVirtualFile();
  final Document document = FileDocumentManager.getInstance().getDocument(file);
  assertNotNull(document);

  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  long count1 = tracker.getJavaStructureModificationCount();
  assertFalse(count1 == count0);

  document.deleteString(0, document.getTextLength());

  // gc softly-referenced file and AST
  PlatformTestUtil.tryGcSoftlyReachableObjects();
  final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject());
  assertNull(psiManager.getFileManager().getCachedPsiFile(file));

  assertEquals(count1, tracker.getJavaStructureModificationCount()); // no PSI changes yet
  //so the class should still be there
  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  assertSize(1, ((PsiJavaFile)psiManager.findFile(file)).getClasses());
  assertEquals("class Foo {}", psiManager.findFile(file).getText());
  PlatformTestUtil.tryGcSoftlyReachableObjects();

  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();

  assertFalse(count1 == tracker.getJavaStructureModificationCount());
  assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:PsiModificationTrackerTest.java

示例11: testDontLoseDocument

import com.intellij.testFramework.PlatformTestUtil; //导入方法依赖的package包/类
public void testDontLoseDocument() {
  PsiExpressionCodeFragment fragment = JavaCodeFragmentFactory.getInstance(myProject).createExpressionCodeFragment("a", null, null, true);
  Document document = PsiDocumentManager.getInstance(myProject).getDocument(fragment);
  document.insertString(1, "b");
  PsiDocumentManager.getInstance(myProject).commitAllDocuments();
  assertEquals("ab", fragment.getText());
  assertEquals("ab", fragment.getExpression().getText());

  //noinspection UnusedAssignment
  document = null;

  PlatformTestUtil.tryGcSoftlyReachableObjects();
  assertEquals("ab", PsiDocumentManager.getInstance(myProject).getDocument(fragment).getText());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:CodeFragmentsTest.java

示例12: testDocumentGced

import com.intellij.testFramework.PlatformTestUtil; //导入方法依赖的package包/类
public void testDocumentGced() throws Exception {
  VirtualFile vFile = getVirtualFile(createTempFile("txt", "abc"));
  PsiDocumentManagerImpl documentManager = getPsiDocumentManager();
  long id = System.identityHashCode(documentManager.getDocument(getPsiManager().findFile(vFile)));

  documentManager.commitAllDocuments();
  UIUtil.dispatchAllInvocationEvents();
  UIUtil.dispatchAllInvocationEvents();
  assertEmpty(documentManager.getUncommittedDocuments());

  LeakHunter.checkLeak(documentManager, DocumentImpl.class);
  LeakHunter.checkLeak(documentManager, PsiFileImpl.class, new Processor<PsiFileImpl>() {
    @Override
    public boolean process(PsiFileImpl psiFile) {
      return psiFile.getViewProvider().getVirtualFile().getFileSystem() instanceof LocalFileSystem;
    }
  });
  //Class.forName("com.intellij.util.ProfilingUtil").getDeclaredMethod("forceCaptureMemorySnapshot").invoke(null);

  for (int i = 0; i < 1000; i++) {
    PlatformTestUtil.tryGcSoftlyReachableObjects();
    UIUtil.dispatchAllInvocationEvents();
    if (documentManager.getCachedDocument(getPsiManager().findFile(vFile)) == null) break;
    System.gc();
  }
  assertNull(documentManager.getCachedDocument(getPsiManager().findFile(vFile)));

  Document newDoc = documentManager.getDocument(getPsiManager().findFile(vFile));
  assertTrue(id != System.identityHashCode(newDoc));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:PsiDocumentManagerImplTest.java

示例13: testFunctionStub

import com.intellij.testFramework.PlatformTestUtil; //导入方法依赖的package包/类
public void testFunctionStub() {
  myFixture.configureByFile("deprecation/functionStub.py");
  PyFile file = (PyFile)myFixture.getFile();
  assertEquals("commands.getstatus() is deprecated", file.findTopLevelFunction("getstatus").getDeprecationMessage());
  PlatformTestUtil.tryGcSoftlyReachableObjects();
  assertNotParsed(file);
  
  assertEquals("commands.getstatus() is deprecated", file.findTopLevelFunction("getstatus").getDeprecationMessage());
  assertNotParsed(file);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:PyDeprecationTest.java

示例14: testFileStub

import com.intellij.testFramework.PlatformTestUtil; //导入方法依赖的package包/类
public void testFileStub() {
  myFixture.configureByFile("deprecation/deprecatedModule.py");
  PyFile file = (PyFile)myFixture.getFile();
  assertEquals("the deprecated module is deprecated; use a non-deprecated module instead", file.getDeprecationMessage());
  PlatformTestUtil.tryGcSoftlyReachableObjects();
  assertNotParsed(file);

  assertEquals("the deprecated module is deprecated; use a non-deprecated module instead", file.getDeprecationMessage());
  assertNotParsed(file);
  
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:PyDeprecationTest.java

示例15: testPsiModificationsWithNoDocumentDocument

import com.intellij.testFramework.PlatformTestUtil; //导入方法依赖的package包/类
public void testPsiModificationsWithNoDocumentDocument() {
  final PsiJavaFile file = (PsiJavaFile)myFixture.addFileToProject("a.java", "class A{}");

  PsiClass aClass = file.getClasses()[0];
  aClass.getNode();
  assertNotNull(PsiDocumentManager.getInstance(getProject()).getCachedDocument(file));
  
  PlatformTestUtil.tryGcSoftlyReachableObjects();
  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"));

}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:MiscPsiTest.java


注:本文中的com.intellij.testFramework.PlatformTestUtil.tryGcSoftlyReachableObjects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。