diff --git a/platform/lang-impl/src/com/intellij/ide/macro/IdePathMacros.java b/platform/lang-impl/src/com/intellij/ide/macro/IdePathMacros.java new file mode 100644 index 000000000000..cd8f8ae148b4 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/macro/IdePathMacros.java @@ -0,0 +1,29 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.ide.macro; + +import com.intellij.application.options.PathMacrosImpl; +import org.jetbrains.annotations.NotNull; + +import java.util.Set; + +public class IdePathMacros extends PathMacrosImpl { + @NotNull + @Override + public Set getToolMacroNames() { + return MacroManager.getInstance().getMacroNames(); + } +} diff --git a/platform/lang-impl/src/com/intellij/ide/macro/MacroManager.java b/platform/lang-impl/src/com/intellij/ide/macro/MacroManager.java index 46349aaa3800..97a6833b804b 100644 --- a/platform/lang-impl/src/com/intellij/ide/macro/MacroManager.java +++ b/platform/lang-impl/src/com/intellij/ide/macro/MacroManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package com.intellij.ide.macro; -import com.intellij.application.options.PathMacrosImpl; import com.intellij.ide.DataManager; +import com.intellij.ide.macro.Macro.ExecutionCancelledException; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.PlatformDataKeys; @@ -30,17 +30,15 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.ConvertingIterator; import com.intellij.util.containers.Convertor; -import com.intellij.util.containers.HashMap; import gnu.trove.THashMap; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; +import java.util.*; public final class MacroManager { - private final HashMap myMacrosMap = new HashMap<>(); + private final Map myMacrosMap = new LinkedHashMap<>(); public static MacroManager getInstance() { return ServiceManager.getService(MacroManager.class); @@ -106,14 +104,17 @@ public final class MacroManager { } private void registerMacro(Macro macro) { - assert PathMacrosImpl.getToolMacroNames().contains(macro.getName()) : "Macro '" + macro.getName() + "' should be registered in PathMacros!"; - myMacrosMap.put(macro.getName(), macro); } public Collection getMacros() { return myMacrosMap.values(); } + + @NotNull + public Set getMacroNames() { + return myMacrosMap.keySet(); + } public void cacheMacrosPreview(DataContext dataContext) { dataContext = getCorrectContext(dataContext); @@ -143,14 +144,12 @@ public final class MacroManager { * Expands all macros that are found in the {@code str}. */ @Nullable - public String expandMacrosInString(String str, boolean firstQueueExpand, DataContext dataContext) throws Macro.ExecutionCancelledException { + public String expandMacrosInString(@Nullable String str, boolean firstQueueExpand, DataContext dataContext) throws ExecutionCancelledException { return expandMacroSet(str, firstQueueExpand, dataContext, getMacros().iterator()); } @Nullable - private String expandMacroSet(String str, - boolean firstQueueExpand, DataContext dataContext, Iterator macros - ) throws Macro.ExecutionCancelledException { + private static String expandMacroSet(@Nullable String str, boolean firstQueueExpand, DataContext dataContext, Iterator macros) throws ExecutionCancelledException { if (str == null) return null; while (macros.hasNext()) { Macro macro = macros.next(); @@ -198,16 +197,8 @@ public final class MacroManager { return str; } - public String expandSilentMarcos(String str, boolean firstQueueExpand, DataContext dataContext) throws Macro.ExecutionCancelledException { - final Convertor convertor = macro -> { - if (macro instanceof PromptingMacro) { - return new Macro.Silent(macro, ""); - } - return macro; - }; - return expandMacroSet( - str, firstQueueExpand, dataContext, ConvertingIterator.create(getMacros().iterator(), convertor) - ); + public String expandSilentMarcos(@Nullable String str, boolean firstQueueExpand, DataContext dataContext) throws ExecutionCancelledException { + Convertor convertor = macro -> macro instanceof PromptingMacro ? new Macro.Silent(macro, "") : macro; + return expandMacroSet(str, firstQueueExpand, dataContext, ConvertingIterator.create(getMacros().iterator(), convertor)); } - } diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 6fda83c150df..2901e6ffde61 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -200,6 +200,9 @@ + + - - diff --git a/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosCollector.java b/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosCollector.java index 902cf784f18d..69541f2cc64c 100644 --- a/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosCollector.java +++ b/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosCollector.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package com.intellij.application.options; import com.intellij.openapi.application.PathMacroFilter; -import com.intellij.openapi.application.PathMacros; import com.intellij.openapi.components.CompositePathMacroFilter; import com.intellij.openapi.components.PathMacroMap; import com.intellij.openapi.extensions.ExtensionPointName; @@ -52,11 +51,11 @@ public class PathMacrosCollector extends PathMacroMap { @NotNull public static Set getMacroNames(@NotNull final Element e) { return getMacroNames(e, new CompositePathMacroFilter(Extensions.getExtensions(MACRO_FILTER_EXTENSION_POINT_NAME)), - PathMacros.getInstance()); + PathMacrosImpl.getInstanceEx()); } @NotNull - public static Set getMacroNames(Element root, @Nullable PathMacroFilter filter, @NotNull PathMacros pathMacros) { + public static Set getMacroNames(Element root, @Nullable PathMacroFilter filter, @NotNull PathMacrosImpl pathMacros) { final PathMacrosCollector collector = new PathMacrosCollector(); collector.substitute(root, true, false, filter); Set preResult = collector.myMacroMap.keySet(); @@ -67,7 +66,7 @@ public class PathMacrosCollector extends PathMacroMap { Set result = new SmartHashSet<>(preResult); result.removeAll(pathMacros.getSystemMacroNames()); result.removeAll(pathMacros.getLegacyMacroNames()); - result.removeAll(PathMacrosImpl.getToolMacroNames()); + result.removeAll(pathMacros.getToolMacroNames()); result.removeAll(pathMacros.getIgnoredMacroNames()); return result; } diff --git a/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.java b/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.java index d3a7f05b6f9d..896a2ecd352e 100644 --- a/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.java +++ b/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,10 +30,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.serialization.JpsGlobalLoader; import org.jetbrains.jps.model.serialization.PathMacroUtil; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.locks.ReentrantReadWriteLock; @State( @@ -67,69 +64,6 @@ public class PathMacrosImpl extends PathMacros implements PersistentStateCompone SYSTEM_MACROS.add(PathMacroUtil.USER_HOME_NAME); } - @SuppressWarnings("SpellCheckingInspection") - private static final Set ourToolsMacros = ContainerUtil.immutableSet( - "ClasspathEntry", - "Classpath", - "ColumnNumber", - "ContentRoot", - "FileClass", - "FileDir", - "FileParentDir", - "FileDirName", - "FileDirPathFromParent", - "FileDirRelativeToProjectRoot", - "/FileDirRelativeToProjectRoot", - "FileDirRelativeToSourcepath", - "/FileDirRelativeToSourcepath", - "FileExt", - "FileFQPackage", - "FileName", - "FileNameWithoutExtension", - "FileNameWithoutAllExtensions", - "FilePackage", - "FilePath", - "UnixSeparators", - "FilePathRelativeToProjectRoot", - "/FilePathRelativeToProjectRoot", - "FilePathRelativeToSourcepath", - "/FilePathRelativeToSourcepath", - "FilePrompt", - "FileRelativeDir", - "/FileRelativeDir", - "FileRelativePath", - "/FileRelativePath", - "FileEncoding", - "JavaDocPath", - "JDKPath", - "LineNumber", - "ModuleFileDir", - "ModuleFilePath", - "ModuleName", - "AffectedModuleNames", - "IsMake", - "ModuleSourcePath", - "ModuleSdkPath", - "OutputPath", - "PhpExecutable", - "ProjectFileDir", - "ProjectFilePath", - "ProjectName", - "Projectpath", - "Prompt", - "SourcepathEntry", - "Sourcepath", - "SHOW_CHANGES", - "ClipboardContent", - "SelectedText", - "SelectionStartLine", - "SelectionEndLine", - "SelectionStartColumn", - "SelectionEndColumn", - "PyInterpreterDirectory", - "ExecutableByFileExt" - ); - public PathMacrosImpl() { } @@ -148,8 +82,9 @@ public class PathMacrosImpl extends PathMacros implements PersistentStateCompone } } - public static Set getToolMacroNames() { - return ourToolsMacros; + @NotNull + public Set getToolMacroNames() { + return Collections.emptySet(); } @Override diff --git a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/FileStorageCoreUtil.java b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/FileStorageCoreUtil.java index 7ba9ad1d35e4..47c6ff5004e3 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/FileStorageCoreUtil.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/FileStorageCoreUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package com.intellij.openapi.components.impl.stores; import com.intellij.application.options.PathMacrosCollector; -import com.intellij.openapi.application.PathMacros; +import com.intellij.application.options.PathMacrosImpl; import com.intellij.openapi.components.CompositePathMacroFilter; import com.intellij.openapi.components.PathMacroSubstitutor; import com.intellij.openapi.components.TrackingPathMacroSubstitutor; @@ -80,7 +80,7 @@ public class FileStorageCoreUtil { } ((TrackingPathMacroSubstitutor)pathMacroSubstitutor) - .addUnknownMacros(name, PathMacrosCollector.getMacroNames(element, filter, PathMacros.getInstance())); + .addUnknownMacros(name, PathMacrosCollector.getMacroNames(element, filter, PathMacrosImpl.getInstanceEx())); } // remove only after "getMacroNames" - some PathMacroFilter requires element name attribute