Class CdtVariableResolver


  • public class CdtVariableResolver
    extends Object
    Utility class to resolve macro and variable references. Provides fixture to parse ${macro} expressions and replace macros with actual values using IVariableSubstitutor.
    Since:
    3.0
    • Constructor Detail

      • CdtVariableResolver

        public CdtVariableResolver()
    • Method Detail

      • convertStringListToString

        public static String convertStringListToString​(String[] value,
                                                       String listDelimiter)
        Converts list of strings to one string using given string as delimiter, i.e -> "string1:string2:string3"
        Parameters:
        value - - list of strings to convert.
        listDelimiter - - delimiter.
        Returns:
        all strings from the list separated with given delimiter.
      • resolveToString

        public static String resolveToString​(String string,
                                             IVariableSubstitutor substitutor)
                                      throws CdtVariableException
        Resolves macros of kind ${Macro} in the given string by calling the macro substitutor for each macro reference found. Macros can be inside one another like ${workspace_loc:/${ProjName}/} but resolved just once. No recursive macro names are allowed. It is not possible to prevent macros from expanding. For historical reasons (See Bug 571472), macros that are multi-line according to Pattern's Line Terminators are not expanded.
        Parameters:
        string - - macro expression.
        substitutor - - macro resolution provider to retrieve macro values.
        Returns:
        resolved string
        Throws:
        CdtVariableException - if substitutor can't handle the macro and returns null or throws.
      • resolveStringListValues

        public static String[] resolveStringListValues​(String[] values,
                                                       IVariableSubstitutor substitutor,
                                                       boolean ignoreErrors)
                                                throws CdtVariableException
        Resolves array of macros using substitutor to pull macro's list of values. Note that each macro of input array can in turn provide list of values and the resulting array combines all of them.
        Parameters:
        values - - input array of macros.
        substitutor - - macro resolution provider to retrieve macro values.
        ignoreErrors - - if true then exceptions are caught and ignored.
        Returns:
        array of resolved values.
        Throws:
        CdtVariableException - if substitutor throws CdtVariableException and ignoreErrors=null.
      • resolveToStringList

        public static String[] resolveToStringList​(String string,
                                                   IVariableSubstitutor substitutor)
                                            throws CdtVariableException
        Resolves macro ${ListMacro} in the given String to the String-list using substitutor to pull macro's list of values. If the provided string is not exactly a single macro it is treated as macro expression and result is put into the first element of resulting array.
        Parameters:
        string - - input string.
        substitutor - - macro resolution provider to retrieve macro values.
        Returns:
        array of resolved values.
        Throws:
        CdtVariableException - if substitutor can't handle the macro and returns null or throws.
      • isStringListVariable

        public static boolean isStringListVariable​(int macroType)
        Test for String-list type of macro.
        Parameters:
        macroType - - type of tested macro.
        Returns:
        true if the given macro is a String-list macro.
      • createVariableReference

        public static String createVariableReference​(String name)
        Constructs a macro reference given the macro name e.g. if the "macro1" name is passed, returns "${macro1}"
        Parameters:
        name - - macro name.
        Returns:
        macro variable in form "${macro}"