diff options
Diffstat (limited to 'platform/projectModel-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java')
-rw-r--r-- | platform/projectModel-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java | 93 |
1 files changed, 47 insertions, 46 deletions
diff --git a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java index 9707364c988b..b3d1edb42b4e 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java @@ -31,16 +31,22 @@ import com.intellij.openapi.vfs.StandardFileSystems; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.VirtualFileSystem; -import com.intellij.util.containers.FactoryMap; +import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.MultiMap; +import com.intellij.util.containers.SmartHashSet; +import gnu.trove.THashSet; import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.serialization.PathMacroUtil; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.Set; public class BasePathMacroManager extends PathMacroManager { - private static final CompositePathMacroFilter ourFilter = new CompositePathMacroFilter(Extensions.getExtensions(PathMacrosCollector.MACRO_FILTER_EXTENSION_POINT_NAME)); + private static final CompositePathMacroFilter FILTER = new CompositePathMacroFilter(Extensions.getExtensions(PathMacrosCollector.MACRO_FILTER_EXTENSION_POINT_NAME)); private PathMacrosImpl myPathMacros; @@ -49,20 +55,26 @@ public class BasePathMacroManager extends PathMacroManager { } protected static void addFileHierarchyReplacements(ExpandMacroToPathMap result, String macroName, @Nullable String path) { - if (path == null) return; - addFileHierarchyReplacements(result, getLocalFileSystem().findFileByPath(path), "$" + macroName + "$"); + if (path != null) { + addFileHierarchyReplacements(result, getLocalFileSystem().findFileByPath(path), '$' + macroName + '$'); + } } private static void addFileHierarchyReplacements(ExpandMacroToPathMap result, @Nullable VirtualFile f, String macro) { - if (f == null) return; + if (f == null) { + return; + } + addFileHierarchyReplacements(result, f.getParent(), macro + "/.."); result.put(macro, StringUtil.trimEnd(f.getPath(), "/")); } protected static void addFileHierarchyReplacements(ReplacePathToMacroMap result, String macroName, @Nullable String path, @Nullable String stopAt) { - if (path == null) return; + if (path == null) { + return; + } - String macro = "$" + macroName + "$"; + String macro = '$' + macroName + '$'; path = StringUtil.trimEnd(FileUtil.toSystemIndependentName(path), "/"); boolean overwrite = true; while (StringUtil.isNotEmpty(path) && path.contains("/")) { @@ -140,25 +152,14 @@ public class BasePathMacroManager extends PathMacroManager { if (myPathMacros == null) { myPathMacros = PathMacrosImpl.getInstanceEx(); } - return myPathMacros; } private class MyTrackingPathMacroSubstitutor implements TrackingPathMacroSubstitutor { private final String myLock = new String("MyTrackingPathMacroSubstitutor.lock"); - private final Map<String, Set<String>> myMacroToComponentNames = new FactoryMap<String, Set<String>>() { - @Override - protected Set<String> create(String key) { - return new HashSet<String>(); - } - }; - private final Map<String, Set<String>> myComponentNameToMacros = new FactoryMap<String, Set<String>>() { - @Override - protected Set<String> create(String key) { - return new HashSet<String>(); - } - }; + private final MultiMap<String, String> myMacroToComponentNames = MultiMap.createSet(); + private final MultiMap<String, String> myComponentNameToMacros = MultiMap.createSet(); public MyTrackingPathMacroSubstitutor() { } @@ -182,13 +183,13 @@ public class BasePathMacroManager extends PathMacroManager { } @Override - public void expandPaths(final Element element) { + public void expandPaths(@NotNull final Element element) { getExpandMacroMap().substitute(element, SystemInfo.isFileSystemCaseSensitive); } @Override - public void collapsePaths(final Element element) { - getReplacePathMap().substitute(element, SystemInfo.isFileSystemCaseSensitive, false, ourFilter); + public void collapsePaths(@NotNull final Element element) { + getReplacePathMap().substitute(element, SystemInfo.isFileSystemCaseSensitive, false, FILTER); } public int hashCode() { @@ -196,52 +197,52 @@ public class BasePathMacroManager extends PathMacroManager { } @Override - public void invalidateUnknownMacros(final Set<String> macros) { + public void invalidateUnknownMacros(@NotNull Set<String> macros) { synchronized (myLock) { - for (final String macro : macros) { - final Set<String> components = myMacroToComponentNames.get(macro); - for (final String component : components) { - myComponentNameToMacros.remove(component); + for (String macro : macros) { + Collection<String> componentNames = myMacroToComponentNames.remove(macro); + if (!ContainerUtil.isEmpty(componentNames)) { + for (String component : componentNames) { + myComponentNameToMacros.remove(component); + } } - - myMacroToComponentNames.remove(macro); } } } + @NotNull @Override - public Collection<String> getComponents(final Collection<String> macros) { + public Collection<String> getComponents(@NotNull Collection<String> macros) { synchronized (myLock) { - final Set<String> result = new HashSet<String>(); - for (String macro : myMacroToComponentNames.keySet()) { - if (macros.contains(macro)) { - result.addAll(myMacroToComponentNames.get(macro)); - } + Set<String> result = new SmartHashSet<String>(); + for (String macro : macros) { + result.addAll(myMacroToComponentNames.get(macro)); } - return result; } } + @NotNull @Override - public Collection<String> getUnknownMacros(final String componentName) { + public Collection<String> getUnknownMacros(@Nullable String componentName) { synchronized (myLock) { - final Set<String> result = new HashSet<String>(); - result.addAll(componentName == null ? myMacroToComponentNames.keySet() : myComponentNameToMacros.get(componentName)); - return Collections.unmodifiableCollection(result); + Collection<String> list = componentName == null ? myMacroToComponentNames.keySet() : myComponentNameToMacros.get(componentName); + return ContainerUtil.isEmpty(list) ? Collections.<String>emptyList() : new THashSet<String>(list); } } @Override - public void addUnknownMacros(final String componentName, final Collection<String> unknownMacros) { - if (unknownMacros.isEmpty()) return; + public void addUnknownMacros(@NotNull String componentName, @NotNull Collection<String> unknownMacros) { + if (unknownMacros.isEmpty()) { + return; + } synchronized (myLock) { for (String unknownMacro : unknownMacros) { - myMacroToComponentNames.get(unknownMacro).add(componentName); + myMacroToComponentNames.putValue(unknownMacro, componentName); } - myComponentNameToMacros.get(componentName).addAll(unknownMacros); + myComponentNameToMacros.putValues(componentName, unknownMacros); } } } |