Package ghidra.program.model.sourcemap
Interface SourcePathTransformer
- All Known Implementing Classes:
UserDataPathTransformer
public interface SourcePathTransformer
SourcePathTransformers are used to transform
SourceFile
paths. The intended use is
to transform the path of a SourceFile
in a programs's SourceFileManager
before sending the path to an IDE.
There are two types of transformations: file and directory. File transforms
map a particular SourceFile
to an absolute file path. Directory transforms
transform an initial segment of a path. For example, the directory transforms
"/c:/users/" -> "/src/test/" sends "/c:/users/dir/file1.c" to "/src/test/dir/file1.c"
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDirectoryTransform
(String sourceDir, String targetDir) Adds a new directory transform.void
addFileTransform
(SourceFile sourceFile, String path) Adds a new file transform.getTransformedPath
(SourceFile sourceFile, boolean useExistingAsDefault) Returns the transformed path forsourceFile
.Returns a list of allSourcePathTransformRecord
svoid
removeDirectoryTransform
(String sourceDir) Removes any directory transform associated withsourceDir
void
removeFileTransform
(SourceFile sourceFile) Removes any file transform forsourceFile
.
-
Method Details
-
addFileTransform
Adds a new file transform. Any existing file transform forsourceFile
is overwritten.path
must be a valid, normalized file path (with forward slashes).- Parameters:
sourceFile
- source file (can't be null).path
- new path
-
removeFileTransform
Removes any file transform forsourceFile
.- Parameters:
sourceFile
- source file
-
addDirectoryTransform
Adds a new directory transform. Any existing directory transform forsourceDir
is overwritten.sourceDir
andtargetDir
must be valid, normalized directory paths (with forward slashes).- Parameters:
sourceDir
- source directorytargetDir
- target directory
-
removeDirectoryTransform
Removes any directory transform associated withsourceDir
- Parameters:
sourceDir
- source directory
-
getTransformedPath
Returns the transformed path forsourceFile
. The transformed path is determined as follows:
- If there is a file transform forsourceFile
, 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 ofuseExistingAsDefault
determines whether the path ofsourceFile
ornull
is returned.- Parameters:
sourceFile
- source file to transformuseExistingAsDefault
- whether to return sourceFile's path if no transform applies- Returns:
- transformed path or null
-
getTransformRecords
List<SourcePathTransformRecord> getTransformRecords()Returns a list of allSourcePathTransformRecord
s- Returns:
- transform records
-