Class Source

java.lang.Object
org.checkerframework.afu.annotator.Source

public final class Source extends Object
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 Classes
    Modifier and Type
    Class
    Description
    static class 
    Signifies that a problem has occurred with the compiler that produces the syntax tree for this source file.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Sets up a compiler for parsing the given Java source file.
  • Method Summary

    Modifier and Type
    Method
    Description
    char
    charAt(int index)
     
     
    com.sun.tools.javac.code.Types
    Returns an object that provides utility methods for types.
    void
    insert(int offset, String str)
    Inserts the given string into the source file at the given offset.
    Parse the input file, returning a set of Tree API roots (as CompilationUnitTrees).
    substring(int start, int end)
     
    void
    Writes the modified source file to the given stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • 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

      public Set<CompilationUnitTree> parse()
      Parse the input file, returning a set of Tree API roots (as CompilationUnitTrees).
      Returns:
      the Tree API roots for the input file
    • insert

      public void insert(int offset, String str)
      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 text
      str - the text to insert
    • charAt

      public char charAt(int index)
    • substring

      public String substring(int start, int end)
    • getString

      public String getString()
    • write

      public void write(OutputStream out) throws IOException
      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