langtools/src/share/classes/com/sun/tools/javac/util/Log.java
author jjg
Wed, 25 Jun 2008 14:24:53 -0700
changeset 813 ab91293d33f4
parent 731 1dd22bdb9ca5
child 815 bcb5c0d7c1ab
permissions -rw-r--r--
6507179: javadoc -source 1.3 does not work with jdk6 Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2006 Sun Microsystems, Inc.  All Rights Reserved.
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.util;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.nio.CharBuffer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.util.HashMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.util.HashSet;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.util.Map;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import java.util.Set;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import javax.tools.DiagnosticListener;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import javax.tools.JavaFileObject;
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 167
diff changeset
    36
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 167
diff changeset
    37
import com.sun.tools.javac.file.JavacFileManager;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.javac.tree.JCTree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition;
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 167
diff changeset
    42
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import static com.sun.tools.javac.util.LayoutCharacters.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
/** A class for error logs. Reports errors and warnings, and
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 *  keeps track of error numbers and positions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *  you write code that depends on this, you do so at your own risk.
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
public class Log {
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    /** The context key for the log. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    public static final Context.Key<Log> logKey
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
        = new Context.Key<Log>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    /** The context key for the output PrintWriter. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    public static final Context.Key<PrintWriter> outKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
        new Context.Key<PrintWriter>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    //@Deprecated
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    public final PrintWriter errWriter;
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    //@Deprecated
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    public final PrintWriter warnWriter;
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    //@Deprecated
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    public final PrintWriter noticeWriter;
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    /** The maximum number of errors/warnings that are reported.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    public final int MaxErrors;
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    public final int MaxWarnings;
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    /** Whether or not to display the line of source containing a diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    private final boolean showSourceLine;
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    /** Switch: prompt user on each error.
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    public boolean promptOnError;
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    /** Switch: emit warning messages.
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    public boolean emitWarnings;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    /** Print stack trace on errors?
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    public boolean dumpOnError;
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    /** Print multiple errors for same source locations.
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    public boolean multipleErrors;
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     * Diagnostic listener, if provided through programmatic
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     * interface to javac (JSR 199).
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    protected DiagnosticListener<? super JavaFileObject> diagListener;
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     * Formatter for diagnostics
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    private DiagnosticFormatter diagFormatter;
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     * Factory for diagnostics
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    private JCDiagnostic.Factory diags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    /** Construct a log with given I/O redirections.
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    @Deprecated
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    protected Log(Context context, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        context.put(logKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        this.errWriter = errWriter;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        this.warnWriter = warnWriter;
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        this.noticeWriter = noticeWriter;
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        this.diags = JCDiagnostic.Factory.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        Options options = Options.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        this.dumpOnError = options.get("-doe") != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        this.promptOnError = options.get("-prompt") != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        this.emitWarnings = options.get("-Xlint:none") == null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        this.MaxErrors = getIntOption(options, "-Xmaxerrs", 100);
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        this.MaxWarnings = getIntOption(options, "-Xmaxwarns", 100);
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        this.showSourceLine = options.get("rawDiagnostics") == null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        this.diagFormatter = DiagnosticFormatter.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        @SuppressWarnings("unchecked") // FIXME
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
        DiagnosticListener<? super JavaFileObject> diagListener =
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
            context.get(DiagnosticListener.class);
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        this.diagListener = diagListener;
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    // where
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        private int getIntOption(Options options, String optionName, int defaultValue) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
            String s = options.get(optionName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
                if (s != null) return Integer.parseInt(s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            } catch (NumberFormatException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
                // silently ignore ill-formed numbers
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
            return defaultValue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    /** The default writer for diagnostics
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    static final PrintWriter defaultWriter(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        PrintWriter result = context.get(outKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
        if (result == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
            context.put(outKey, result = new PrintWriter(System.err));
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    /** Construct a log with default settings.
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    protected Log(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        this(context, defaultWriter(context));
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    /** Construct a log with all output redirected.
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    protected Log(Context context, PrintWriter defaultWriter) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        this(context, defaultWriter, defaultWriter, defaultWriter);
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    /** Get the Log instance for this context. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    public static Log instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        Log instance = context.get(logKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
            instance = new Log(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    /** The file that's currently translated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    protected JCDiagnostic.DiagnosticSource source;
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    /** The number of errors encountered so far.
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    public int nerrors = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    /** The number of warnings encountered so far.
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    public int nwarnings = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    /** A set of all errors generated so far. This is used to avoid printing an
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     *  error message more than once. For each error, a pair consisting of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     *  source file name and source code position of the error is added to the set.
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    private Set<Pair<JavaFileObject, Integer>> recorded = new HashSet<Pair<JavaFileObject,Integer>>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
    private Map<JavaFileObject, Map<JCTree, Integer>> endPosTables;
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    /** The buffer containing the file that's currently translated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    private char[] buf = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
167
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   201
    /** The length of useful data in buf
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   202
     */
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   203
    private int bufLen = 0;
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   204
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    /** The position in the buffer at which last error was reported
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
    private int bp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
    /** number of the current source line; first line is 1
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
    private int line;
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
    /**  buffer index of the first character of the current source line
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
    private int lineStart;
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
    public boolean hasDiagnosticListener() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
        return diagListener != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
    public void setEndPosTable(JavaFileObject name, Map<JCTree, Integer> table) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        if (endPosTables == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
            endPosTables = new HashMap<JavaFileObject, Map<JCTree, Integer>>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
        endPosTables.put(name, table);
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
    /** Re-assign source, returning previous setting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
    public JavaFileObject useSource(final JavaFileObject name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        JavaFileObject prev = currentSource();
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        if (name != prev) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
            source = new JCDiagnostic.DiagnosticSource() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
                    public JavaFileObject getFile() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
                        return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
                    public CharSequence getName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
                        return JavacFileManager.getJavacBaseFileName(getFile());
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
                    public int getLineNumber(int pos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
                        return Log.this.getLineNumber(pos);
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
                    public int getColumnNumber(int pos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
                        return Log.this.getColumnNumber(pos);
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
                    public Map<JCTree, Integer> getEndPosTable() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
                        return (endPosTables == null ? null : endPosTables.get(name));
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
                };
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
            buf = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
        return prev;
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
    /** Re-assign source buffer for existing source name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
    protected void setBuf(char[] newBuf) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
        buf = newBuf;
167
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   258
        bufLen = buf.length;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
        bp = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        lineStart = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        line = 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
    protected char[] getBuf() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        return buf;
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
    /** Return current source name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    public JavaFileObject currentSource() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
        return source == null ? null : source.getFile();
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
    /** Flush the logs
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
    public void flush() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        errWriter.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        warnWriter.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        noticeWriter.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    /** Returns true if an error needs to be reported for a given
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
     * source name and pos.
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
    protected boolean shouldReport(JavaFileObject file, int pos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        if (multipleErrors || file == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
        Pair<JavaFileObject,Integer> coords = new Pair<JavaFileObject,Integer>(file, pos);
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
        boolean shouldReport = !recorded.contains(coords);
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        if (shouldReport)
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
            recorded.add(coords);
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        return shouldReport;
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    /** Prompt user after an error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
    public void prompt() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
        if (promptOnError) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
            System.err.println(getLocalizedString("resume.abort"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
            char ch;
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
                while (true) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
                    switch (System.in.read()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
                    case 'a': case 'A':
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
                        System.exit(-1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
                        return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
                    case 'r': case 'R':
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
                        return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
                    case 'x': case 'X':
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
                        throw new AssertionError("user abort");
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
                    default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
            } catch (IOException e) {}
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
    /** Print the faulty source code line and point to the error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
     *  @param pos   Buffer index of the error position, must be on current line
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
    private void printErrLine(int pos, PrintWriter writer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
        if (!findLine(pos))
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
        int lineEnd = lineStart;
167
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   327
        while (lineEnd < bufLen && buf[lineEnd] != CR && buf[lineEnd] != LF)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
            lineEnd++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        if (lineEnd - lineStart == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
        printLines(writer, new String(buf, lineStart, lineEnd - lineStart));
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
        for (bp = lineStart; bp < pos; bp++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
            writer.print((buf[bp] == '\t') ? "\t" : " ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        writer.println("^");
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        writer.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
167
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   339
    protected void initBuf(JavaFileObject fileObject) throws IOException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        CharSequence cs = fileObject.getCharContent(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
        if (cs instanceof CharBuffer) {
167
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   342
            CharBuffer cb = (CharBuffer) cs;
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   343
            buf = JavacFileManager.toArray(cb);
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   344
            bufLen = cb.limit();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
        } else {
167
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   346
            buf = cs.toString().toCharArray();
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   347
            bufLen = buf.length;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
    /** Find the line in the buffer that contains the current position
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
     * @param pos      Character offset into the buffer
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
    private boolean findLine(int pos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        if (pos == Position.NOPOS || currentSource() == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
            if (buf == null) {
167
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   359
                initBuf(currentSource());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
                lineStart = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
                line = 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
            } else if (lineStart > pos) { // messages don't come in order
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
                lineStart = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
                line = 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
            bp = lineStart;
167
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   367
            while (bp < bufLen && bp < pos) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
                switch (buf[bp++]) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
                case CR:
167
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   370
                    if (bp < bufLen && buf[bp] == LF) bp++;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
                    line++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
                    lineStart = bp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
                case LF:
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
                    line++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
                    lineStart = bp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
            }
167
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   380
            return bp <= bufLen;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
            //e.printStackTrace();
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
            // FIXME: include e.getLocalizedMessage() in error message
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
            printLines(errWriter, getLocalizedString("source.unavailable"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
            errWriter.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
            buf = new char[0];
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
    /** Print the text of a message, translating newlines appropriately
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
     *  for the platform.
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
    public static void printLines(PrintWriter writer, String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        int nl;
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
        while ((nl = msg.indexOf('\n')) != -1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
            writer.println(msg.substring(0, nl));
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
            msg = msg.substring(nl+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
        if (msg.length() != 0) writer.println(msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
    /** Report an error, unless another error was already reported at same
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
     *  source position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
     *  @param key    The key for the localized error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
     *  @param args   Fields of the error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
    public void error(String key, Object ... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
        report(diags.error(source, null, key, args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
    /** Report an error, unless another error was already reported at same
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
     *  source position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
     *  @param pos    The source position at which to report the error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
     *  @param key    The key for the localized error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
     *  @param args   Fields of the error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
    public void error(DiagnosticPosition pos, String key, Object ... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
        report(diags.error(source, pos, key, args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
    /** Report an error, unless another error was already reported at same
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
     *  source position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
     *  @param pos    The source position at which to report the error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
     *  @param key    The key for the localized error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
     *  @param args   Fields of the error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
    public void error(int pos, String key, Object ... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
        report(diags.error(source, wrap(pos), key, args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
    /** Report a warning, unless suppressed by the  -nowarn option or the
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
     *  maximum number of warnings has been reached.
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
     *  @param pos    The source position at which to report the warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
     *  @param key    The key for the localized warning message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
     *  @param args   Fields of the warning message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
    public void warning(String key, Object ... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
        report(diags.warning(source, null, key, args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
    /** Report a warning, unless suppressed by the  -nowarn option or the
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
     *  maximum number of warnings has been reached.
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
     *  @param pos    The source position at which to report the warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
     *  @param key    The key for the localized warning message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
     *  @param args   Fields of the warning message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
    public void warning(DiagnosticPosition pos, String key, Object ... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
        report(diags.warning(source, pos, key, args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
    /** Report a warning, unless suppressed by the  -nowarn option or the
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
     *  maximum number of warnings has been reached.
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
     *  @param pos    The source position at which to report the warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
     *  @param key    The key for the localized warning message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
     *  @param args   Fields of the warning message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
    public void warning(int pos, String key, Object ... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
        report(diags.warning(source, wrap(pos), key, args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
    /** Report a warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
     *  @param pos    The source position at which to report the warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
     *  @param key    The key for the localized warning message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
     *  @param args   Fields of the warning message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
    public void mandatoryWarning(DiagnosticPosition pos, String key, Object ... args) {
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   468
        report(diags.mandatoryWarning(source, pos, key, args));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
    /** Report a warning that cannot be suppressed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
     *  @param pos    The source position at which to report the warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
     *  @param key    The key for the localized warning message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
     *  @param args   Fields of the warning message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
    public void strictWarning(DiagnosticPosition pos, String key, Object ... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
        writeDiagnostic(diags.warning(source, pos, key, args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
        nwarnings++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
     *  @param key    The key for the localized notification message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
     *  @param args   Fields of the notification message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
    public void note(String key, Object ... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
        report(diags.note(source, null, key, args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
     *  @param key    The key for the localized notification message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
     *  @param args   Fields of the notification message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
    public void note(DiagnosticPosition pos, String key, Object ... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
        report(diags.note(source, pos, key, args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
     *  @param key    The key for the localized notification message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
     *  @param args   Fields of the notification message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
    public void note(int pos, String key, Object ... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
        report(diags.note(source, wrap(pos), key, args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   506
     *  @param file   The file to which the note applies.
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   507
     *  @param key    The key for the localized notification message.
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   508
     *  @param args   Fields of the notification message.
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   509
     */
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   510
    public void note(JavaFileObject file, String key, Object ... args) {
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   511
        report(diags.note(wrap(file), null, key, args));
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   512
    }
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   513
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   514
    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
     *  @param key    The key for the localized notification message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
     *  @param args   Fields of the notification message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
    public void mandatoryNote(final JavaFileObject file, String key, Object ... args) {
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   519
        report(diags.mandatoryNote(wrap(file), key, args));
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   520
    }
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   521
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   522
    private JCDiagnostic.DiagnosticSource wrap(final JavaFileObject file) {
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   523
        if (file == null) {
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   524
            return null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
        }
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   526
        return new JCDiagnostic.DiagnosticSource() {
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   527
            public JavaFileObject getFile() {
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   528
                return file;
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   529
            }
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   530
            public CharSequence getName() {
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   531
                return JavacFileManager.getJavacBaseFileName(getFile());
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   532
            }
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   533
            public int getLineNumber(int pos) {
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   534
                return Log.this.getLineNumber(pos);
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   535
            }
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   536
            public int getColumnNumber(int pos) {
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   537
                return Log.this.getColumnNumber(pos);
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   538
            }
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   539
            public Map<JCTree, Integer> getEndPosTable() {
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   540
                return (endPosTables == null ? null : endPosTables.get(file));
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   541
            }
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 731
diff changeset
   542
        };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
    private DiagnosticPosition wrap(int pos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
        return (pos == Position.NOPOS ? null : new SimpleDiagnosticPosition(pos));
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
     * Common diagnostic handling.
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
     * The diagnostic is counted, and depending on the options and how many diagnostics have been
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
     * reported so far, the diagnostic may be handed off to writeDiagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
    public void report(JCDiagnostic diagnostic) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
        switch (diagnostic.getType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
        case FRAGMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
            throw new IllegalArgumentException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
        case NOTE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
            // Print out notes only when we are permitted to report warnings
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
            // Notes are only generated at the end of a compilation, so should be small
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
            // in number.
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
            if (emitWarnings || diagnostic.isMandatory()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
                writeDiagnostic(diagnostic);
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
        case WARNING:
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
            if (emitWarnings || diagnostic.isMandatory()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
                if (nwarnings < MaxWarnings) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
                    writeDiagnostic(diagnostic);
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
                    nwarnings++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
        case ERROR:
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
            if (nerrors < MaxErrors
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
                && shouldReport(diagnostic.getSource(), diagnostic.getIntPosition())) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
                writeDiagnostic(diagnostic);
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
                nerrors++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
     * Write out a diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
    protected void writeDiagnostic(JCDiagnostic diag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
        if (diagListener != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
                diagListener.report(diag);
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
            catch (Throwable t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
                throw new ClientCodeException(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
        PrintWriter writer = getWriterForDiagnosticType(diag.getType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
        printLines(writer, diagFormatter.format(diag));
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
        if (showSourceLine) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
            int pos = diag.getIntPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
            if (pos != Position.NOPOS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
                JavaFileObject prev = useSource(diag.getSource());
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
                printErrLine(pos, writer);
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
                useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
        if (promptOnError) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
            switch (diag.getType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
            case ERROR:
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
            case WARNING:
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
                prompt();
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
        if (dumpOnError)
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
            new RuntimeException().printStackTrace(writer);
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
        writer.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
    @Deprecated
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
    protected PrintWriter getWriterForDiagnosticType(DiagnosticType dt) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
        switch (dt) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
        case FRAGMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
            throw new IllegalArgumentException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
        case NOTE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
            return noticeWriter;
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
        case WARNING:
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
            return warnWriter;
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
        case ERROR:
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
            return errWriter;
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
            throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
    /** Find a localized string in the resource bundle.
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
     *  @param key    The key for the localized string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
     *  @param args   Fields to substitute into the string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
    public static String getLocalizedString(String key, Object ... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
        return Messages.getDefaultLocalizedString("compiler.misc." + key, args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
/***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
 * raw error messages without internationalization; used for experimentation
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
 * and quick prototyping
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
 ***************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
/** print an error or warning message:
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
    private void printRawError(int pos, String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
        if (!findLine(pos)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
            printLines(errWriter, "error: " + msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
            JavaFileObject file = currentSource();
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
            if (file != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
                printLines(errWriter,
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
                           JavacFileManager.getJavacFileName(file) + ":" +
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
                           line + ": " + msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
            printErrLine(pos, errWriter);
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
        errWriter.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
/** report an error:
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
    public void rawError(int pos, String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
        if (nerrors < MaxErrors && shouldReport(currentSource(), pos)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
            printRawError(pos, msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
            prompt();
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
            nerrors++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
        errWriter.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
/** report a warning:
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
    public void rawWarning(int pos, String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
        if (nwarnings < MaxWarnings && emitWarnings) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
            printRawError(pos, "warning: " + msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
        prompt();
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
        nwarnings++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
        errWriter.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
    /** Return the one-based line number associated with a given pos
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
     * for the current source file.  Zero is returned if no line exists
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
     * for the given position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
    protected int getLineNumber(int pos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
        if (findLine(pos))
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
            return line;
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
        return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
    /** Return the one-based column number associated with a given pos
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
     * for the current source file.  Zero is returned if no column exists
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
     * for the given position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
    protected int getColumnNumber(int pos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
        if (findLine(pos)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
            int column = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
            for (bp = lineStart; bp < pos; bp++) {
167
f4b81c733bea 6668802: javac handles diagnostics for last line badly, if line not terminated by newline
jjg
parents: 10
diff changeset
   716
                if (bp >= bufLen)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
                    return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
                if (buf[bp] == '\t')
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
                    column = (column / TabInc * TabInc) + TabInc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
                    column++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
            return column + 1; // positions are one-based
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
        return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
    public static String format(String fmt, Object... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
        return String.format((java.util.Locale)null, fmt, args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
}