langtools/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java
author briangoetz
Wed, 18 Dec 2013 16:05:18 -0500
changeset 22163 3651128c74eb
parent 14258 8d2148961366
permissions -rw-r--r--
8030244: Update langtools to use Diamond Reviewed-by: darcy
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
/*
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 11055
diff changeset
     2
 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
867
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
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3995
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
867
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
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3995
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
867
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
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3995
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3995
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3995
diff changeset
    23
 * questions.
867
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 javax.tools.JavaFileObject;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    32
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    33
import com.sun.tools.javac.file.JavacFileManager;
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 11055
diff changeset
    34
import com.sun.tools.javac.tree.EndPosTable;
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    35
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    36
import static com.sun.tools.javac.util.LayoutCharacters.*;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    37
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
 * 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
    40
 * 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
    41
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    42
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    43
 *  If you write code that depends on this, you do so at your own risk.
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    44
 *  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
    45
 *  deletion without notice.</b>
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    46
 */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    47
public class DiagnosticSource {
3144
202fa249dc34 6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents: 1109
diff changeset
    48
202fa249dc34 6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents: 1109
diff changeset
    49
    /* constant DiagnosticSource to be used when sourcefile is missing */
202fa249dc34 6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents: 1109
diff changeset
    50
    public static final DiagnosticSource NO_SOURCE = new DiagnosticSource() {
202fa249dc34 6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents: 1109
diff changeset
    51
        @Override
202fa249dc34 6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents: 1109
diff changeset
    52
        protected boolean findLine(int pos) {
202fa249dc34 6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents: 1109
diff changeset
    53
            return false;
202fa249dc34 6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents: 1109
diff changeset
    54
        }
202fa249dc34 6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents: 1109
diff changeset
    55
    };
202fa249dc34 6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents: 1109
diff changeset
    56
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    57
    public DiagnosticSource(JavaFileObject fo, AbstractLog log) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    58
        this.fileObject = fo;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    59
        this.log = log;
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
3144
202fa249dc34 6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents: 1109
diff changeset
    62
    private DiagnosticSource() {}
202fa249dc34 6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents: 1109
diff changeset
    63
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    64
    /** Return the underlying file object handled by this
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    65
     *  DiagnosticSource object.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    66
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    67
    public JavaFileObject getFile() {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    68
        return fileObject;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    69
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    70
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    71
    /** 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
    72
     * 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
    73
     * for the given position.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    74
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    75
    public int getLineNumber(int pos) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    76
        try {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    77
            if (findLine(pos)) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    78
                return line;
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 0;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    81
        } finally {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    82
            buf = null;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    83
        }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    84
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    85
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    86
    /** 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
    87
     * 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
    88
     * for the given position.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    89
     */
1109
853d8c191eac 6733837: Recent work on javac diagnostic affected javac output
mcimadamore
parents: 867
diff changeset
    90
    public int getColumnNumber(int pos, boolean expandTabs) {
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    91
        try {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    92
            if (findLine(pos)) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    93
                int column = 0;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    94
                for (int bp = lineStart; bp < pos; bp++) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    95
                    if (bp >= bufLen) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    96
                        return 0;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    97
                    }
1109
853d8c191eac 6733837: Recent work on javac diagnostic affected javac output
mcimadamore
parents: 867
diff changeset
    98
                    if (buf[bp] == '\t' && expandTabs) {
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    99
                        column = (column / TabInc * TabInc) + TabInc;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   100
                    } else {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   101
                        column++;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   102
                    }
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
                return column + 1; // positions are one-based
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 0;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   107
        } finally {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   108
            buf = null;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   109
        }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   110
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   111
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   112
    /** 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
   113
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   114
    public String getLine(int pos) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   115
        try {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   116
            if (!findLine(pos))
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
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   119
            int lineEnd = lineStart;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   120
            while (lineEnd < bufLen && buf[lineEnd] != CR && buf[lineEnd] != LF)
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   121
                lineEnd++;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   122
            if (lineEnd - lineStart == 0)
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   123
                return null;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   124
            return new String(buf, lineStart, lineEnd - lineStart);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   125
        } finally {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   126
            buf = null;
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
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   129
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 5847
diff changeset
   130
    public EndPosTable getEndPosTable() {
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   131
        return endPosTable;
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
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 5847
diff changeset
   134
    public void setEndPosTable(EndPosTable t) {
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   135
        if (endPosTable != null && endPosTable != t)
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   136
            throw new IllegalStateException("endPosTable already set");
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   137
        endPosTable = t;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   138
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   139
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   140
    /** 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
   141
     * @param pos      Character offset into the buffer
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   142
     */
3144
202fa249dc34 6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents: 1109
diff changeset
   143
    protected boolean findLine(int pos) {
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   144
        if (pos == Position.NOPOS)
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   145
            return false;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   146
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   147
        try {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   148
            // try and recover buffer from soft reference cache
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   149
            if (buf == null && refBuf != null)
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   150
                buf = refBuf.get();
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   151
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   152
            if (buf == null) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   153
                buf = initBuf(fileObject);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   154
                lineStart = 0;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   155
                line = 1;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   156
            } 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
   157
                lineStart = 0;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   158
                line = 1;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   159
            }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   160
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   161
            int bp = lineStart;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   162
            while (bp < bufLen && bp < pos) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   163
                switch (buf[bp++]) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   164
                case CR:
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   165
                    if (bp < bufLen && buf[bp] == LF) bp++;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   166
                    line++;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   167
                    lineStart = bp;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   168
                    break;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   169
                case LF:
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   170
                    line++;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   171
                    lineStart = bp;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   172
                    break;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   173
                }
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
            return bp <= bufLen;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   176
        } catch (IOException e) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   177
            log.directError("source.unavailable");
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   178
            buf = new char[0];
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   179
            return false;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   180
        }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   181
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   182
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   183
    protected char[] initBuf(JavaFileObject fileObject) throws IOException {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   184
        char[] buf;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   185
        CharSequence cs = fileObject.getCharContent(true);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   186
        if (cs instanceof CharBuffer) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   187
            CharBuffer cb = (CharBuffer) cs;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   188
            buf = JavacFileManager.toArray(cb);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   189
            bufLen = cb.limit();
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   190
        } else {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   191
            buf = cs.toString().toCharArray();
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   192
            bufLen = buf.length;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   193
        }
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14258
diff changeset
   194
        refBuf = new SoftReference<>(buf);
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   195
        return buf;
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
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   198
    /** The underlying file object. */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   199
    protected JavaFileObject fileObject;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   200
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 5847
diff changeset
   201
    protected EndPosTable endPosTable;
867
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
    /** 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
   204
    protected SoftReference<char[]> refBuf;
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
    /** 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
   207
    protected char[] buf;
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 length of the content. */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   210
    protected int bufLen;
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
    /** The start of a line found by findLine. */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   213
    protected int lineStart;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   214
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   215
    /** The line number of a line found by findLine. */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   216
    protected int line;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   217
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   218
    /** 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
   219
    protected AbstractLog log;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   220
}