Interface TextFile


  • @Experimental
    public interface TextFile
    Represents some location containing character data. Despite the name, it's not necessarily backed by a file in the file-system: it may be eg an in-memory buffer, or a zip entry, ie it's an abstraction. Text files are the input which PMD and CPD process.

    Text files must provide read access, and may provide write access. This interface only provides block IO operations, while TextDocument adds logic about incremental edition (eg replacing a single region of text).

    This interface is meant to replace DataSource and SourceCode.CodeLoader. "DataSource" is not an appropriate name for a file which can be written to, also, the "data" it provides is text, not bytes.

    Experimental

    This interface will change in PMD 7 to support read/write operations and other things. You don't need to use it in PMD 6, as FileCollector decouples you from this. A file collector is available through PmdAnalysis.files().
    • Field Detail

      • UNKNOWN_FILENAME

        static final String UNKNOWN_FILENAME
        The name used for a file that has no name. This is mostly only relevant for unit tests.
        See Also:
        Constant Field Values
    • Method Detail

      • getLanguageVersion

        LanguageVersion getLanguageVersion()
        Returns the language version which should be used to process this file. This is a property of the file, which allows sources for several different language versions to be processed in the same PMD run. It also makes it so, that the file extension is not interpreted to find out the language version after the initial file collection phase.
        Returns:
        A language version
      • getPathId

        String getPathId()
        Returns an identifier for the path of this file. This should not be interpreted as a File, it may not be a file on this filesystem. The only requirement for this method, is that two distinct text files should have distinct path IDs, and that from one analysis to the next, the path ID of logically identical files be the same.

        Basically this may be implemented as a URL, or a file path. It is used to index violation caches.

      • getDisplayName

        String getDisplayName()
        Returns a display name for the file. This name is used for reporting and should not be interpreted. It may be relative to a directory, may use platform-specific path separators, may not be normalized. Use getPathId() when you want an identifier.
      • readContents

        String readContents()
                     throws IOException
        Reads the contents of the underlying character source.
        Returns:
        The most up-to-date content
        Throws:
        IOException - If this instance is closed
        IOException - If reading causes an IOException