@Experimental public interface TextFileRepresents 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
TextDocumentadds logic about incremental edition (eg replacing a single region of text).
This interface is meant to replace
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.
ExperimentalThis 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
FileCollectordecouples you from this. A file collector is available through
Fields Modifier and Type Field Description
UNKNOWN_FILENAMEThe name used for a file that has no name.
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description
getDisplayName()Returns a display name for the file.
getLanguageVersion()Returns the language version which should be used to process this file.
getPathId()Returns an identifier for the path of this file.
readContents()Reads the contents of the underlying character source.
static final String UNKNOWN_FILENAMEThe name used for a file that has no name. This is mostly only relevant for unit tests.
- See Also:
- Constant Field Values
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.
- A language version
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.
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.
String readContents() throws IOExceptionReads the contents of the underlying character source.
- The most up-to-date content
IOException- If this instance is closed
IOException- If reading causes an IOException
@Deprecated DataSource toDataSourceCompat()Deprecated.Compatibility with
DataSource(pmd internals still use DataSource in PMD 6).