langtools/src/share/classes/com/sun/tools/javac/util/DiagnosticFormatter.java
author mcimadamore
Thu, 24 Jul 2008 19:06:57 +0100
changeset 939 38e24969c7e9
parent 867 1dff24b5f407
permissions -rw-r--r--
6717241: some diagnostic argument is prematurely converted into a String object Summary: removed early toString() conversions applied to diagnostic arguments Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
735
372aa565a221 6719955: Update copyright year
xdono
parents: 731
diff changeset
     2
 * Copyright 2005-2008 Sun Microsystems, Inc.  All Rights Reserved.
10
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
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 867
diff changeset
    28
import java.util.Collection;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 10
diff changeset
    31
import com.sun.tools.javac.file.JavacFileManager;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * A formatter for diagnostic messages.
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * The formatter will format a diagnostic according to one of two format strings, depending on whether
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * or not the source name and position are set. The format is a printf-like string,
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * with the following special characters:
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * <ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * <li>%b: the base of the source name, or "-" if not set
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * <li>%f: the source name, or "-" if not set
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * <li>%l: the line number of the diagnostic, derived from the character offset if set, or "-" otherwise
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * <li>%c: the column number of the diagnostic, derived from the character offset if set, or "-" otherwise
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * <li>%o: the character offset of the diagnostic if set, or "-" otherwise
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * <li>%p: the prefix for the diagnostic, derived from the diagnostic type
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * <li>%t: the prefix as it normally appears in standard diagnostics. In this case, no prefix is
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *        shown if the type is ERROR and if a source name is set
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * <li>%m: the text or the diagnostic, including any appropriate arguments
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * </ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
public class DiagnosticFormatter {
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * A format string to be used for diagnostics with a given position.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    protected String posFormat;
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     * A format string to be used for diagnostics regarding classfiles
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    protected String classFormat = DEFAULT_CLASS_FORMAT;
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     * A format string to be used for diagnostics without a given position.
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    protected String noPosFormat;
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     * A value to indicate whether to output the i18n key and args, instead of
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     * the derived l10n message.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    protected boolean raw;
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    /** The context key for the formatter. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    protected static final Context.Key<DiagnosticFormatter> formatterKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
        new Context.Key<DiagnosticFormatter>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    /** Get the DiagnosticFormatter instance for this context. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    public static DiagnosticFormatter instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        DiagnosticFormatter instance = context.get(formatterKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
            instance = new DiagnosticFormatter(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     * Create a formatter based on the supplied options.
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    protected DiagnosticFormatter(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        Options options = Options.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        raw = options.get("rawDiagnostics") != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        String fmt = options.get("diags");
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        if (fmt != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
            int sep = fmt.indexOf('|');
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
            if (sep == -1)
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
                posFormat = noPosFormat = fmt;
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
            else {
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
                posFormat = fmt.substring(0, sep);
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
                noPosFormat = fmt.substring(sep + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
            posFormat = DEFAULT_POS_FORMAT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
            noPosFormat = DEFAULT_NO_POS_FORMAT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    public static final String DEFAULT_POS_FORMAT = "%f:%l: %t%m";
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    public static final String DEFAULT_CLASS_FORMAT = "%f: %t%m";
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    public static final String DEFAULT_NO_POS_FORMAT = "%p%m";
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    public DiagnosticFormatter() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        posFormat = DEFAULT_POS_FORMAT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        noPosFormat = DEFAULT_NO_POS_FORMAT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        raw = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    public DiagnosticFormatter(String pos, String noPos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        posFormat = pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        noPosFormat = noPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        raw = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    String format(JCDiagnostic d) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        return (raw ? format_raw(d) : format_std(d));
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    private String format_raw(JCDiagnostic d) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        DiagnosticSource source = d.getDiagnosticSource();
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        int position = d.getIntPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        StringBuilder sb = new StringBuilder();
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        if (position == Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
            sb.append("-");
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
            sb.append(source.getName() + ":" + source.getLineNumber(position) + ":" + source.getColumnNumber(position) + ":");
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        sb.append(" ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        sb.append(d.getCode());
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        String sep = ": ";
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        for (Object arg: d.getArgs()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
            sb.append(sep);
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            if (arg instanceof JCDiagnostic) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
                sb.append('(');
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
                sb.append(format_raw((JCDiagnostic) arg));
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
                sb.append(')');
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
            else if (arg instanceof JavaFileObject)
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
                sb.append(JavacFileManager.getJavacBaseFileName((JavaFileObject) arg));
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 867
diff changeset
   149
            else if (arg instanceof Collection<?>)
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 867
diff changeset
   150
                sb.append(convert((Collection<?>)arg));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
                sb.append(arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
            sep = ", ";
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        return sb.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 867
diff changeset
   158
    static <T> List<T> convert(Collection<T> c) {
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 867
diff changeset
   159
        if (c instanceof List<?>)
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 867
diff changeset
   160
            return (List<T>)c;
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 867
diff changeset
   161
        else {
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 867
diff changeset
   162
            List<T> l = List.<T>nil();
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 867
diff changeset
   163
            for (T t : c) {
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 867
diff changeset
   164
                l = l.prepend(t);
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 867
diff changeset
   165
            }
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 867
diff changeset
   166
            return l.reverse();
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 867
diff changeset
   167
        }
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 867
diff changeset
   168
    }
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 867
diff changeset
   169
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    private String format_std(JCDiagnostic d) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        DiagnosticSource source = d.getDiagnosticSource();
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        DiagnosticType type = d.getType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        int position = d.getIntPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
        String format = noPosFormat;
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        if (source != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
            if (position != Position.NOPOS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
                format = posFormat;
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
            } else if (source.getFile() != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
                       source.getFile().getKind() == JavaFileObject.Kind.CLASS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
                format = classFormat;
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        StringBuilder sb = new StringBuilder();
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        for (int i = 0; i < format.length(); i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
            char c = format.charAt(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
            if (c == '%' && i < format.length() - 1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
                c = format.charAt(++i);
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
                switch (c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
                case 'b':
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
                    sb.append(source == null ? "-" : source.getName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
                case 'e':
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
                    sb.append(position == Position.NOPOS ? "-" : String.valueOf(d.getEndPosition()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
                case 'f':
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
                    sb.append(source == null ? "-" : d.getSourceName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
                case 'l':
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
                    sb.append(position == Position.NOPOS ? "-" : String.valueOf(d.getLineNumber()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
                case 'c':
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
                    sb.append(position == Position.NOPOS ? "-" : String.valueOf(d.getColumnNumber()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
                case 'o':
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
                    sb.append(position == Position.NOPOS ? "-" : String.valueOf(position));
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
                case 'p':
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
                    sb.append(d.getPrefix());
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
                case 's':
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
                    sb.append(position == Position.NOPOS ? "-" : String.valueOf(d.getStartPosition()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
                case 't': {
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
                    boolean usePrefix;
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
                    switch (type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
                    case FRAGMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
                        usePrefix = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
                    case ERROR:
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
                        usePrefix = (position == Position.NOPOS);
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
                    default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
                        usePrefix = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
                    if (usePrefix)
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
                        sb.append(d.getPrefix());
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
                case 'm':
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
                    sb.append(d.getMessage(null));
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
                case '_':
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
                    sb.append(' ');
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
                case '%':
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
                    sb.append('%');
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
                default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
                    sb.append(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
                sb.append(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        return sb.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
}