From 085c67a53fa517a8572b559f3043e1934bf65d17 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 3 Sep 2009 18:38:10 +0400 Subject: [PATCH] fix userdata calculation --- .../roots/impl/JavaLanguageLevelPusher.java | 3 +++ .../com/intellij/lang/LanguagePerFileMappings.java | 14 +++++++--- .../openapi/roots/impl/FilePropertyPusher.java | 2 ++ .../roots/impl/PushedFilePropertiesUpdater.java | 30 ++++++++++++++-------- 4 files changed, 34 insertions(+), 15 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 59363257b8..019cf1e470 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 @@ -15,6 +15,8 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import org.jetbrains.annotations.NotNull; + /** * @author Gregory.Shrago */ @@ -28,6 +30,7 @@ public class JavaLanguageLevelPusher implements FilePropertyPusher getFileDataKey() { return LanguageLevel.KEY; } diff --git a/platform/lang-impl/src/com/intellij/lang/LanguagePerFileMappings.java b/platform/lang-impl/src/com/intellij/lang/LanguagePerFileMappings.java index c369b11ce2..32ae1536c6 100644 --- a/platform/lang-impl/src/com/intellij/lang/LanguagePerFileMappings.java +++ b/platform/lang-impl/src/com/intellij/lang/LanguagePerFileMappings.java @@ -80,12 +80,14 @@ public abstract class LanguagePerFileMappings implements PersistentStateCompo } public void setMappings(final Map mappings) { + final Collection oldFiles; synchronized (myMappings) { + oldFiles = new ArrayList(myMappings.keySet()); myMappings.clear(); myMappings.putAll(mappings); cleanup(); } - handleMappingChange(mappings.keySet(), true); + handleMappingChange(mappings.keySet(), oldFiles, true); } public void setMapping(final VirtualFile file, T dialect) { @@ -97,15 +99,19 @@ public abstract class LanguagePerFileMappings implements PersistentStateCompo myMappings.put(file, dialect); } } - handleMappingChange(ContainerUtil.createMaybeSingletonList(file), false); + final List files = ContainerUtil.createMaybeSingletonList(file); + handleMappingChange(files, files, false); } - private void handleMappingChange(final Collection files, final boolean includeOpenFiles) { - FileContentUtil.reparseFiles(myProject, files, includeOpenFiles); + private void handleMappingChange(final Collection files, Collection oldFiles, final boolean includeOpenFiles) { final FilePropertyPusher pusher = getFilePropertyPusher(); if (pusher != null) { + for (VirtualFile oldFile : oldFiles) { + oldFile.putUserData(pusher.getFileDataKey(), null); + } PushedFilePropertiesUpdater.getInstance(myProject).pushAll(pusher); } + FileContentUtil.reparseFiles(myProject, files, includeOpenFiles); } public Collection getAvailableValues(VirtualFile file) { diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/FilePropertyPusher.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/FilePropertyPusher.java index 25ed54ebae..0645c1029d 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/FilePropertyPusher.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/FilePropertyPusher.java @@ -6,6 +6,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.messages.MessageBus; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.IOException; @@ -17,6 +18,7 @@ public interface FilePropertyPusher { ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.filePropertyPusher"); void initExtra(Project project, MessageBus bus, Engine languageLevelUpdater); + @NotNull Key getFileDataKey(); boolean pushDirectoriesOnly(); 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 faae8febb6..7460248c30 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 @@ -91,25 +91,33 @@ public class PushedFilePropertiesUpdater { public 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); - } - return true; + 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); } - }); - } + 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, null); + if (parent != null) return findPusherValuesUpwards(project, parent, pusher); return pusher.getDefaultValue(); } @@ -121,7 +129,7 @@ public class PushedFilePropertiesUpdater { } final ModuleRootManager rootManager = ModuleRootManager.getInstance(module); final ModuleFileIndex index = rootManager.getFileIndex(); - for (VirtualFile root : rootManager.getSourceRoots()) { + for (VirtualFile root : rootManager.getContentRoots()) { index.iterateContentUnderDirectory(root, new ContentIterator() { public boolean processFile(final VirtualFile fileOrDir) { final boolean isDir = fileOrDir.isDirectory(); -- 2.11.4.GIT