mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't increment psi mod counts on file writability change
This commit is contained in:
@@ -57,7 +57,9 @@ public class JavaCodeBlockModificationListener implements PsiTreeChangePreproces
|
||||
|
||||
case CHILD_MOVED:
|
||||
case PROPERTY_CHANGED:
|
||||
myModificationTracker.incCounter();
|
||||
if (PsiModificationTrackerImpl.canAffectPsi(event)) {
|
||||
myModificationTracker.incCounter();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -418,4 +418,20 @@ public class PsiModificationTrackerTest extends CodeInsightTestCase {
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public void testNoIncrementOnReadOnlyStatusChange() throws IOException {
|
||||
VirtualFile file = addFileToProject("Foo.java", "class Foo {}").getVirtualFile();
|
||||
|
||||
PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
|
||||
long mc = tracker.getModificationCount();
|
||||
|
||||
WriteAction.run(() -> file.setWritable(false));
|
||||
assertEquals(mc, tracker.getModificationCount());
|
||||
|
||||
PlatformTestUtil.tryGcSoftlyReachableObjects();
|
||||
assertNull(PsiManagerEx.getInstanceEx(myProject).getFileManager().getCachedPsiFile(file));
|
||||
|
||||
WriteAction.run(() -> file.setWritable(true));
|
||||
assertEquals(mc, tracker.getModificationCount());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.ModificationTracker;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiTreeChangeEvent;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -83,6 +84,10 @@ public class PsiModificationTrackerImpl implements PsiModificationTracker, PsiTr
|
||||
|
||||
@Override
|
||||
public void treeChanged(@NotNull PsiTreeChangeEventImpl event) {
|
||||
if (!canAffectPsi(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
myModificationCount.getAndIncrement();
|
||||
if (event.getParent() instanceof PsiDirectory
|
||||
|| event.getOldParent() instanceof PsiDirectory /* move events */) {
|
||||
@@ -92,6 +97,10 @@ public class PsiModificationTrackerImpl implements PsiModificationTracker, PsiTr
|
||||
fireEvent();
|
||||
}
|
||||
|
||||
public static boolean canAffectPsi(@NotNull PsiTreeChangeEventImpl event) {
|
||||
return !PsiTreeChangeEvent.PROP_WRITABLE.equals(event.getPropertyName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getModificationCount() {
|
||||
return myModificationCount.get();
|
||||
|
||||
Reference in New Issue
Block a user