Java 类com.intellij.psi.PsiTreeChangeAdapter 实例源码

项目:intellij-ce-playground    文件:PropertiesAnchorizer.java   
public PropertiesAnchorizer(Project project) {
  PsiManager.getInstance(project).addPsiTreeChangeListener(new PsiTreeChangeAdapter() {
    @Override
    public void childRemoved(@NotNull PsiTreeChangeEvent event) {
      final PsiElement removed = event.getChild();
      if (removed instanceof IProperty) {
        myAnchors.remove(removed);
      }
    }
  });
}
项目:intellij-ce-playground    文件:PsiEventsTest.java   
public void testEditingInDocComment() throws  Exception {
  final Ref<Boolean> gotIt = new Ref<Boolean>(false);
  getPsiManager().addPsiTreeChangeListener(new PsiTreeChangeAdapter() {
    @Override
    public void childReplaced(@NotNull PsiTreeChangeEvent event) {
      gotIt.set(true);
    }
  });

  GroovyFile file = GroovyPsiElementFactory.getInstance(myProject).createGroovyFile("/** This is doc comment*/class C{}", true, null);
  final PsiDocumentManager docManager = PsiDocumentManager.getInstance(myProject);
  final Document doc = docManager.getDocument(file);
  assertNotNull(doc);
  CommandProcessor.getInstance().executeCommand(myProject,
    new Runnable() {
      @Override
      public void run() {
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
          @Override
          public void run() {
            doc.insertString(3, " ");
            docManager.commitDocument(doc);
          }
        });
      }
    },
    "file text set",
    this
  );


  assertTrue(gotIt.get());
}
项目:tools-idea    文件:PsiEventsTest.java   
public void testEditingInDocComment() throws  Exception {
  final Ref<Boolean> gotIt = new Ref<Boolean>(false);
  getPsiManager().addPsiTreeChangeListener(new PsiTreeChangeAdapter() {
    @Override
    public void childReplaced(@NotNull PsiTreeChangeEvent event) {
      gotIt.set(true);
    }
  });

  GroovyFile file = GroovyPsiElementFactory.getInstance(myProject).createGroovyFile("/** This is doc comment*/class C{}", true, null);
  final PsiDocumentManager docManager = PsiDocumentManager.getInstance(myProject);
  final Document doc = docManager.getDocument(file);
  assertNotNull(doc);
  CommandProcessor.getInstance().executeCommand(myProject,
    new Runnable() {
      @Override
      public void run() {
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
          @Override
          public void run() {
            doc.insertString(3, " ");
            docManager.commitDocument(doc);
          }
        });
      }
    },
    "file text set",
    this
  );


  assertTrue(gotIt.get());
}