1 // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.openapi.components;
4 import org.jdom.Element;
5 import org.jetbrains.annotations.Contract;
6 import org.jetbrains.annotations.NotNull;
7 import org.jetbrains.annotations.Nullable;
10 * Provides methods to convert paths from absolute to portable form and vice versa.
12 * @see com.intellij.openapi.application.PathMacros
14 public interface PathMacroSubstitutor {
16 * Convert path to absolute by replacing all names of path variables by its values
18 @Contract("null -> null; !null -> !null")
19 String expandPath(@Nullable String text);
21 @Contract("null -> null; !null -> !null")
22 default String collapsePath(@Nullable String text) {
23 return collapsePath(text, false);
27 * Convert paths inside {@code text} to portable form by replacing all values of path variables by their names.
28 * @param recursively if {@code true} all occurrences of paths inside {@code text} will be processed, otherwise {@code text} will be converted
29 * only if its entire content is a path (or URL)
31 @Contract("null, _ -> null; !null, _ -> !null")
32 String collapsePath(@Nullable String text, boolean recursively);
35 * Process sub tags of {@code element} recursively and convert paths to absolute forms in all tag texts and attribute values.
37 void expandPaths(@NotNull Element element);
39 default void collapsePaths(@NotNull Element element) {
40 collapsePaths(element, false);
43 default void collapsePathsRecursively(@NotNull Element element) {
44 collapsePaths(element, true);
48 * Process sub tags of {@code element} recursively and convert paths to portable forms in all tag texts and attribute values.
49 * @param recursively if {@code true} all occurrences of paths inside tag texts and attribute values will be processed, otherwise
50 * they will be converted only if their entire content is a path (or URL)
52 void collapsePaths(@NotNull Element element, boolean recursively);
54 @Contract("null -> null; !null -> !null")
55 default String collapsePathsRecursively(@Nullable String text) {
56 return collapsePath(text, true);