langtools/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java
author mcimadamore
Fri, 22 Aug 2008 11:46:29 +0100
changeset 1109 853d8c191eac
parent 867 1dff24b5f407
child 3144 202fa249dc34
permissions -rw-r--r--
6733837: Recent work on javac diagnostic affected javac output Summary: Problems with diagnostic path and tab character in the source code Reviewed-by: darcy, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
     1
/*
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
     2
 * Copyright 1999-2008 Sun Microsystems, Inc.  All Rights Reserved.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
     4
 *
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    10
 *
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    15
 * accompanied this code).
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    16
 *
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    20
 *
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    23
 * have any questions.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    24
 */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    25
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    26
package com.sun.tools.javac.util;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    27
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    28
import java.io.IOException;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    29
import java.lang.ref.SoftReference;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    30
import java.nio.CharBuffer;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    31
import java.util.Map;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    32
import javax.tools.JavaFileObject;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    33
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    34
import com.sun.tools.javac.file.JavacFileManager;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    35
import com.sun.tools.javac.tree.JCTree;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    36
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    37
import static com.sun.tools.javac.util.LayoutCharacters.*;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    38
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    39
/**
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    40
 * A simple abstraction of a source file, as needed for use in a diagnostic message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    41
 * Provides access to the line and position in a line for any given character offset.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    42
 *
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    43
 *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    44
 *  you write code that depends on this, you do so at your own risk.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    45
 *  This code and its internal interfaces are subject to change or
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    46
 *  deletion without notice.</b>
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    47
 */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    48
public class DiagnosticSource {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    49
    public DiagnosticSource(JavaFileObject fo, AbstractLog log) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    50
        this.fileObject = fo;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    51
        this.log = log;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    52
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    53
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    54
    /** Return the underlying file object handled by this
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    55
     *  DiagnosticSource object.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    56
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    57
    public JavaFileObject getFile() {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    58
        return fileObject;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    59
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    60
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    61
    public CharSequence getName()  {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    62
        return JavacFileManager.getJavacBaseFileName(fileObject);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    63
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    64
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    65
    /** Return the one-based line number associated with a given pos
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    66
     * for the current source file.  Zero is returned if no line exists
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    67
     * for the given position.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    68
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    69
    public int getLineNumber(int pos) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    70
        try {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    71
            if (findLine(pos)) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    72
                return line;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    73
            }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    74
            return 0;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    75
        } finally {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    76
            buf = null;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    77
        }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    78
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    79
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    80
    /** Return the one-based column number associated with a given pos
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    81
     * for the current source file.  Zero is returned if no column exists
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    82
     * for the given position.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    83
     */
1109
853d8c191eac 6733837: Recent work on javac diagnostic affected javac output
mcimadamore
parents: 867
diff changeset
    84
    public int getColumnNumber(int pos, boolean expandTabs) {
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    85
        try {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    86
            if (findLine(pos)) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    87
                int column = 0;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    88
                for (int bp = lineStart; bp < pos; bp++) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    89
                    if (bp >= bufLen) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    90
                        return 0;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    91
                    }
1109
853d8c191eac 6733837: Recent work on javac diagnostic affected javac output
mcimadamore
parents: 867
diff changeset
    92
                    if (buf[bp] == '\t' && expandTabs) {
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    93
                        column = (column / TabInc * TabInc) + TabInc;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    94
                    } else {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    95
                        column++;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    96
                    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    97
                }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    98
                return column + 1; // positions are one-based
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    99
            }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   100
            return 0;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   101
        } finally {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   102
            buf = null;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   103
        }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   104
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   105
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   106
    /** Return the content of the line containing a given pos.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   107
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   108
    public String getLine(int pos) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   109
        try {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   110
            if (!findLine(pos))
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   111
                return null;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   112
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   113
            int lineEnd = lineStart;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   114
            while (lineEnd < bufLen && buf[lineEnd] != CR && buf[lineEnd] != LF)
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   115
                lineEnd++;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   116
            if (lineEnd - lineStart == 0)
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   117
                return null;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   118
            return new String(buf, lineStart, lineEnd - lineStart);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   119
        } finally {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   120
            buf = null;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   121
        }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   122
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   123
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   124
    public Map<JCTree, Integer> getEndPosTable() {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   125
        return endPosTable;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   126
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   127
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   128
    public void setEndPosTable(Map<JCTree, Integer> t) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   129
        if (endPosTable != null && endPosTable != t)
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   130
            throw new IllegalStateException("endPosTable already set");
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   131
        endPosTable = t;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   132
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   133
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   134
    /** Find the line in the buffer that contains the current position
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   135
     * @param pos      Character offset into the buffer
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   136
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   137
    private boolean findLine(int pos) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   138
        if (pos == Position.NOPOS)
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   139
            return false;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   140
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   141
        try {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   142
            // try and recover buffer from soft reference cache
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   143
            if (buf == null && refBuf != null)
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   144
                buf = refBuf.get();
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   145
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   146
            if (buf == null) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   147
                buf = initBuf(fileObject);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   148
                lineStart = 0;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   149
                line = 1;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   150
            } else if (lineStart > pos) { // messages don't come in order
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   151
                lineStart = 0;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   152
                line = 1;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   153
            }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   154
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   155
            int bp = lineStart;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   156
            while (bp < bufLen && bp < pos) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   157
                switch (buf[bp++]) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   158
                case CR:
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   159
                    if (bp < bufLen && buf[bp] == LF) bp++;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   160
                    line++;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   161
                    lineStart = bp;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   162
                    break;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   163
                case LF:
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   164
                    line++;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   165
                    lineStart = bp;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   166
                    break;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   167
                }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   168
            }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   169
            return bp <= bufLen;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   170
        } catch (IOException e) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   171
            log.directError("source.unavailable");
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   172
            buf = new char[0];
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   173
            return false;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   174
        }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   175
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   176
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   177
    protected char[] initBuf(JavaFileObject fileObject) throws IOException {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   178
        char[] buf;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   179
        CharSequence cs = fileObject.getCharContent(true);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   180
        if (cs instanceof CharBuffer) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   181
            CharBuffer cb = (CharBuffer) cs;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   182
            buf = JavacFileManager.toArray(cb);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   183
            bufLen = cb.limit();
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   184
        } else {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   185
            buf = cs.toString().toCharArray();
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   186
            bufLen = buf.length;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   187
        }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   188
        refBuf = new SoftReference<char[]>(buf);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   189
        return buf;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   190
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   191
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   192
    /** The underlying file object. */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   193
    protected JavaFileObject fileObject;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   194
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   195
    protected Map<JCTree, Integer> endPosTable;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   196
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   197
    /** A soft reference to the content of the file object. */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   198
    protected SoftReference<char[]> refBuf;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   199
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   200
    /** A temporary hard reference to the content of the file object. */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   201
    protected char[] buf;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   202
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   203
    /** The length of the content. */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   204
    protected int bufLen;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   205
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   206
    /** The start of a line found by findLine. */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   207
    protected int lineStart;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   208
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   209
    /** The line number of a line found by findLine. */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   210
    protected int line;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   211
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   212
    /** A log for reporting errors, such as errors accessing the content. */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   213
    protected AbstractLog log;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   214
}