Class SourceFile
java.lang.Object
com.google.errorprone.apply.SourceFile
Representation of a mutable Java source file.
This class is not thread-safe.
- Author:
- sjnickerson@google.com (Simon Nickerson), alexeagle@google.com (Alex Eagle)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic SourceFile
create
(JavaFileObject fileObject) getFragmentByChars
(int startPosition, int endPosition) Returns a fragment of the source code as a string.getFragmentByLines
(int startLine, int endLine) Returns a fragment of the source code between the two stated line numbers.getLines()
Returns a copy of code as a list of lines.getPath()
Returns the path for this source fileReturns a copy of the code as a string.void
replaceChars
(int startPosition, int endPosition, String replacement) Replace the source code between the start and end character positions with a new string.void
replaceLines
(int startLine, int endLine, List<String> replacementLines) Replace the source code between the start and end lines with some new lines of code.void
replaceLines
(List<String> lines) Replace the source code with the new lines of code.void
setSourceText
(CharSequence source) Clears the current source test for this SourceFile and resets it to the passed-in value.
-
Constructor Details
-
SourceFile
-
-
Method Details
-
create
- Throws:
IOException
-
getPath
Returns the path for this source file -
getLines
-
getSourceText
Returns a copy of the code as a string. -
getAsSequence
-
setSourceText
Clears the current source test for this SourceFile and resets it to the passed-in value. -
getFragmentByChars
Returns a fragment of the source code as a string.This method uses the same conventions as
String.substring(int, int)
for its start and end parameters. -
getFragmentByLines
Returns a fragment of the source code between the two stated line numbers. The parameters represent inclusive line numbers.The returned fragment will end in a newline.
-
replaceLines
-
replaceLines
-
replaceChars
Replace the source code between the start and end character positions with a new string.This method uses the same conventions as
String.substring(int, int)
for its start and end parameters.
-