From b1695608d8d789ee705be5f17eb80f0a560bcfed Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Fri, 18 Nov 2016 14:17:08 +0100 Subject: [PATCH] [review feedback]: 1. remove getCheapFileSystemModificationCount & javadoc for getModificationCount(VirtualFile) and getFilesystemModificationCount 2. in tests also specify changes in local fs mod count (ManagingFS.getModificationCount) 3. more compact code --- .../openapi/vfs/newvfs/ManagingFS.java | 15 +++---- .../openapi/vfs/local/PersistentFsTest.java | 39 ++++++++++--------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java index f3a7eab5273b..0e9c41971394 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/ManagingFS.java @@ -19,6 +19,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -41,15 +42,11 @@ public abstract class ManagingFS implements FileSystemInterface { @NotNull public abstract DataOutputStream writeAttribute(@NotNull VirtualFile file, @NotNull FileAttribute att); - public abstract int getModificationCount(@NotNull VirtualFile fileOrDirectory); - /** - * @deprecated to be removed in IDEA 16 - * @see #getModificationCount() + * @return a number that's incremented every time something changes for the file: name, size, flags, content. + * This number is persisted between IDE sessions and so it'll always increase. This method invocation means disk access, so it's not terribly cheap. */ - public int getCheapFileSystemModificationCount() { - return getModificationCount(); - } + public abstract int getModificationCount(@NotNull VirtualFile fileOrDirectory); /** * @return a number that's incremented every time something changes in the VFS, i.e. file hierarchy, names, flags, attributes, contents. @@ -67,10 +64,10 @@ public abstract class ManagingFS implements FileSystemInterface { public abstract int getStructureModificationCount(); /** - * @deprecated to be removed in IDEA 16 - * @return a number that's incremented every time something changes in the VFS, i.e. file hierarchy, names, flags, attributes, contents. + * @return a number that's incremented every time modification count for some file is advanced, @see {@link #getModificationCount(VirtualFile)}. * This number is persisted between IDE sessions and so it'll always increase. This method invocation means disk access, so it's not terribly cheap. */ + @TestOnly public abstract int getFilesystemModificationCount(); public abstract long getCreationTimestamp(); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/PersistentFsTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/PersistentFsTest.java index e834f0983514..c44e33d4ce4d 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/PersistentFsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/PersistentFsTest.java @@ -15,9 +15,8 @@ */ package com.intellij.openapi.vfs.local; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.IoTestUtil; import com.intellij.openapi.util.text.StringUtil; @@ -182,30 +181,32 @@ public class PersistentFsTest extends PlatformTestCase { public void testModCountIncreases() throws IOException { VirtualFile vFile = setupFile(); ManagingFS managingFS = ManagingFS.getInstance(); + int inSessionModCount = managingFS.getModificationCount(); int globalModCount = managingFS.getFilesystemModificationCount(); final int parentModCount = managingFS.getModificationCount(vFile.getParent()); - ApplicationManager.getApplication().runWriteAction((ThrowableComputable)() -> { - vFile.setWritable(false); - return null; - }); + WriteAction.run(() -> vFile.setWritable(false)); assertEquals(globalModCount + 1, managingFS.getModificationCount(vFile)); assertEquals(globalModCount + 1, managingFS.getFilesystemModificationCount()); assertEquals(parentModCount, managingFS.getModificationCount(vFile.getParent())); + assertEquals(inSessionModCount + 1, managingFS.getModificationCount()); FSRecords.force(); - assertTrue(!FSRecords.isDirty()); + assertFalse(FSRecords.isDirty()); ++globalModCount; + ++inSessionModCount; - ApplicationManager.getApplication().runWriteAction((ThrowableComputable)() -> { - vFile.setWritable(true); // 1 - vFile.setBinaryContent("foo".getBytes(Charset.defaultCharset())); // 1 + timestamp + length - return null; + final long timestamp = vFile.getTimeStamp(); + WriteAction.run(() -> { + vFile.setWritable(true); // 1 change + vFile.setBinaryContent("foo".getBytes(Charset.defaultCharset())); // content change + length change + maybe timestamp change }); - assertEquals(globalModCount + 4, managingFS.getModificationCount(vFile)); - assertEquals(globalModCount + 4, managingFS.getFilesystemModificationCount()); + final int changesCount = timestamp == vFile.getTimeStamp() ? 3 : 4; + assertEquals(globalModCount + changesCount, managingFS.getModificationCount(vFile)); + assertEquals(globalModCount + changesCount, managingFS.getFilesystemModificationCount()); + assertEquals(inSessionModCount + changesCount, managingFS.getModificationCount()); assertEquals(parentModCount, managingFS.getModificationCount(vFile.getParent())); } @@ -222,25 +223,26 @@ public class PersistentFsTest extends PlatformTestCase { ManagingFS managingFS = ManagingFS.getInstance(); final int globalModCount = managingFS.getFilesystemModificationCount(); final int parentModCount = managingFS.getModificationCount(vFile.getParent()); + int inSessionModCount = managingFS.getModificationCount(); FSRecords.force(); - assertTrue(!FSRecords.isDirty()); + assertFalse(FSRecords.isDirty()); FileAttribute attribute = new FileAttribute("test.attribute", 1, true); - ApplicationManager.getApplication().runWriteAction((ThrowableComputable)() -> { + WriteAction.run(() -> { try(DataOutputStream output = attribute.writeAttribute(vFile)) { DataInputOutputUtil.writeINT(output, 1); } - return null; }); assertEquals(globalModCount, managingFS.getModificationCount(vFile)); assertEquals(globalModCount, managingFS.getFilesystemModificationCount()); assertEquals(parentModCount, managingFS.getModificationCount(vFile.getParent())); + assertEquals(inSessionModCount + 1, managingFS.getModificationCount()); assertTrue(FSRecords.isDirty()); FSRecords.force(); - assertTrue(!FSRecords.isDirty()); + assertFalse(FSRecords.isDirty()); // int fileId = ((VirtualFileWithId)vFile).getId(); @@ -250,6 +252,7 @@ public class PersistentFsTest extends PlatformTestCase { assertEquals(globalModCount, managingFS.getModificationCount(vFile)); assertEquals(globalModCount, managingFS.getFilesystemModificationCount()); assertEquals(parentModCount, managingFS.getModificationCount(vFile.getParent())); - assertTrue(!FSRecords.isDirty()); + assertEquals(inSessionModCount + 1, managingFS.getModificationCount()); + assertFalse(FSRecords.isDirty()); } }