com.threerings.presents.tools
Class SourceFile

java.lang.Object
  extended by com.threerings.presents.tools.SourceFile

public class SourceFile
extends Object

Reads in a source file, allows the replacement of a "generated fields" and "generated methods" section and writing of the file back out to the disk.


Field Summary
protected  List<String> _lines
           
protected  int _mend
           
protected  int _mstart
           
protected  int _nend
           
protected  int _nstart
           
protected static String FIELDS_END
           
protected static String FIELDS_START
           
protected static String MARKER
           
protected static String METHODS_END
           
protected static String METHODS_START
           
 
Constructor Summary
SourceFile()
           
 
Method Summary
protected  void addOrRemoveGeneratedImport(boolean add)
          Add or remove an import for "@Generated", if needed.
protected  void check(File source, String mname, int mline, String fname, int fline)
          Helper function for sanity checking marker existence.
 boolean containsString(String text)
          Returns true if the supplied text appears in the non-auto-generated section.
 String generate(String fsection, String msection)
          Writes the code out to the specified file.
 void readFrom(File source)
          Reads the code from the supplied source file.
protected  String safeGetLine(int index)
          Safely gets the indexth line, returning the empty string if we exceed the length of the array.
protected  void writeln(BufferedWriter bout, String line)
          Helper function for writing a string and a newline to a writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_lines

protected List<String> _lines

_nstart

protected int _nstart

_nend

protected int _nend

_mstart

protected int _mstart

_mend

protected int _mend

MARKER

protected static final String MARKER
See Also:
Constant Field Values

FIELDS_START

protected static final String FIELDS_START
See Also:
Constant Field Values

FIELDS_END

protected static final String FIELDS_END
See Also:
Constant Field Values

METHODS_START

protected static final String METHODS_START
See Also:
Constant Field Values

METHODS_END

protected static final String METHODS_END
See Also:
Constant Field Values
Constructor Detail

SourceFile

public SourceFile()
Method Detail

readFrom

public void readFrom(File source)
              throws IOException
Reads the code from the supplied source file.

Throws:
IOException

containsString

public boolean containsString(String text)
Returns true if the supplied text appears in the non-auto-generated section.


generate

public String generate(String fsection,
                       String msection)
                throws IOException
Writes the code out to the specified file.

Parameters:
fsection - the new "generated fields" to write to the file, or null.
msection - the new "generated methods" to write to the file, or null.
Throws:
IOException

check

protected void check(File source,
                     String mname,
                     int mline,
                     String fname,
                     int fline)
              throws IOException
Helper function for sanity checking marker existence.

Throws:
IOException

safeGetLine

protected String safeGetLine(int index)
Safely gets the indexth line, returning the empty string if we exceed the length of the array.


writeln

protected void writeln(BufferedWriter bout,
                       String line)
                throws IOException
Helper function for writing a string and a newline to a writer.

Throws:
IOException

addOrRemoveGeneratedImport

protected void addOrRemoveGeneratedImport(boolean add)
Add or remove an import for "@Generated", if needed.