Java 类com.intellij.psi.impl.PsiModificationTrackerImpl 实例源码

项目:intellij-ce-playground    文件:CodeInsightTestFixtureImpl.java   
protected PsiFile addFileToProject(@NotNull final String rootPath, @NotNull final String relativePath, @NotNull final String fileText) {
  return new WriteCommandAction<PsiFile>(getProject()) {
    @Override
    protected void run(@NotNull Result<PsiFile> result) throws Throwable {
      try {
        if (myTempDirFixture instanceof LightTempDirTestFixtureImpl) {
          final VirtualFile file = myTempDirFixture.createFile(relativePath, fileText);
          result.setResult(PsiManager.getInstance(getProject()).findFile(file));
        }
        else {
          result.setResult(((HeavyIdeaTestFixture)myProjectFixture).addFileToProject(rootPath, relativePath, fileText));
        }
      }
      catch (IOException e) {
        throw new RuntimeException(e);
      }
      finally {
        ((PsiModificationTrackerImpl)PsiManager.getInstance(getProject()).getModificationTracker()).incCounter();
      }
    }
  }.execute().getResultObject();
}
项目:intellij-ce-playground    文件:ReferenceInjectionTest.java   
public void testSurviveSerialization() throws Exception {
  myFixture.configureByText("foo.xml", "<foo xmlns=\"http://foo.bar\" \n" +
                                       "     xxx=\"ba<caret>r\"/>");
  assertNull(myFixture.getReferenceAtCaretPosition());

  InjectLanguageAction.invokeImpl(getProject(), myFixture.getEditor(), myFixture.getFile(), new FileReferenceInjector());
  assertTrue(myFixture.getReferenceAtCaretPosition() instanceof FileReference);

  Configuration configuration = Configuration.getInstance();
  Element element = configuration.getState();
  configuration.loadState(element);

  ((PsiModificationTrackerImpl)PsiManager.getInstance(getProject()).getModificationTracker()).incCounter();
  assertTrue(myFixture.getReferenceAtCaretPosition() instanceof FileReference);

  UnInjectLanguageAction.invokeImpl(getProject(), myFixture.getEditor(), myFixture.getFile());
  assertNull(myFixture.getReferenceAtCaretPosition());
}
项目:tools-idea    文件:CodeInsightTestFixtureImpl.java   
protected PsiFile addFileToProject(final String rootPath, final String relativePath, final String fileText) {
  return new WriteCommandAction<PsiFile>(getProject()) {
    @Override
    protected void run(Result<PsiFile> result) throws Throwable {
      try {
        if (myTempDirFixture instanceof LightTempDirTestFixtureImpl) {
          final VirtualFile file = myTempDirFixture.createFile(relativePath, fileText);
          result.setResult(PsiManager.getInstance(getProject()).findFile(file));
        }
        else {
          result.setResult(((HeavyIdeaTestFixture)myProjectFixture).addFileToProject(rootPath, relativePath, fileText));
        }
      }
      catch (IOException e) {
        throw new RuntimeException(e);
      }
      finally {
        ((PsiModificationTrackerImpl)PsiManager.getInstance(getProject()).getModificationTracker()).incCounter();
      }
    }
  }.execute().getResultObject();
}
项目:tools-idea    文件:InjectLanguageAction.java   
public static void invokeImpl(Project project, Editor editor, PsiFile file, Injectable injectable) {
  final PsiLanguageInjectionHost host = findInjectionHost(editor, file);
  if (host == null) return;
  if (defaultFunctionalityWorked(host, injectable.getId())) return;

  try {
    Language language = injectable.toLanguage();
    for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
      if (support.isApplicableTo(host) && support.addInjectionInPlace(language, host)) {
        return;
      }
    }
    if (TemporaryPlacesRegistry.getInstance(project).getLanguageInjectionSupport().addInjectionInPlace(language, host)) {
      HintManager.getInstance().showInformationHint(editor, StringUtil.escapeXml(language.getDisplayName()) + " was temporarily injected");
    }
  }
  finally {
    if (injectable.getLanguage() != null) {    // no need for reference injection
      FileContentUtil.reparseFiles(project, Collections.<VirtualFile>emptyList(), true);
    }
    else {
      ((PsiModificationTrackerImpl)PsiManager.getInstance(project).getModificationTracker()).incCounter();
      DaemonCodeAnalyzer.getInstance(project).restart();
    }
  }
}
项目:tools-idea    文件:ReferenceInjectionTest.java   
public void testSurviveSerialization() throws Exception {
  myFixture.configureByText("foo.xml", "<foo xmlns=\"http://foo.bar\" \n" +
                                       "     xxx=\"ba<caret>r\"/>");
  assertNull(myFixture.getReferenceAtCaretPosition());

  InjectLanguageAction.invokeImpl(getProject(), myFixture.getEditor(), myFixture.getFile(), new FileReferenceInjector());
  assertNotNull(myFixture.getReferenceAtCaretPosition());

  Configuration configuration = Configuration.getInstance();
  Element element = configuration.getState();
  configuration.loadState(element);

  ((PsiModificationTrackerImpl)PsiManager.getInstance(getProject()).getModificationTracker()).incCounter();
  assertNotNull(myFixture.getReferenceAtCaretPosition());

  UnInjectLanguageAction.invokeImpl(getProject(), myFixture.getEditor(), myFixture.getFile());
  assertNull(myFixture.getReferenceAtCaretPosition());
}
项目:consulo    文件:CodeInsightTestFixtureImpl.java   
protected PsiFile addFileToProject(final String rootPath, final String relativePath, final String fileText) {
  return new WriteCommandAction<PsiFile>(getProject()) {
    @Override
    protected void run(Result<PsiFile> result) throws Throwable {
      try {
        if (myTempDirFixture instanceof LightTempDirTestFixtureImpl) {
          final VirtualFile file = myTempDirFixture.createFile(relativePath, fileText);
          result.setResult(PsiManager.getInstance(getProject()).findFile(file));
        }
        else {
          result.setResult(((HeavyIdeaTestFixture)myProjectFixture).addFileToProject(rootPath, relativePath, fileText));
        }
      }
      catch (IOException e) {
        throw new RuntimeException(e);
      }
      finally {
        ((PsiModificationTrackerImpl)PsiManager.getInstance(getProject()).getModificationTracker()).incCounter();
      }
    }
  }.execute().getResultObject();
}
项目:intellij-ce-playground    文件:JavaCodeInsightTestFixtureImpl.java   
@Override
public void tearDown() throws Exception {
  try {
    UIUtil.invokeLaterIfNeeded(new Runnable() {
      @Override
      public void run() {
        ((PsiModificationTrackerImpl)getPsiManager().getModificationTracker()).incCounter();// drop all caches
      }
    });
  }
  finally {
    super.tearDown();
  }
}
项目:intellij-ce-playground    文件:SpellCheckerManager.java   
public void acceptWordAsCorrect(@NotNull String word, Project project) {
  final String transformed = spellChecker.getTransformation().transform(word);
  if (transformed != null) {
    userDictionary.addToDictionary(transformed);
    final PsiModificationTrackerImpl modificationTracker =
      (PsiModificationTrackerImpl)PsiManager.getInstance(project).getModificationTracker();
    modificationTracker.incCounter();
  }
}
项目:intellij-ce-playground    文件:PsiModificationTrackerTreeChangesUpdatesTest.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  // since we want to test PsiModificationTrackerImpl in isolation, we create a separate instance:
  // The existing PsiModificationTrackerImpl is affected by various components.
  myTracker = new PsiModificationTrackerImpl(getProject());
  ((PsiManagerImpl)PsiManager.getInstance(getProject())).addTreeChangePreprocessor(myTracker);
}
项目:intellij-ce-playground    文件:DomTestCase.java   
protected static void incModCount() {
  new WriteCommandAction(getProject()) {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      ((PsiModificationTrackerImpl)getPsiManager().getModificationTracker()).incCounter();
    }
  }.execute();
}
项目:intellij-ce-playground    文件:AntSupport.java   
public static void markFileAsAntFile(final VirtualFile file, final Project project, final boolean value) {
  if (file.isValid() && ForcedAntFileAttribute.isAntFile(file) != value) {
    ForcedAntFileAttribute.forceAntFile(file, value);
    ((PsiModificationTrackerImpl)PsiManager.getInstance(project).getModificationTracker()).incCounter();
    restartDaemon(project);
  }
}
项目:intellij-ce-playground    文件:GroovyDslFileIndex.java   
private static void clearScriptCache() {
  Application app = ApplicationManager.getApplication();
  app.invokeLater(new Runnable() {
    @Override
    public void run() {
      for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        project.putUserData(SCRIPTS_CACHE, null);
        ((PsiModificationTrackerImpl)PsiManager.getInstance(project).getModificationTracker()).incCounter();
      }
    }
  }, app.getDisposed());
}
项目:intellij-ce-playground    文件:DynamicManagerImpl.java   
private void fireChangeCodeAnalyze() {
  final Editor textEditor = FileEditorManager.getInstance(myProject).getSelectedTextEditor();
  if (textEditor == null) return;
  final PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(textEditor.getDocument());
  if (file == null) return;

  ((PsiModificationTrackerImpl)PsiManager.getInstance(myProject).getModificationTracker()).incCounter();
  DaemonCodeAnalyzer.getInstance(myProject).restart();
}
项目:tools-idea    文件:JavaCodeInsightTestFixtureImpl.java   
@Override
public void tearDown() throws Exception {
  try {
    UIUtil.invokeLaterIfNeeded(new Runnable() {
      @Override
      public void run() {
        ((PsiModificationTrackerImpl)getPsiManager().getModificationTracker()).incCounter();// drop all caches
      }
    });
  }
  finally {
    super.tearDown();
  }
}
项目:tools-idea    文件:SpellCheckerManager.java   
public void acceptWordAsCorrect(@NotNull String word, Project project) {
  final String transformed = spellChecker.getTransformation().transform(word);
  if (transformed != null) {
    userDictionary.addToDictionary(transformed);
    final PsiModificationTrackerImpl modificationTracker =
      (PsiModificationTrackerImpl)PsiManager.getInstance(project).getModificationTracker();
    modificationTracker.incCounter();
  }
}
项目:tools-idea    文件:DomTestCase.java   
protected static void incModCount() {
  new WriteCommandAction(getProject()) {
    @Override
    protected void run(Result result) throws Throwable {
      ((PsiModificationTrackerImpl)getPsiManager().getModificationTracker()).incCounter();
    }
  }.execute();
}
项目:tools-idea    文件:AntSupport.java   
public static void markFileAsAntFile(final VirtualFile file, final Project project, final boolean value) {
  if (file.isValid() && ForcedAntFileAttribute.isAntFile(file) != value) {
    ForcedAntFileAttribute.forceAntFile(file, value);
    ((PsiModificationTrackerImpl)PsiManager.getInstance(project).getModificationTracker()).incCounter();
    restartDaemon(project);
  }
}
项目:tools-idea    文件:DynamicManagerImpl.java   
private void fireChangeCodeAnalyze() {
  final Editor textEditor = FileEditorManager.getInstance(myProject).getSelectedTextEditor();
  if (textEditor == null) return;
  final PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(textEditor.getDocument());
  if (file == null) return;

  ((PsiModificationTrackerImpl)PsiManager.getInstance(myProject).getModificationTracker()).incCounter();
  DaemonCodeAnalyzer.getInstance(myProject).restart();
}
项目:consulo-apache-ant    文件:AntSupport.java   
public static void markFileAsAntFile(final VirtualFile file, final Project project, final boolean value)
{
    if(file.isValid() && ForcedAntFileAttribute.isAntFile(file) != value)
    {
        ForcedAntFileAttribute.forceAntFile(file, value);
        SwingUtilities.invokeLater(() -> WriteAction.run(() -> ((PsiModificationTrackerImpl) PsiManager.getInstance(project).getModificationTracker()).incCounter()));
        restartDaemon(project);
    }
}
项目:consulo    文件:FileManagerImpl.java   
@Override
@TestOnly
public void cleanupForNextTest() {
  ApplicationManager.getApplication().runWriteAction(this::clearViewProviders);

  myVFileToPsiDirMap.set(null);
  ((PsiModificationTrackerImpl)myManager.getModificationTracker()).incCounter();
}
项目:consulo-xml    文件:DomTestCase.java   
protected static void incModCount()
{
    new WriteCommandAction(getProject())
    {
        @Override
        protected void run(Result result) throws Throwable
        {
            ((PsiModificationTrackerImpl) getPsiManager().getModificationTracker()).incCounter();
        }
    }.execute();
}
项目:consulo-javascript    文件:DescriptionByAnotherPsiElementEditorNotification.java   
private void wantUpdate(PsiFile psiFile)
{
    ((PsiModificationTrackerImpl) PsiModificationTracker.SERVICE.getInstance(myProject)).incCounter();

    DaemonCodeAnalyzer.getInstance(myProject).restart(psiFile);

    EditorNotifications.getInstance(psiFile.getProject()).updateNotifications(psiFile.getVirtualFile());
}
项目:intellij-ce-playground    文件:ExternalAnnotationsManagerImpl.java   
private void notifyAfterAnnotationChanging(@NotNull PsiModifierListOwner owner, @NotNull String annotationFQName, boolean successful) {
  myBus.syncPublisher(TOPIC).afterExternalAnnotationChanging(owner, annotationFQName, successful);
  ((PsiModificationTrackerImpl)myPsiManager.getModificationTracker()).incCounter();
}
项目:intellij-ce-playground    文件:ExternalAnnotationsManagerImpl.java   
private void notifyChangedExternally() {
  myBus.syncPublisher(TOPIC).externalAnnotationsChangedExternally();
  ((PsiModificationTrackerImpl)myPsiManager.getModificationTracker()).incCounter();
}
项目:intellij-ce-playground    文件:JsonTreeChangePreprocessor.java   
/**
 * @see com.intellij.psi.impl.PsiTreeChangePreprocessorBase#treeChanged(com.intellij.psi.impl.PsiTreeChangeEventImpl)
 */
@Override
public void treeChanged(@NotNull PsiTreeChangeEventImpl event) {
  if (!(event.getFile() instanceof JsonFile)) return;

  final PsiElement element = event.getParent();
  if (element == null || !(element.getManager() instanceof PsiManagerImpl)) {
    return;
  }
  final PsiModificationTrackerImpl modificationTracker = (PsiModificationTrackerImpl)element.getManager().getModificationTracker();
  boolean changedInsideCodeBlock = false;

  switch (event.getCode()) {
    case BEFORE_CHILDREN_CHANGE:
      if (event.getParent() instanceof PsiFile) {
        changedInsideCodeBlock = true;
        break;
      }

    case CHILDREN_CHANGED:
      if (event.isGenericChange()) {
        return;
      }
      changedInsideCodeBlock = isInsideCodeBlock(event.getParent());
      break;

    case BEFORE_CHILD_ADDITION:
    case BEFORE_CHILD_REMOVAL:
    case CHILD_ADDED:
    case CHILD_REMOVED:
      changedInsideCodeBlock = isInsideCodeBlock(event.getParent());
      break;

    case BEFORE_PROPERTY_CHANGE:
    case PROPERTY_CHANGED:
      changedInsideCodeBlock = false;
      break;

    case BEFORE_CHILD_REPLACEMENT:
    case CHILD_REPLACED:
      changedInsideCodeBlock = isInsideCodeBlock(event.getParent());
      break;

    case BEFORE_CHILD_MOVEMENT:
    case CHILD_MOVED:
      changedInsideCodeBlock = isInsideCodeBlock(event.getOldParent()) && isInsideCodeBlock(event.getNewParent());
      break;
  }

  if (!changedInsideCodeBlock) {
    modificationTracker.incOutOfCodeBlockModificationCounter();
  }
}
项目:intellij-ce-playground    文件:PythonPsiManager.java   
public void initComponent() {
  myModificationTracker = (PsiModificationTrackerImpl) myPsiManager.getModificationTracker();
  myPsiManager.addTreeChangePreprocessor(this);
}
项目:intellij-ce-playground    文件:InjectLanguageAction.java   
public static void invokeImpl(Project project, Editor editor, final PsiFile file, Injectable injectable) {
  final PsiLanguageInjectionHost host = findInjectionHost(editor, file);
  if (host == null) return;
  if (defaultFunctionalityWorked(host, injectable.getId())) return;

  try {
    host.putUserData(FIX_KEY, null);
    Language language = injectable.toLanguage();
    for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
      if (support.isApplicableTo(host) && support.addInjectionInPlace(language, host)) {
        return;
      }
    }
    if (TemporaryPlacesRegistry.getInstance(project).getLanguageInjectionSupport().addInjectionInPlace(language, host)) {
      final Processor<PsiLanguageInjectionHost> data = host.getUserData(FIX_KEY);
      String text = StringUtil.escapeXml(language.getDisplayName()) + " was temporarily injected.";
      if (data != null) {
        if (!ApplicationManager.getApplication().isUnitTestMode()) {
          final SmartPsiElementPointer<PsiLanguageInjectionHost> pointer =
            SmartPointerManager.getInstance(project).createSmartPsiElementPointer(host);
          final TextRange range = host.getTextRange();
          HintManager.getInstance().showQuestionHint(editor, text + "<br>Do you want to insert annotation? " + KeymapUtil
            .getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS)),
                                                     range.getStartOffset(), range.getEndOffset(), new QuestionAction() {
            @Override
            public boolean execute() {
              return data.process(pointer.getElement());
            }
          });
        }
      }
      else {
        HintManager.getInstance().showInformationHint(editor, text);
      }
    }
  }
  finally {
    if (injectable.getLanguage() != null) {    // no need for reference injection
      FileContentUtil.reparseFiles(project, Collections.<VirtualFile>emptyList(), true);
    }
    else {
      ((PsiModificationTrackerImpl)PsiManager.getInstance(project).getModificationTracker()).incCounter();
      DaemonCodeAnalyzer.getInstance(project).restart();
    }
  }
}
项目:intellij-ce-playground    文件:SdkHomeSettings.java   
protected SdkHomeSettings(Project project) {
  myTracker = (PsiModificationTrackerImpl)PsiManager.getInstance(project).getModificationTracker();
}
项目:tools-idea    文件:GroovyDslFileIndex.java   
private static void clearScriptCache() {
  for (Project project : ProjectManager.getInstance().getOpenProjects()) {
    project.putUserData(SCRIPTS_CACHE, null);
    ((PsiModificationTrackerImpl)PsiManager.getInstance(project).getModificationTracker()).incCounter();
  }
}
项目:tools-idea    文件:SdkHomeSettings.java   
protected SdkHomeSettings(Project project) {
  myTracker = (PsiModificationTrackerImpl)PsiManager.getInstance(project).getModificationTracker();
}
项目:consulo-javaee    文件:JspPsiTreeChangePreprocessor.java   
@Override
protected void doIncOutOfCodeBlockCounter()
{
    ((PsiModificationTrackerImpl) myPsiManager.getModificationTracker()).incCounter();
}
项目:consulo-java    文件:JavaCodeInsightTestFixtureImpl.java   
@Override
public void tearDown() throws Exception {
  ((PsiModificationTrackerImpl)getPsiManager().getModificationTracker()).incCounter();// drop all caches
  super.tearDown();
}
项目:consulo-java    文件:ExternalAnnotationsManagerImpl.java   
private void notifyAfterAnnotationChanging(@NotNull PsiModifierListOwner owner, @NotNull String annotationFQName, boolean successful)
{
    myBus.syncPublisher(TOPIC).afterExternalAnnotationChanging(owner, annotationFQName, successful);
    ((PsiModificationTrackerImpl) myPsiManager.getModificationTracker()).incCounter();
}
项目:consulo-java    文件:ExternalAnnotationsManagerImpl.java   
private void notifyChangedExternally()
{
    myBus.syncPublisher(TOPIC).externalAnnotationsChangedExternally();
    ((PsiModificationTrackerImpl) myPsiManager.getModificationTracker()).incCounter();
}
项目:intellij-ce-playground    文件:ProjectRootManagerImpl.java   
private boolean fireRootsChanged(boolean fileTypes) {
  if (myProject.isDisposed()) return false;

  ApplicationManager.getApplication().assertWriteAccessAllowed();

  LOG.assertTrue(!isFiringEvent, "Do not use API that changes roots from roots events. Try using invoke later or something else.");

  if (myMergedCallStarted) {
    LOG.assertTrue(!fileTypes, "File types change is not supported inside merged call");
  }

  myRootsChangesDepth--;
  if (myRootsChangesDepth > 0) return false;
  if (myRootsChangesDepth < 0) {
    LOG.info("Restoring from roots change start/finish mismatch: ", new Throwable());
    myRootsChangesDepth = 0;
  }

  clearScopesCaches();

  incModificationCount();

  PsiManager psiManager = PsiManager.getInstance(myProject);
  psiManager.dropResolveCaches();
  ((PsiModificationTrackerImpl)psiManager.getModificationTracker()).incCounter();

  fireRootsChangedEvent(fileTypes);

  doSynchronizeRoots();

  addRootsToWatch();

  return true;
}
项目:tools-idea    文件:ProjectRootManagerImpl.java   
private boolean fireRootsChanged(boolean filetypes) {
  if (myProject.isDisposed()) return false;

  ApplicationManager.getApplication().assertWriteAccessAllowed();

  LOG.assertTrue(!isFiringEvent, "Do not use API that changes roots from roots events. Try using invoke later or something else.");

  if (myMergedCallStarted) {
    LOG.assertTrue(!filetypes, "Filetypes change is not supported inside merged call");
  }

  myRootsChangesDepth--;
  if (myRootsChangesDepth > 0) return false;

  clearScopesCaches();

  myModificationCount++;

  PsiManager psiManager = PsiManager.getInstance(myProject);
  psiManager.dropResolveCaches();
  ((PsiModificationTrackerImpl)psiManager.getModificationTracker()).incCounter();

  fireRootsChangedEvent(filetypes);

  doSynchronizeRoots();

  addRootsToWatch();

  return true;
}