src/share/classes/com/sun/tools/javac/util/Log.java

changeset 10
508c01999047
parent 1
9a66ca7c79fa
child 50
b9bcea8bbe24
     1.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java	Thu Mar 06 10:07:25 2008 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java	Thu Mar 06 10:25:04 2008 -0800
     1.3 @@ -203,6 +203,10 @@
     1.4       */
     1.5      private char[] buf = null;
     1.6  
     1.7 +    /** The length of useful data in buf
     1.8 +     */
     1.9 +    private int bufLen = 0;
    1.10 +
    1.11      /** The position in the buffer at which last error was reported
    1.12       */
    1.13      private int bp;
    1.14 @@ -256,6 +260,7 @@
    1.15       */
    1.16      protected void setBuf(char[] newBuf) {
    1.17          buf = newBuf;
    1.18 +        bufLen = buf.length;
    1.19          bp = 0;
    1.20          lineStart = 0;
    1.21          line = 1;
    1.22 @@ -324,7 +329,7 @@
    1.23              return;
    1.24  
    1.25          int lineEnd = lineStart;
    1.26 -        while (lineEnd < buf.length && buf[lineEnd] != CR && buf[lineEnd] != LF)
    1.27 +        while (lineEnd < bufLen && buf[lineEnd] != CR && buf[lineEnd] != LF)
    1.28              lineEnd++;
    1.29          if (lineEnd - lineStart == 0)
    1.30              return;
    1.31 @@ -336,12 +341,15 @@
    1.32          writer.flush();
    1.33      }
    1.34  
    1.35 -    protected static char[] getCharContent(JavaFileObject fileObject) throws IOException {
    1.36 +    protected void initBuf(JavaFileObject fileObject) throws IOException {
    1.37          CharSequence cs = fileObject.getCharContent(true);
    1.38          if (cs instanceof CharBuffer) {
    1.39 -            return JavacFileManager.toArray((CharBuffer)cs);
    1.40 +            CharBuffer cb = (CharBuffer) cs;
    1.41 +            buf = JavacFileManager.toArray(cb);
    1.42 +            bufLen = cb.limit();
    1.43          } else {
    1.44 -            return cs.toString().toCharArray();
    1.45 +            buf = cs.toString().toCharArray();
    1.46 +            bufLen = buf.length;
    1.47          }
    1.48      }
    1.49  
    1.50 @@ -353,7 +361,7 @@
    1.51              return false;
    1.52          try {
    1.53              if (buf == null) {
    1.54 -                buf = getCharContent(currentSource());
    1.55 +                initBuf(currentSource());
    1.56                  lineStart = 0;
    1.57                  line = 1;
    1.58              } else if (lineStart > pos) { // messages don't come in order
    1.59 @@ -361,10 +369,10 @@
    1.60                  line = 1;
    1.61              }
    1.62              bp = lineStart;
    1.63 -            while (bp < buf.length && bp < pos) {
    1.64 +            while (bp < bufLen && bp < pos) {
    1.65                  switch (buf[bp++]) {
    1.66                  case CR:
    1.67 -                    if (bp < buf.length && buf[bp] == LF) bp++;
    1.68 +                    if (bp < bufLen && buf[bp] == LF) bp++;
    1.69                      line++;
    1.70                      lineStart = bp;
    1.71                      break;
    1.72 @@ -374,7 +382,7 @@
    1.73                      break;
    1.74                  }
    1.75              }
    1.76 -            return bp <= buf.length;
    1.77 +            return bp <= bufLen;
    1.78          } catch (IOException e) {
    1.79              //e.printStackTrace();
    1.80              // FIXME: include e.getLocalizedMessage() in error message
    1.81 @@ -704,7 +712,7 @@
    1.82          if (findLine(pos)) {
    1.83              int column = 0;
    1.84              for (bp = lineStart; bp < pos; bp++) {
    1.85 -                if (bp >= buf.length)
    1.86 +                if (bp >= bufLen)
    1.87                      return 0;
    1.88                  if (buf[bp] == '\t')
    1.89                      column = (column / TabInc * TabInc) + TabInc;

mercurial