Package ghidra.program.database.sourcemap

# Class UserDataPathTransformer

java.lang.Object
ghidra.program.database.sourcemap.UserDataPathTransformer

All Implemented Interfaces:
  `DomainObjectClosedListener`, `SourcePathTransformer`

public class UserDataPathTransformer extends Object implements SourcePathTransformer, DomainObjectClosedListener
An implementation of `SourcePathTransformer` that stores transform information using `ProgramUserData`. This means that transform information will be stored locally but not checked in to a shared project.

Use the static method `getPathTransformer(ghidra.program.model.listing.Program)` to get the transformer for a program.

Synchronization policy: `userData`, `pathMap`, `fileMap`, and `programsToTransformers` must be protected.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addDirectoryTransform(String sourceDir, String targetDir)`
  Adds a new directory transform.
  `void`
  `addFileTransform(SourceFile sourceFile, String path)`
  Adds a new file transform.
  `void`
  `domainObjectClosed(DomainObject dobj)`
  Callback indicating that the specified `DomainObject` has been closed.
  `static SourcePathTransformer`
  `getPathTransformer(Program program)`
  Returns the path transformer for `program`
  `String`
  `getTransformedPath(SourceFile sourceFile, boolean useExistingAsDefault)`
  Returns the transformed path for `sourceFile`.
  `List<SourcePathTransformRecord>`
  `getTransformRecords()`
  Returns a list of all `SourcePathTransformRecord`s
  `void`
  `removeDirectoryTransform(String sourceDir)`
  Removes any directory transform associated with `sourceDir`
  `void`
  `removeFileTransform(SourceFile sourceFile)`
  Removes any file transform for `sourceFile`.
  `static void`
  `validateDirectoryPath(String directory)`
  Throws an `IllegalArgumentException` if `directory` is not a valid, normalized directory path (with forward slashes).

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### getPathTransformer

    public static SourcePathTransformer getPathTransformer(Program program)
    Returns the path transformer for `program`
    Parameters:
      `program` - program
    Returns:
      path transformer

  - ### validateDirectoryPath

    public static void validateDirectoryPath(String directory)
    Throws an `IllegalArgumentException` if `directory` is not a valid, normalized directory path (with forward slashes).
    Parameters:
      `directory` - path to validate

  - ### domainObjectClosed

    public void domainObjectClosed(DomainObject dobj)
    Description copied from interface: `DomainObjectClosedListener`
    Callback indicating that the specified `DomainObject` has been closed.
    Specified by:
      `domainObjectClosed` in interface `DomainObjectClosedListener`
    Parameters:
      `dobj` - domain object

  - ### addFileTransform

    public void addFileTransform(SourceFile sourceFile, String path)
    Description copied from interface: `SourcePathTransformer`
    Adds a new file transform. Any existing file transform for `sourceFile` is overwritten. `path` must be a valid, normalized file path (with forward slashes).
    Specified by:
      `addFileTransform` in interface `SourcePathTransformer`
    Parameters:
      `sourceFile` - source file (can't be null).
      `path` - new path

  - ### removeFileTransform

    public void removeFileTransform(SourceFile sourceFile)
    Description copied from interface: `SourcePathTransformer`
    Removes any file transform for `sourceFile`.
    Specified by:
      `removeFileTransform` in interface `SourcePathTransformer`
    Parameters:
      `sourceFile` - source file

  - ### addDirectoryTransform

    public void addDirectoryTransform(String sourceDir, String targetDir)
    Description copied from interface: `SourcePathTransformer`
    Adds a new directory transform. Any existing directory transform for `sourceDir` is overwritten. `sourceDir` and `targetDir` must be valid, normalized directory paths (with forward slashes).
    Specified by:
      `addDirectoryTransform` in interface `SourcePathTransformer`
    Parameters:
      `sourceDir` - source directory
      `targetDir` - target directory

  - ### removeDirectoryTransform

    public void removeDirectoryTransform(String sourceDir)
    Description copied from interface: `SourcePathTransformer`
    Removes any directory transform associated with `sourceDir`
    Specified by:
      `removeDirectoryTransform` in interface `SourcePathTransformer`
    Parameters:
      `sourceDir` - source directory

  - ### getTransformedPath

    public String getTransformedPath(SourceFile sourceFile, boolean useExistingAsDefault)
    Description copied from interface: `SourcePathTransformer`
    Returns the transformed path for `sourceFile`. The transformed path is determined as follows:
    - If there is a file transform for `sourceFile`, the file transform is applied.
    - Otherwise, the most specific directory transform (i.e., longest source directory string) is applied.
    - If no directory transform applies, the value of `useExistingAsDefault` determines whether the path of `sourceFile` or `null` is returned.
    Specified by:
      `getTransformedPath` in interface `SourcePathTransformer`
    Parameters:
      `sourceFile` - source file to transform
      `useExistingAsDefault` - whether to return sourceFile's path if no transform applies
    Returns:
      transformed path or null

  - ### getTransformRecords

    public List<SourcePathTransformRecord> getTransformRecords()
    Description copied from interface: `SourcePathTransformer`
    Returns a list of all `SourcePathTransformRecord`s
    Specified by:
      `getTransformRecords` in interface `SourcePathTransformer`
    Returns:
      transform records