langtools/test/tools/javac/Diagnostics/6769027/T6769027.java
author jjg
Wed, 23 Sep 2009 18:48:13 -0700
changeset 3995 73af8b6fb8bc
parent 2085 4792e12a8ca2
child 5520 86e4b9a9da40
permissions -rw-r--r--
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject. 6747645: ZipFileObject.getName is incorrectly deprecated 6885123: JavaFileObject getName issues Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2085
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
     1
/*
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
     4
 *
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
     8
 *
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    13
 * accompanied this code).
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    14
 *
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    18
 *
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    21
 * have any questions.
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    22
 */
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    23
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    24
/**
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    25
 * @test
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    26
 * @bug     6769027
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    27
 * @summary Source line should be displayed immediately after the first diagnostic line
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    28
 * @author  Maurizio Cimadamore
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    29
 * @run main/othervm T6769027
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    30
 */
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    31
import java.net.URI;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    32
import java.util.regex.Matcher;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    33
import javax.tools.*;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    34
import com.sun.tools.javac.util.*;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    35
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    36
public class T6769027 {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    37
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    38
    enum OutputKind {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    39
        RAW("rawDiagnostics","rawDiagnostics"),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    40
        BASIC("","");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    41
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    42
        String key;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    43
        String value;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    44
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    45
        void init(Options opts) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    46
            opts.put(key, value);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    47
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    48
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    49
        OutputKind(String key, String value) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    50
            this.key = key;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    51
            this.value = value;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    52
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    53
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    54
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    55
    enum CaretKind {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    56
        DEFAULT("", ""),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    57
        SHOW("showCaret","true"),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    58
        HIDE("showCaret","false");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    59
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    60
        String key;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    61
        String value;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    62
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    63
        void init(Options opts) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    64
            opts.put(key, value);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    65
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    66
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    67
        CaretKind(String key, String value) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    68
            this.key = key;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    69
            this.value = value;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    70
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    71
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    72
        boolean isEnabled() {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    73
            return this == DEFAULT || this == SHOW;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    74
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    75
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    76
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    77
    enum SourceLineKind {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    78
        DEFAULT("", ""),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    79
        AFTER_SUMMARY("sourcePosition", "top"),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    80
        BOTTOM("sourcePosition", "bottom");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    81
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    82
        String key;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    83
        String value;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    84
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    85
        void init(Options opts) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    86
            opts.put(key, value);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    87
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    88
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    89
        SourceLineKind(String key, String value) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    90
            this.key = key;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    91
            this.value = value;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    92
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    93
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    94
        boolean isAfterSummary() {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    95
            return this == DEFAULT || this == AFTER_SUMMARY;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    96
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    97
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    98
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
    99
    enum XDiagsSource {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   100
        DEFAULT(""),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   101
        SOURCE("source"),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   102
        NO_SOURCE("-source");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   103
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   104
        String flag;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   105
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   106
        void init(Options opts) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   107
            if (this != DEFAULT) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   108
                String flags = opts.get("diags");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   109
                flags = flags == null ? flag : flags + "," + flag;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   110
                opts.put("diags", flags);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   111
            }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   112
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   113
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   114
        XDiagsSource(String flag) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   115
            this.flag = flag;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   116
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   117
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   118
        String getOutput(CaretKind caretKind, IndentKind indent, OutputKind outKind) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   119
            String spaces = (outKind == OutputKind.BASIC) ? indent.string : "";
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   120
            return "\n" + spaces + "This is a source line" +
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   121
                   (caretKind.isEnabled() ? "\n" + spaces + "     ^" : "");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   122
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   123
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   124
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   125
    enum XDiagsCompact {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   126
        DEFAULT(""),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   127
        COMPACT("short"),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   128
        NO_COMPACT("-short");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   129
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   130
        String flag;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   131
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   132
        void init(Options opts) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   133
            if (this != DEFAULT) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   134
                String flags = opts.get("diags");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   135
                flags = flags == null ? flag : flags + "," + flag;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   136
                opts.put("diags", flags);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   137
            }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   138
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   139
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   140
        XDiagsCompact(String flag) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   141
            this.flag = flag;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   142
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   143
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   144
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   145
    enum ErrorKind {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   146
        SINGLE("single",
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   147
            "compiler.err.single: Hello!",
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   148
            "KXThis is a test error message Hello!"),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   149
        DOUBLE("double",
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   150
            "compiler.err.double: Hello!",
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   151
            "KXThis is a test error message.\n" +
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   152
            "KXYThis is another line of the above error message Hello!");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   153
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   154
        String key;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   155
        String rawOutput;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   156
        String nonRawOutput;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   157
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   158
        String key() {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   159
            return key;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   160
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   161
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   162
        ErrorKind(String key, String rawOutput, String nonRawOutput) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   163
            this.key = key;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   164
            this.rawOutput = rawOutput;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   165
            this.nonRawOutput = nonRawOutput;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   166
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   167
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   168
        String getOutput(OutputKind outKind, IndentKind summaryIndent, IndentKind detailsIndent) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   169
            return outKind == OutputKind.RAW ?
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   170
                rawOutput :
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   171
                nonRawOutput.replace("X", summaryIndent.string).replace("Y", detailsIndent.string).replace("K", "");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   172
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   173
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   174
        String getOutput(OutputKind outKind, IndentKind summaryIndent, IndentKind detailsIndent, String indent) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   175
            return outKind == OutputKind.RAW ?
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   176
                rawOutput :
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   177
                nonRawOutput.replace("X", summaryIndent.string).replace("Y", detailsIndent.string).replace("K", indent);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   178
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   179
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   180
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   181
    enum MultilineKind {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   182
        NONE(0),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   183
        DOUBLE(1),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   184
        NESTED(2),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   185
        DOUBLE_NESTED(3);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   186
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   187
        static String[][] rawTemplates = {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   188
            {"", ",{(E),(E)}", ",{(E,{(E)})}", ",{(E,{(E)}),(E,{(E)})}"}, //ENABLED
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   189
            {"", "", "", "",""}, //DISABLED
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   190
            {"", ",{(E)}", ",{(E,{(E)})}", ",{(E,{(E)})}"}, //LIMIT_LENGTH
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   191
            {"", ",{(E),(E)}", ",{(E)}", ",{(E),(E)}"}, //LIMIT_DEPTH
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   192
            {"", ",{(E)}", ",{(E)}", ",{(E)}"}}; //LIMIT_BOTH
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   193
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   194
        static String[][] basicTemplates = {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   195
            {"", "\nE\nE", "\nE\nQ", "\nE\nQ\nE\nQ"}, //ENABLED
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   196
            {"", "", "", "",""}, //DISABLED
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   197
            {"", "\nE", "\nE\nQ", "\nE\nQ"}, //LIMIT_LENGTH
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   198
            {"", "\nE\nE", "\nE", "\nE\nE"}, //LIMIT_DEPTH
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   199
            {"", "\nE", "\nE", "\nE"}}; //LIMIT_BOTH
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   200
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   201
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   202
        int index;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   203
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   204
        MultilineKind (int index) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   205
            this.index = index;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   206
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   207
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   208
        boolean isDouble() {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   209
            return this == DOUBLE || this == DOUBLE_NESTED;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   210
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   211
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   212
        boolean isNested() {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   213
            return this == NESTED || this == DOUBLE_NESTED;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   214
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   215
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   216
        String getOutput(OutputKind outKind, ErrorKind errKind, MultilinePolicy policy,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   217
                IndentKind summaryIndent, IndentKind detailsIndent, IndentKind multiIndent) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   218
            String constIndent = (errKind == ErrorKind.DOUBLE) ?
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   219
                summaryIndent.string + detailsIndent.string :
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   220
                summaryIndent.string;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   221
            constIndent += multiIndent.string;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   222
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   223
            String errMsg1 = errKind.getOutput(outKind, summaryIndent, detailsIndent, constIndent);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   224
            String errMsg2 = errKind.getOutput(outKind, summaryIndent, detailsIndent, constIndent + constIndent);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   225
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   226
            errMsg1 = errMsg1.replaceAll("compiler.err", "compiler.misc");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   227
            errMsg1 = errMsg1.replaceAll("error message", "subdiagnostic");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   228
            errMsg2 = errMsg2.replaceAll("compiler.err", "compiler.misc");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   229
            errMsg2 = errMsg2.replaceAll("error message", "subdiagnostic");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   230
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   231
            String template = outKind == OutputKind.RAW ?
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   232
                rawTemplates[policy.index][index] :
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   233
                basicTemplates[policy.index][index];
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   234
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   235
            template = template.replaceAll("E", errMsg1);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   236
            return template.replaceAll("Q", errMsg2);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   237
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   238
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   239
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   240
    enum MultilinePolicy {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   241
        ENABLED(0, "multilinePolicy", "enabled"),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   242
        DISABLED(1, "multilinePolicy", "disabled"),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   243
        LIMIT_LENGTH(2, "multilinePolicy", "limit:1:*"),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   244
        LIMIT_DEPTH(3, "multilinePolicy", "limit:*:1"),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   245
        LIMIT_BOTH(4, "multilinePolicy", "limit:1:1");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   246
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   247
        String name;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   248
        String value;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   249
        int index;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   250
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   251
        MultilinePolicy(int index, String name, String value) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   252
            this.name = name;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   253
            this.value = value;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   254
            this.index = index;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   255
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   256
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   257
        void init(Options options) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   258
            options.put(name, value);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   259
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   260
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   261
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   262
    enum PositionKind {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   263
        NOPOS(Position.NOPOS, "- ", "error: "),
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 2085
diff changeset
   264
        POS(5, "Test.java:1:6: ", "/Test.java:1: ");
2085
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   265
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   266
        int pos;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   267
        String rawOutput;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   268
        String nonRawOutput;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   269
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   270
        PositionKind(int pos, String rawOutput, String nonRawOutput) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   271
            this.pos = pos;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   272
            this.rawOutput = rawOutput;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   273
            this.nonRawOutput = nonRawOutput;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   274
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   275
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   276
        JCDiagnostic.DiagnosticPosition pos() {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   277
            return new JCDiagnostic.SimpleDiagnosticPosition(pos);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   278
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   279
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   280
        String getOutput(OutputKind outputKind) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   281
            return outputKind == OutputKind.RAW ?
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   282
                rawOutput :
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   283
                nonRawOutput;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   284
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   285
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   286
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   287
    static class MyFileObject extends SimpleJavaFileObject {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   288
        private String text;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   289
        public MyFileObject(String text) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   290
            super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   291
            this.text = text;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   292
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   293
        @Override
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   294
        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   295
            return text;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   296
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   297
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   298
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   299
    enum IndentKind {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   300
        NONE(""),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   301
        CUSTOM("   ");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   302
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   303
        String string;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   304
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   305
        IndentKind(String indent) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   306
            string = indent;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   307
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   308
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   309
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   310
    class MyLog extends Log {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   311
        MyLog(Context ctx) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   312
            super(ctx);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   313
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   314
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   315
        @Override
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   316
        protected java.io.PrintWriter getWriterForDiagnosticType(JCDiagnostic.DiagnosticType dt) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   317
            return new java.io.PrintWriter(System.out);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   318
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   319
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   320
        @Override
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   321
        protected boolean shouldReport(JavaFileObject jfo, int pos) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   322
            return true;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   323
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   324
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   325
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   326
    int nerrors = 0;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   327
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   328
    void exec(OutputKind outputKind, ErrorKind errorKind, MultilineKind multiKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   329
            MultilinePolicy multiPolicy, PositionKind posKind, XDiagsSource xdiagsSource,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   330
            XDiagsCompact xdiagsCompact, CaretKind caretKind, SourceLineKind sourceLineKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   331
            IndentKind summaryIndent, IndentKind detailsIndent, IndentKind sourceIndent,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   332
            IndentKind subdiagsIndent) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   333
        Context ctx = new Context();
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   334
        Options options = Options.instance(ctx);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   335
        outputKind.init(options);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   336
        multiPolicy.init(options);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   337
        xdiagsSource.init(options);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   338
        xdiagsCompact.init(options);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   339
        caretKind.init(options);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   340
        sourceLineKind.init(options);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   341
        String indentString = "";
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   342
        indentString = (summaryIndent == IndentKind.CUSTOM) ? "3" : "0";
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   343
        indentString += (detailsIndent == IndentKind.CUSTOM) ? "|3" : "|0";
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   344
        indentString += (sourceIndent == IndentKind.CUSTOM) ? "|3" : "|0";
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   345
        indentString += (subdiagsIndent == IndentKind.CUSTOM) ? "|3" : "|0";
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   346
        options.put("diagsIndentation", indentString);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   347
        MyLog log = new MyLog(ctx);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   348
        JavacMessages messages = JavacMessages.instance(ctx);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   349
        messages.add("tester");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   350
        JCDiagnostic.Factory diags = JCDiagnostic.Factory.instance(ctx);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   351
        log.useSource(new MyFileObject("This is a source line"));
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   352
        JCDiagnostic d = diags.error(log.currentSource(),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   353
            posKind.pos(),
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   354
            errorKind.key(), "Hello!");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   355
        if (multiKind != MultilineKind.NONE) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   356
            JCDiagnostic sub = diags.fragment(errorKind.key(), "Hello!");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   357
            if (multiKind.isNested())
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   358
                sub = new JCDiagnostic.MultilineDiagnostic(sub, List.of(sub));
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   359
            List<JCDiagnostic> subdiags = multiKind.isDouble() ?
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   360
                List.of(sub, sub) :
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   361
                List.of(sub);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   362
            d = new JCDiagnostic.MultilineDiagnostic(d, subdiags);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   363
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   364
        String diag = log.getDiagnosticFormatter().format(d, messages.getCurrentLocale());
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   365
        checkOutput(diag,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   366
                outputKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   367
                errorKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   368
                multiKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   369
                multiPolicy,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   370
                posKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   371
                xdiagsSource,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   372
                xdiagsCompact,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   373
                caretKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   374
                sourceLineKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   375
                summaryIndent,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   376
                detailsIndent,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   377
                sourceIndent,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   378
                subdiagsIndent);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   379
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   380
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   381
    void test() {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   382
        for (OutputKind outputKind : OutputKind.values()) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   383
            for (ErrorKind errKind : ErrorKind.values()) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   384
                for (MultilineKind multiKind : MultilineKind.values()) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   385
                    for (MultilinePolicy multiPolicy : MultilinePolicy.values()) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   386
                        for (PositionKind posKind : PositionKind.values()) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   387
                            for (XDiagsSource xdiagsSource : XDiagsSource.values()) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   388
                                for (XDiagsCompact xdiagsCompact : XDiagsCompact.values()) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   389
                                    for (CaretKind caretKind : CaretKind.values()) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   390
                                        for (SourceLineKind sourceLineKind : SourceLineKind.values()) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   391
                                            for (IndentKind summaryIndent : IndentKind.values()) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   392
                                                for (IndentKind detailsIndent : IndentKind.values()) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   393
                                                    for (IndentKind sourceIndent : IndentKind.values()) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   394
                                                        for (IndentKind subdiagsIndent : IndentKind.values()) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   395
                                                            exec(outputKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   396
                                                                errKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   397
                                                                multiKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   398
                                                                multiPolicy,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   399
                                                                posKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   400
                                                                xdiagsSource,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   401
                                                                xdiagsCompact,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   402
                                                                caretKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   403
                                                                sourceLineKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   404
                                                                summaryIndent,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   405
                                                                detailsIndent,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   406
                                                                sourceIndent,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   407
                                                                subdiagsIndent);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   408
                                                        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   409
                                                    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   410
                                                }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   411
                                            }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   412
                                        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   413
                                    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   414
                                }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   415
                            }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   416
                        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   417
                    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   418
                }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   419
            }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   420
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   421
        if (nerrors != 0)
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   422
            throw new AssertionError(nerrors + " errors found");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   423
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   424
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   425
    void printInfo(String msg, OutputKind outputKind, ErrorKind errorKind, MultilineKind multiKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   426
            MultilinePolicy multiPolicy, PositionKind posKind, XDiagsSource xdiagsSource,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   427
            XDiagsCompact xdiagsCompact, CaretKind caretKind, SourceLineKind sourceLineKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   428
            IndentKind summaryIndent, IndentKind detailsIndent, IndentKind sourceIndent,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   429
            IndentKind subdiagsIndent, String errorLine) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   430
        String sep = "*********************************************************";
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   431
        String desc = "raw=" + outputKind + " pos=" + posKind + " key=" + errorKind.key() +
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   432
                " multiline=" + multiKind +" multiPolicy=" + multiPolicy.value +
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   433
                " diags= " + java.util.Arrays.asList(xdiagsSource.flag, xdiagsCompact.flag) +
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   434
                " caret=" + caretKind + " sourcePosition=" + sourceLineKind +
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   435
                " summaryIndent=" + summaryIndent + " detailsIndent=" + detailsIndent +
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   436
                " sourceIndent=" + sourceIndent + " subdiagsIndent=" + subdiagsIndent;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   437
        System.out.println(sep);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   438
        System.out.println(desc);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   439
        System.out.println(sep);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   440
        System.out.println(msg);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   441
        System.out.println("Diagnostic formatting problem - expected diagnostic...\n" + errorLine);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   442
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   443
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   444
    void checkOutput(String msg, OutputKind outputKind, ErrorKind errorKind, MultilineKind multiKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   445
            MultilinePolicy multiPolicy, PositionKind posKind, XDiagsSource xdiagsSource,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   446
            XDiagsCompact xdiagsCompact, CaretKind caretKind, SourceLineKind sourceLineKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   447
            IndentKind summaryIndent, IndentKind detailsIndent, IndentKind sourceIndent,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   448
            IndentKind subdiagsIndent) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   449
        boolean shouldPrintSource = posKind == PositionKind.POS &&
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   450
                xdiagsSource != XDiagsSource.NO_SOURCE &&
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   451
                (xdiagsSource == XDiagsSource.SOURCE ||
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   452
                outputKind == OutputKind.BASIC);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   453
        String errorLine = posKind.getOutput(outputKind) +
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   454
                errorKind.getOutput(outputKind, summaryIndent, detailsIndent);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   455
        if (xdiagsCompact != XDiagsCompact.COMPACT)
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   456
            errorLine += multiKind.getOutput(outputKind, errorKind, multiPolicy, summaryIndent, detailsIndent, subdiagsIndent);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   457
        String[] lines = errorLine.split("\n");
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   458
        if (xdiagsCompact == XDiagsCompact.COMPACT) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   459
            errorLine = lines[0];
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   460
            lines = new String[] {errorLine};
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   461
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   462
        if (shouldPrintSource) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   463
            if (sourceLineKind.isAfterSummary()) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   464
                String sep = "\n";
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   465
                if (lines.length == 1) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   466
                    errorLine += "\n";
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   467
                    sep = "";
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   468
                }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   469
                errorLine = errorLine.replaceFirst("\n",
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   470
                        Matcher.quoteReplacement(xdiagsSource.getOutput(caretKind, sourceIndent, outputKind) + sep));
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   471
            }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   472
            else
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   473
                errorLine += xdiagsSource.getOutput(caretKind, sourceIndent, outputKind);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   474
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   475
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   476
        if (!msg.equals(errorLine)) {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   477
            printInfo(msg,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   478
                    outputKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   479
                    errorKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   480
                    multiKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   481
                    multiPolicy,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   482
                    posKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   483
                    xdiagsSource,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   484
                    xdiagsCompact,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   485
                    caretKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   486
                    sourceLineKind,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   487
                    summaryIndent,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   488
                    detailsIndent,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   489
                    sourceIndent,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   490
                    subdiagsIndent,
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   491
                    errorLine);
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   492
            nerrors++;
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   493
        }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   494
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   495
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   496
    public static void main(String... args) throws Exception {
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   497
        new T6769027().test();
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   498
    }
4792e12a8ca2 6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
diff changeset
   499
}