From 4e68dc2ac78f0200f78047c055cee40fd0e864ed Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Fri, 22 Jul 2011 16:22:53 +0400 Subject: [PATCH] pushing faster + @NotNulls --- .../roots/impl/JavaLanguageLevelPusher.java | 3 +- .../roots/impl/FilePropertyPusher.java | 3 +- .../impl/PushedFilePropertiesUpdater.java | 47 ++++++++----------- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/java/java-impl/src/com/intellij/openapi/roots/impl/JavaLanguageLevelPusher.java b/java/java-impl/src/com/intellij/openapi/roots/impl/JavaLanguageLevelPusher.java index 50cb8ecb43f7..94625d1e2ed8 100644 --- a/java/java-impl/src/com/intellij/openapi/roots/impl/JavaLanguageLevelPusher.java +++ b/java/java-impl/src/com/intellij/openapi/roots/impl/JavaLanguageLevelPusher.java @@ -53,6 +53,7 @@ public class JavaLanguageLevelPusher implements FilePropertyPusher { Key getFileDataKey(); boolean pushDirectoriesOnly(); + @NotNull T getDefaultValue(); @Nullable @@ -48,7 +49,7 @@ public interface FilePropertyPusher { boolean acceptsFile(VirtualFile file); - void persistAttribute(VirtualFile fileOrDir, T value) throws IOException; + void persistAttribute(VirtualFile fileOrDir, @NotNull T value) throws IOException; public interface Engine { void pushAll(); diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdater.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdater.java index 828e2a5f37fb..57ce7ebe97dd 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdater.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdater.java @@ -33,6 +33,7 @@ import com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.messages.MessageBus; import com.intellij.util.messages.MessageBusConnection; +import org.jetbrains.annotations.Nullable; import java.io.IOException; @@ -100,7 +101,7 @@ public class PushedFilePropertiesUpdater { } public void pushRecursively(VirtualFile file, Project project) { - PushedFilePropertiesUpdater.this.pushRecursively(file, project, pusher); + PushedFilePropertiesUpdater.pushRecursively(file, project, pusher); } }); } @@ -108,44 +109,28 @@ public class PushedFilePropertiesUpdater { }); } - public void pushRecursively(final VirtualFile dir, final Project project, final FilePropertyPusher... pushers) { + private static void pushRecursively(final VirtualFile dir, final Project project, final FilePropertyPusher... pushers) { if (pushers.length == 0) return; ProjectRootManager.getInstance(project).getFileIndex().iterateContentUnderDirectory(dir, new ContentIterator() { public boolean processFile(final VirtualFile fileOrDir) { final boolean isDir = fileOrDir.isDirectory(); for (FilePropertyPusher pusher : pushers) { if (!isDir && (pusher.pushDirectoriesOnly() || !pusher.acceptsFile(fileOrDir))) continue; - findAndUpdateValue(project, fileOrDir, pusher, null); + findAndUpdateValue(project, fileOrDir, pusher, pusher.getDefaultValue()); } return true; } }); } - private static T findPusherValuesUpwards(final Project project, final VirtualFile dir, FilePropertyPusher pusher, T moduleValue) { - final T value = pusher.getImmediateValue(project, dir); - if (value != null) return value; - if (moduleValue != null) return moduleValue; - final VirtualFile parent = dir.getParent(); - if (parent != null) return findPusherValuesUpwards(project, parent, pusher); - return pusher.getDefaultValue(); - } - - private static T findPusherValuesUpwards(final Project project, final VirtualFile dir, FilePropertyPusher pusher) { - final T userValue = dir.getUserData(pusher.getFileDataKey()); - if (userValue != null) return userValue; - final T value = pusher.getImmediateValue(project, dir); - if (value != null) return value; - final VirtualFile parent = dir.getParent(); - if (parent != null) return findPusherValuesUpwards(project, parent, pusher); - return pusher.getDefaultValue(); - } - public void pushAll(final FilePropertyPusher... pushers) { for (Module module : ModuleManager.getInstance(myProject).getModules()) { - final Object[] moduleValues = new Object[pushers.length]; - for (int i = 0; i < moduleValues.length; i++) { - moduleValues[i] = pushers[i].getImmediateValue(module); + final Object[] values = new Object[pushers.length]; + for (int i = 0; i < values.length; i++) { + values[i] = pushers[i].getImmediateValue(module); + if (values[i] == null) { + values[i] = pushers[i].getDefaultValue(); + } } final ModuleRootManager rootManager = ModuleRootManager.getInstance(module); final ModuleFileIndex index = rootManager.getFileIndex(); @@ -156,7 +141,7 @@ public class PushedFilePropertiesUpdater { for (int i = 0, pushersLength = pushers.length; i < pushersLength; i++) { final FilePropertyPusher pusher = pushers[i]; if (!isDir && (pusher.pushDirectoriesOnly() || !pusher.acceptsFile(fileOrDir))) continue; - findAndUpdateValue(myProject, fileOrDir, pusher, moduleValues[i]); + values[i] = findAndUpdateValue(myProject, fileOrDir, pusher, values[i]); } return true; } @@ -165,9 +150,15 @@ public class PushedFilePropertiesUpdater { } } - public static void findAndUpdateValue(final Project project, final VirtualFile fileOrDir, final FilePropertyPusher pusher, final T moduleValue) { - final T value = findPusherValuesUpwards(project, fileOrDir, pusher, moduleValue); + @Nullable + public static T findAndUpdateValue(final Project project, + final VirtualFile fileOrDir, + final FilePropertyPusher pusher, + final T parentValue) { + final T immediateValue = pusher.getImmediateValue(project, fileOrDir); + final T value = immediateValue != null ? immediateValue : parentValue; updateValue(fileOrDir, value, pusher); + return value; } private static void updateValue(final VirtualFile fileOrDir, final T value, final FilePropertyPusher pusher) {