Interface IPathVariableManager
A path variable is a pair of non-null elements (name,value) where name is
a case-sensitive string (containing only letters, digits and the underscore
character, and not starting with a digit), and value is an absolute
IPath
object.
Path variables allow for the creation of relative paths whose exact location in the file system depends on the value of a variable. A variable reference may only appear as the first segment of a relative path.
- Since:
- 2.1
- See Also:
- Restriction:
- This interface is not intended to be implemented by clients.
- Restriction:
- This interface is not intended to be extended by clients.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addChangeListener
(IPathVariableChangeListener listener) Registers the given listener to receive notification of changes to path variables.convertFromUserEditableFormat
(String value, boolean locationFormat) Converts the user editable format to the internal format.convertToRelative
(URI path, boolean force, String variableHint) Converts an absolute path to path relative to some defined variable.convertToUserEditableFormat
(String value, boolean locationFormat) Converts the internal format of the linked resource location if the PARENT variables is used.String[]
Returns an array containing all defined path variable names.getURIValue
(String name) Returns the value of the path variable with the given name.Deprecated.getVariableRelativePathLocation
(URI location) Returns a variable relative path equivalent to an absolute path for a file or folder in the file system, according to the variables defined in this project PathVariableManager.boolean
Returnstrue
if the given variable is defined andfalse
otherwise.boolean
isUserDefined
(String name) Returns whether a variable is user defined or not.void
Removes the given path variable change listener from the listeners list.resolvePath
(IPath path) Deprecated.useresolveURI(URI)
instead.resolveURI
(URI uri) Resolves a relativeURI
object potentially containing a variable reference as its first segment, replacing the variable reference (if any) with the variable's value (which is a concrete absolute URI).void
setURIValue
(String name, URI value) Sets the path variable with the given name to be the specified value.void
Deprecated.usesetURIValue(String, URI)
instead.validateName
(String name) Validates the given name as the name for a path variable.validateValue
(URI path) Validates the given path as the value for a path variable.validateValue
(IPath path) Validates the given path as the value for a path variable.
-
Method Details
-
convertToRelative
Converts an absolute path to path relative to some defined variable. For example, converts "C:/foo/bar.txt" into "FOO/bar.txt", granted that the path variable "FOO" value is "C:/foo".The "force" argument will cause an intermediate path variable to be created if the given path can be relative only to a parent of an existing path variable. For example, if the path "C:/other/file.txt" is to be converted and no path variables point to "C:/" or "C:/other" but "FOO" points to "C:/foo", an intermediate "OTHER" variable will be created relative to "FOO" containing the value "${PARENT-1-FOO}" so that the final path returned will be "OTHER/file.txt".
The argument "variableHint" can be used to specify the name of the path variable to make the provided path relative to.
- Parameters:
path
- The absolute path to be convertedforce
- indicates whether intermediate path variables should be created if the path is relative only to a parent of an existing path variable.variableHint
- The name of the variable to which the path should be made relative to, ornull
for the nearest one.- Returns:
- The converted path
- Throws:
CoreException
- if this method fails. Reasons include:- The variable name is not valid
- Since:
- 3.6
-
setValue
Deprecated.usesetURIValue(String, URI)
instead.Sets the path variable with the given name to be the specified value. Depending on the value given and if the variable is currently defined or not, there are several possible outcomes for this operation:- A new variable will be created, if there is no variable defined with
the given name, and the given value is not
null
. - The referred variable's value will be changed, if it already exists
and the given value is not
null
. - The referred variable will be removed, if a variable with the given
name is currently defined and the given value is
null
. - The call will be ignored, if a variable with the given name is not
currently defined and the given value is
null
, or if it is defined but the given value is equal to its current value.
If a variable is effectively changed, created or removed by a call to this method, notification will be sent to all registered listeners.
- Parameters:
name
- the name of the variablevalue
- the value for the variable (may benull
)- Throws:
CoreException
- if this method fails. Reasons include:- The variable name is not valid
- The variable value is relative
- A new variable will be created, if there is no variable defined with
the given name, and the given value is not
-
setURIValue
Sets the path variable with the given name to be the specified value. Depending on the value given and if the variable is currently defined or not, there are several possible outcomes for this operation:- A new variable will be created, if there is no variable defined with
the given name, and the given value is not
null
. - The referred variable's value will be changed, if it already exists
and the given value is not
null
. - The referred variable will be removed, if a variable with the given
name is currently defined and the given value is
null
. - The call will be ignored, if a variable with the given name is not
currently defined and the given value is
null
, or if it is defined but the given value is equal to its current value.
If a variable is effectively changed, created or removed by a call to this method, notification will be sent to all registered listeners.
- Parameters:
name
- the name of the variablevalue
- the value for the variable (may benull
)- Throws:
CoreException
- if this method fails. Reasons include:- The variable name is not valid
- The variable value is relative
- Since:
- 3.6
- A new variable will be created, if there is no variable defined with
the given name, and the given value is not
-
getValue
Deprecated.usegetURIValue(String)
instead.Returns the value of the path variable with the given name. If there is no variable defined with the given name, returnsnull
.- Parameters:
name
- the name of the variable to return the value for- Returns:
- the value for the variable, or
null
if there is no variable defined with the given name
-
getURIValue
Returns the value of the path variable with the given name. If there is no variable defined with the given name, returnsnull
.- Parameters:
name
- the name of the variable to return the value for- Returns:
- the value for the variable, or
null
if there is no variable defined with the given name - Since:
- 3.6
-
getPathVariableNames
String[] getPathVariableNames()Returns an array containing all defined path variable names.- Returns:
- an array containing all defined path variable names
-
addChangeListener
Registers the given listener to receive notification of changes to path variables. The listener will be notified whenever a variable has been added, removed or had its value changed. Has no effect if an identical path variable change listener is already registered.- Parameters:
listener
- the listener- See Also:
-
removeChangeListener
Removes the given path variable change listener from the listeners list. Has no effect if an identical listener is not registered.- Parameters:
listener
- the listener- See Also:
-
resolveURI
Resolves a relativeURI
object potentially containing a variable reference as its first segment, replacing the variable reference (if any) with the variable's value (which is a concrete absolute URI). If the given URI is absolute or has a non-null
device then no variable substitution is done and that URI is returned as is. If the given URI is relative and has anull
device, but the first segment does not correspond to a defined variable, then the URI is returned as is.If the given URI is
null
thennull
will be returned. In all other cases the result will be non-null
.- Parameters:
uri
- the URI to be resolved- Returns:
- the resolved URI or
null
- Since:
- 3.2
-
resolvePath
Deprecated.useresolveURI(URI)
instead.Resolves a relativeIPath
object potentially containing a variable reference as its first segment, replacing the variable reference (if any) with the variable's value (which is a concrete absolute path). If the given path is absolute or has a non-null
device then no variable substitution is done and that path is returned as is. If the given path is relative and has anull
device, but the first segment does not correspond to a defined variable, then the path is returned as is.If the given path is
null
thennull
will be returned. In all other cases the result will be non-null
.For example, consider the following collection of path variables:
- TEMP = c:/temp
- BACKUP = /tmp/backup
The following paths would be resolved as:
c:/bin => c:/bin
c:TEMP => c:TEMP
/TEMP => /TEMP
TEMP => c:/temp
TEMP/foo => c:/temp/foo
BACKUP => /tmp/backup
BACKUP/bar.txt => /tmp/backup/bar.txt
SOMEPATH/foo => SOMEPATH/foo
- Parameters:
path
- the path to be resolved- Returns:
- the resolved path or
null
-
isDefined
Returnstrue
if the given variable is defined andfalse
otherwise. Returnsfalse
if the given name is not a valid path variable name.- Parameters:
name
- the variable's name- Returns:
true
if the variable exists,false
otherwise
-
isUserDefined
Returns whether a variable is user defined or not.- Returns:
- true if the path is user defined.
- Since:
- 3.6
-
validateName
Validates the given name as the name for a path variable. A valid path variable name is made exclusively of letters, digits and the underscore character, and does not start with a digit.- Parameters:
name
- a possibly valid path variable name- Returns:
- a status object with code
IStatus.OK
if the given name is a valid path variable name, otherwise a status object indicating what is wrong with the string - See Also:
-
validateValue
Validates the given path as the value for a path variable. A path variable value must be a valid path that is absolute.- Parameters:
path
- a possibly valid path variable value- Returns:
- a status object with code
IStatus.OK
if the given path is a valid path variable value, otherwise a status object indicating what is wrong with the value - See Also:
-
validateValue
Validates the given path as the value for a path variable. A path variable value must be a valid path that is absolute.- Parameters:
path
- a possibly valid path variable value- Returns:
- a status object with code
IStatus.OK
if the given path is a valid path variable value, otherwise a status object indicating what is wrong with the value - Since:
- 3.6
- See Also:
-
getVariableRelativePathLocation
Returns a variable relative path equivalent to an absolute path for a file or folder in the file system, according to the variables defined in this project PathVariableManager. The file or folder need not to exist.- Parameters:
location
- a path in the local file system- Returns:
- the corresponding variable relative path, or
null
if no such path is available - Since:
- 3.6
-
convertToUserEditableFormat
Converts the internal format of the linked resource location if the PARENT variables is used. For example, if the value is "${PARENT-2-VAR}\foo", the converted result is "${VAR}\..\..\foo".- Parameters:
value
- the value encoded using OS string (as returned from Path.toOSString())locationFormat
- indicates whether the value contains a string that is stored in the linked resource location rather than in the path variable value- Returns:
- the converted path variable value
- Since:
- 3.6
-
convertFromUserEditableFormat
Converts the user editable format to the internal format. For example, if the value is "${VAR}\..\..\foo", the converted result is "${PARENT-2-VAR}\foo". If the string is not directly convertible to a ${PARENT-COUNT-VAR} syntax (for example, the editable string "${FOO}bar\..\..\"), intermediate path variables will be created.- Parameters:
value
- the value encoded using OS string (as returned from Path.toOSString())locationFormat
- indicates whether the value contains a string that is stored in the linked resource location rather than in the path variable value- Returns:
- the converted path variable value
- Since:
- 3.6
-
getURIValue(String)
instead.