Class Source
java.lang.Object
org.checkerframework.afu.annotator.Source
Represents a Java source file. This class provides three major operations: parsing the source
file to obtain a syntax tree (via JSR-199), inserting text into the source file at specified
offsets, and writing the rewritten source file.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Signifies that a problem has occurred with the compiler that produces the syntax tree for this source file. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchar
charAt
(int index) com.sun.tools.javac.code.Types
getTypes()
Returns an object that provides utility methods for types.void
Inserts the given string into the source file at the given offset.parse()
Parse the input file, returning a set of Tree API roots (asCompilationUnitTree
s).substring
(int start, int end) void
write
(OutputStream out) Writes the modified source file to the given stream.
-
Constructor Details
-
Source
Sets up a compiler for parsing the given Java source file.- Throws:
Source.CompilerException
- if the input file couldn't be readIOException
-
-
Method Details
-
getTypes
public com.sun.tools.javac.code.Types getTypes()Returns an object that provides utility methods for types.- Returns:
- an object that provides utility methods for types
-
parse
Parse the input file, returning a set of Tree API roots (asCompilationUnitTree
s).- Returns:
- the Tree API roots for the input file
-
insert
Inserts the given string into the source file at the given offset.Note that calling this can throw off indices in later parts of the file. Therefore, when doing multiple insertions, you should perform them from the end of the file forward.
- Parameters:
offset
- the offset to place the start of the insertion textstr
- the text to insert
-
charAt
public char charAt(int index) -
substring
-
getString
-
write
Writes the modified source file to the given stream.- Parameters:
out
- the stream for writing the file- Throws:
IOException
- if the source file couldn't be written
-