com.sun.tools.javac.util
Class DiagnosticSource

java.lang.Object
  extended by com.sun.tools.javac.util.DiagnosticSource

public class DiagnosticSource
extends java.lang.Object

A simple abstraction of a source file, as needed for use in a diagnostic message. Provides access to the line and position in a line for any given character offset.

This is NOT part of any API supported by Sun Microsystems. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.


Field Summary
protected  char[] buf
          A temporary hard reference to the content of the file object.
protected  int bufLen
          The length of the content.
protected  java.util.Map<JCTree,java.lang.Integer> endPosTable
           
protected  JavaFileObject fileObject
          The underlying file object.
protected  int line
          The line number of a line found by findLine.
protected  int lineStart
          The start of a line found by findLine.
protected  AbstractLog log
          A log for reporting errors, such as errors accessing the content.
protected  java.lang.ref.SoftReference<char[]> refBuf
          A soft reference to the content of the file object.
 
Constructor Summary
DiagnosticSource(JavaFileObject fo, AbstractLog log)
           
 
Method Summary
private  boolean findLine(int pos)
          Find the line in the buffer that contains the current position
 int getColumnNumber(int pos, boolean expandTabs)
          Return the one-based column number associated with a given pos for the current source file.
 java.util.Map<JCTree,java.lang.Integer> getEndPosTable()
           
 JavaFileObject getFile()
          Return the underlying file object handled by this DiagnosticSource object.
 java.lang.String getLine(int pos)
          Return the content of the line containing a given pos.
 int getLineNumber(int pos)
          Return the one-based line number associated with a given pos for the current source file.
 java.lang.CharSequence getName()
           
protected  char[] initBuf(JavaFileObject fileObject)
           
 void setEndPosTable(java.util.Map<JCTree,java.lang.Integer> t)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileObject

protected JavaFileObject fileObject
The underlying file object.


endPosTable

protected java.util.Map<JCTree,java.lang.Integer> endPosTable

refBuf

protected java.lang.ref.SoftReference<char[]> refBuf
A soft reference to the content of the file object.


buf

protected char[] buf
A temporary hard reference to the content of the file object.


bufLen

protected int bufLen
The length of the content.


lineStart

protected int lineStart
The start of a line found by findLine.


line

protected int line
The line number of a line found by findLine.


log

protected AbstractLog log
A log for reporting errors, such as errors accessing the content.

Constructor Detail

DiagnosticSource

public DiagnosticSource(JavaFileObject fo,
                        AbstractLog log)
Method Detail

getFile

public JavaFileObject getFile()
Return the underlying file object handled by this DiagnosticSource object.


getName

public java.lang.CharSequence getName()

getLineNumber

public int getLineNumber(int pos)
Return the one-based line number associated with a given pos for the current source file. Zero is returned if no line exists for the given position.


getColumnNumber

public int getColumnNumber(int pos,
                           boolean expandTabs)
Return the one-based column number associated with a given pos for the current source file. Zero is returned if no column exists for the given position.


getLine

public java.lang.String getLine(int pos)
Return the content of the line containing a given pos.


getEndPosTable

public java.util.Map<JCTree,java.lang.Integer> getEndPosTable()

setEndPosTable

public void setEndPosTable(java.util.Map<JCTree,java.lang.Integer> t)

findLine

private boolean findLine(int pos)
Find the line in the buffer that contains the current position

Parameters:
pos - Character offset into the buffer

initBuf

protected char[] initBuf(JavaFileObject fileObject)
                  throws java.io.IOException
Throws:
java.io.IOException