Package ghidra.program.database.sourcemap

# Class SourceFile

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

All Implemented Interfaces:
  `Comparable<SourceFile>`

public final class SourceFile extends Object implements Comparable<SourceFile>
A SourceFile is an immutable object representing a source file. It contains an absolute path along with an optional `SourceFileIdType` and identifier. For example, if the id type is `SourceFileIdType.MD5`, the identifier would be the md5 sum of the source file (stored as a byte array).

Note: path parameters are assumed to be absolute file paths with forward slashes as the separator. For other cases, e.g. windows paths, consider the static convenience methods in the `SourceFileUtils` class.

Note: you can use `SourceFileUtils.hexStringToByteArray` to convert hex Strings to byte arrays. You can use `SourceFileUtils.longToByteArray` to convert long values to the appropriate byte arrays.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SourceFile(String path)`
  Constructor requiring only a path.
  `SourceFile(String path, SourceFileIdType type, byte[] identifier)`
  Constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `compareTo(SourceFile sourceFile)`
  `boolean`
  `equals(Object o)`
  `String`
  `getFilename()`
  Returns the filename
  `String`
  `getIdAsString()`
  Returns a String representation of the identifier
  `byte[]`
  `getIdentifier()`
  Returns (a copy of) the identifier
  `SourceFileIdType`
  `getIdType()`
  Returns the source file identifier type
  `String`
  `getPath()`
  Returns the path
  `URI`
  `getUri()`
  Returns a file URI for this SourceFile.
  `int`
  `hashCode()`
  `String`
  `toString()`

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

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### SourceFile

    public SourceFile(String path)
    Constructor requiring only a path. The path will be normalized (see `URI.normalize()`) The id type will be set to `SourceFileIdType.NONE` and the identifier will be set to an array of length 0.
    Parameters:
      `path` - path

  - ### SourceFile

    public SourceFile(String path, SourceFileIdType type, byte[] identifier)
    Constructor. The path will be normalized (see `URI.normalize()`).

    Note: if `type` is `SourceFileIdType.NONE`, the `identifier` parameter is ignored.

    Note: use `SourceFileUtils.longToByteArray` to convert a `long` value to the appropriate `byte` array.

    Parameters:
      `path` - path
      `type` - id type
      `identifier` - id

- ## Method Details

  - ### getUri

    public URI getUri()
    Returns a file URI for this SourceFile.
    Returns:
      uri

  - ### getPath

    public String getPath()
    Returns the path
    Returns:
      path

  - ### getFilename

    public String getFilename()
    Returns the filename
    Returns:
      filename

  - ### getIdType

    public SourceFileIdType getIdType()
    Returns the source file identifier type
    Returns:
      id type

  - ### getIdentifier

    public byte[] getIdentifier()
    Returns (a copy of) the identifier
    Returns:
      identifier

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### equals

    public boolean equals(Object o)
    Overrides:
      `equals` in class `Object`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### compareTo

    public int compareTo(SourceFile sourceFile)
    Specified by:
      `compareTo` in interface `Comparable<SourceFile>`

  - ### getIdAsString

    public String getIdAsString()
    Returns a String representation of the identifier
    Returns:
      id display string