ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

javafe.util
Class LocationManagerCorrelatedReader

java.lang.Object
  extended byjavafe.util.CorrelatedReader
      extended byjavafe.util.BufferedCorrelatedReader
          extended byjavafe.util.LocationManagerCorrelatedReader
Direct Known Subclasses:
FileCorrelatedReader

public abstract class LocationManagerCorrelatedReader
extends BufferedCorrelatedReader

This CorrelatedReader class manages the allocation of location numbers.


Field Summary
private static java.util.Vector allCorrStreams
          A static Vector containing all LocationManagerCorrelatedReader instances, in the order they were allocated, which is used to map a given location to a corresponding LocationManagerCorrelatedReader instance.
protected  int curLineNo
          The current line number; that is, the number of we've read from our stream so far + 1.
private static int freeLoc
          The next location to be allocated to a LocationManagerCorrelatedReader instance.
protected  boolean isWholeFile
          Are all of our locations whole-file locations?
private  int markLineNo
          The value of curLineNo at the mark point (if marked is true).
(package private) static int MAXFILESIZE
          A location is an integer that encodes file/line/column/offset information.
private  int[] NLOA
          Each LocationManagerCorrelatedReader has a "new line offset array", or NLOA, that contains the offset of the beginning of each line.
private static int NLOA_DEFAULT_SIZE
          The default initial size to allocate an NLOA array
protected  int streamid
           
static int totalLinesRead
          The total # of lines that have been read so far by all FileCorrelatedReaders.
 
Fields inherited from class javafe.util.BufferedCorrelatedReader
beforeBufLoc, buf, curNdx, endBufNdx, lastCharNdx, markNdx, maxLoc, minLoc, oddSlashLoc, STARTFREELOC
 
Fields inherited from class javafe.util.CorrelatedReader
marked
 
Constructor Summary
(package private) LocationManagerCorrelatedReader()
          This constructor allocates a range of location for use by the CorrelatedReader.
 
Method Summary
static void clear()
           
 void close()
          Closes us.
static java.util.Vector fileNumbersToNames()
          Creates and returns a vector that associates file numbers to file names.
protected static LocationManagerCorrelatedReader getCorrStreamAt(int i)
          Return the LocationManagerCorrelatedReader associated with streamId i.
(package private) static boolean isWholeFileLoc(int loc)
          Is a location a whole file location?
private static int locToColOrLine(int loc, boolean wantColumn)
          Returns the column number (if wantColumn) or line number (if !
(package private) static int locToColumn(int loc)
          Returns the column number associated with location loc.
(package private) static GenericFile locToFile(int loc)
          Returns the GenericFile associated with location loc.
(package private) static int locToLineNumber(int loc)
          Returns the line number associated with location loc.
(package private) static int locToOffset(int loc)
          Returns the offset associated with location loc.
protected static LocationManagerCorrelatedReader locToStream(int loc)
          Return the LocationManager CorrelatedReader instance associated with location loc.
(package private) static int locToStreamId(int loc)
          Returns the internal stream ID used for the stream associated with location loc.
(package private) static int makeLocation(int streamId, int line, int col)
          Attempt to return the valid regular location associated with a given streamId, line #, and col #.
 void mark()
          Marks the position of the current character in this input stream.
protected  void recordNewLineLocation()
          Records a newline at the current location.
 void reset()
          Repositions this stream to the position at the time the mark method was last called on this input stream.
(package private) static GenericFile streamIdToFile(int id)
          Returns the GenericFile associated with stream id id, where id has previously been returned by locToStreamId.
 java.lang.String toString()
           
 
Methods inherited from class javafe.util.BufferedCorrelatedReader
clearMark, createReaderFromMark, getBeforeMarkLocation, getBufferFromMark, getLocation, peek, readRaw, refillBuf
 
Methods inherited from class javafe.util.CorrelatedReader
getFile, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

freeLoc

private static int freeLoc
The next location to be allocated to a LocationManagerCorrelatedReader instance. (The next instance's stream will have locations in a prefix of [freeLoc, freeLoc+MAXFILESIZE).)

We do not use ints below STARTFREELOC to denote locations. If freeLoc+MAXFILESIZE results in an overflow, then too many LocationManagerCorrelatedReader instances have been created and an assertion failure occurs.


MAXFILESIZE

static final int MAXFILESIZE
A location is an integer that encodes file/line/column/offset information. When a LocationManagerCorrelatedReader is created, we allocate MAXFILESIZE locations for its stream. An assertion failure will occur if a location is requested for a character located at an offset greater than or equal to MAXFILESIZE.

See Also:
Constant Field Values

NLOA

private int[] NLOA
Each LocationManagerCorrelatedReader has a "new line offset array", or NLOA, that contains the offset of the beginning of each line. This array allows us to map an offset to line or column information.

NLOA is defined for indexes in [0..curLineNo).

If NLOA[i], i in [0..curLineNo), = j, then the characters at offset j and j-1 were on different lines. Furthermore, either (a) i=j=0, or (b) i>0, j>0, and the character at offset j-1 is a newline.

Note: this means a line ends just *after* a newline, not before.


NLOA_DEFAULT_SIZE

private static final int NLOA_DEFAULT_SIZE
The default initial size to allocate an NLOA array

See Also:
Constant Field Values

streamid

protected int streamid

allCorrStreams

private static java.util.Vector allCorrStreams
A static Vector containing all LocationManagerCorrelatedReader instances, in the order they were allocated, which is used to map a given location to a corresponding LocationManagerCorrelatedReader instance.

A location's streamId is its index in allCorrStreams. See locToStreamId(int) for the algorithm mapping locations to streamId's.


isWholeFile

protected boolean isWholeFile
Are all of our locations whole-file locations?


totalLinesRead

public static int totalLinesRead
The total # of lines that have been read so far by all FileCorrelatedReaders.

This is not used internally, and is kept only for interested clients.


curLineNo

protected int curLineNo
The current line number; that is, the number of we've read from our stream so far + 1.

(Line numbers are counted from 1 not 0.)


markLineNo

private int markLineNo
The value of curLineNo at the mark point (if marked is true).

The justification for why it's okay to place the following invariant in this class, even though marked is declared in the superclass, is that this class overrides the methods that set marked to true. (But there's no mechanical check that this justification is upheld, so it needs to be upheld manually.)

Constructor Detail

LocationManagerCorrelatedReader

LocationManagerCorrelatedReader()
This constructor allocates a range of location for use by the CorrelatedReader.

Method Detail

close

public void close()
Closes us. No other I/O operations may be called on us after we have been closed.

Overrides:
close in class BufferedCorrelatedReader

recordNewLineLocation

protected void recordNewLineLocation()
Records a newline at the current location.


fileNumbersToNames

public static java.util.Vector fileNumbersToNames()
Creates and returns a vector that associates file numbers to file names.


getCorrStreamAt

protected static LocationManagerCorrelatedReader getCorrStreamAt(int i)
Return the LocationManagerCorrelatedReader associated with streamId i.

If i is not a valid streamId (aka, i not in [0, allCorrStreams.size()) ), an assertion failure occurs.


makeLocation

static int makeLocation(int streamId,
                        int line,
                        int col)
Attempt to return the valid regular location associated with a given streamId, line #, and col #.

If there is no such location currently in existence, an assertion failure will occur.

This method is intended mainly for debugging purposes.


locToStream

protected static LocationManagerCorrelatedReader locToStream(int loc)
Return the LocationManager CorrelatedReader instance associated with location loc.

Requires that loc be a valid location.


locToStreamId

static int locToStreamId(int loc)
Returns the internal stream ID used for the stream associated with location loc. Requires that loc be a valid location.


isWholeFileLoc

static boolean isWholeFileLoc(int loc)
Is a location a whole file location? Requires that loc be a valid location or NULL.


locToOffset

static int locToOffset(int loc)
Returns the offset associated with location loc.

Requires that loc be a valid regular location (regular ==> not a whole-file location).

Note: offsets start with 1 (a la emacs).


locToLineNumber

static int locToLineNumber(int loc)
Returns the line number associated with location loc.

Requires that loc be a valid regular location (regular ==> not a whole-file location).

Note: line numbers start with 1 (a la emacs).


locToColumn

static int locToColumn(int loc)
Returns the column number associated with location loc.

Requires that loc be a valid regular location (regular ==> not a whole-file location).

Note: column numbers start with 0.


locToColOrLine

private static int locToColOrLine(int loc,
                                  boolean wantColumn)
Returns the column number (if wantColumn) or line number (if !wantColumn) associated with location loc.

Requires that loc be a valid regular location (regular ==> not a whole-file location).

Note: line numbers start with 1 (a la emacs), while column numbers start with 0.


streamIdToFile

static GenericFile streamIdToFile(int id)
Returns the GenericFile associated with stream id id, where id has previously been returned by locToStreamId. Requires that id be a valid streamId.


locToFile

static GenericFile locToFile(int loc)
Returns the GenericFile associated with location loc.

Requires that id be a valid streamId of a FileCorrelatedReader.


mark

public void mark()
Description copied from class: BufferedCorrelatedReader
Marks the position of the current character in this input stream. A subsequent call to the reset method repositions this stream at the last marked position. This method differs from java.io.InputStream.readlimit in that it does not take a readlimit argument.

Overrides:
mark in class BufferedCorrelatedReader
See Also:
BufferedCorrelatedReader.reset(), BufferedCorrelatedReader.clearMark(), BufferedCorrelatedReader.createReaderFromMark(int)

reset

public void reset()
           throws java.io.IOException
Description copied from class: BufferedCorrelatedReader
Repositions this stream to the position at the time the mark method was last called on this input stream.

Requires that the input stream had been previously marked via the mark() method.

If mark() is called before read(), then the mark will be restored to its previous value (and not the preceeding character().

Overrides:
reset in class BufferedCorrelatedReader
Throws:
java.io.IOException - if this stream is not marked.
See Also:
BufferedCorrelatedReader.mark()

toString

public java.lang.String toString()

clear

public static void clear()

ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

The ESC/Java2 Project Homepage