Package com.google.errorprone.apply
Class SourceFile
java.lang.Object
com.google.errorprone.apply.SourceFile
public class SourceFile extends Object
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
Constructors Constructor Description SourceFile(String path, CharSequence source)
-
Method Summary
Modifier and Type Method Description static SourceFile
create(JavaFileObject fileObject)
CharSequence
getAsSequence()
String
getFragmentByChars(int startPosition, int endPosition)
Returns a fragment of the source code as a string.String
getFragmentByLines(int startLine, int endLine)
Returns a fragment of the source code between the two stated line numbers.List<String>
getLines()
Returns a copy of code as a list of lines.String
getPath()
Returns the path for this source fileString
getSourceText()
Returns 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
Returns a copy of code as a list of lines. -
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
Replace the source code with the new lines of code. -
replaceLines
Replace the source code between the start and end lines with some new lines of code. -
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.
-