langtools/test/tools/javac/diags/MessageFile.java
author mcimadamore
Sat, 06 Oct 2012 10:35:38 +0100
changeset 14062 b7439971a094
parent 8226 8c2fd7e7bcf3
child 16569 48416084b910
permissions -rw-r--r--
7177386: Add attribution support for method references Summary: Add type-checking/lookup routines for method references Reviewed-by: jjg, dlsmith
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     1
/*
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     2
 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     4
 *
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     8
 *
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    13
 * accompanied this code).
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    14
 *
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    18
 *
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    21
 * questions.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    22
 */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    23
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    24
import java.io.*;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    25
import java.util.*;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    26
import java.util.regex.Matcher;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    27
import java.util.regex.Pattern;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    28
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    29
/**
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    30
 * Class to facilitate manipulating compiler.properties.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    31
 */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    32
class MessageFile {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    33
    static final Pattern emptyOrCommentPattern = Pattern.compile("( *#.*)?");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    34
    static final Pattern infoPattern = Pattern.compile("# ([0-9]+: [-A-Za-z ]+, )*[0-9]+: [-A-Za-z ]+");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    35
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    36
    /**
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    37
     * A line of text within the message file.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    38
     * The lines form a doubly linked list for simple navigation.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    39
     */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    40
    class Line {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    41
        String text;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    42
        Line prev;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    43
        Line next;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    44
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    45
        Line(String text) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    46
            this.text = text;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    47
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    48
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    49
        boolean isEmptyOrComment() {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    50
            return emptyOrCommentPattern.matcher(text).matches();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    51
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    52
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    53
        boolean isInfo() {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    54
            return infoPattern.matcher(text).matches();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    55
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    56
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    57
        boolean hasContinuation() {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    58
            return (next != null) && text.endsWith("\\");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    59
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    60
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    61
        Line insertAfter(String text) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    62
            Line l = new Line(text);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    63
            insertAfter(l);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    64
            return l;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    65
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    66
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    67
        void insertAfter(Line l) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    68
            assert prev == null && next == null;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    69
            l.prev = this;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    70
            l.next = next;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    71
            if (next == null)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    72
                lastLine = l;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    73
            else
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    74
                next.prev = l;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    75
            next = l;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    76
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    77
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    78
        Line insertBefore(String text) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    79
            Line l = new Line(text);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    80
            insertBefore(l);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    81
            return l;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    82
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    83
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    84
        void insertBefore(Line l) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    85
            assert prev == null && next == null;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    86
            l.prev = prev;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    87
            l.next = this;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    88
            if (prev == null)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    89
                firstLine = l;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    90
            else
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    91
                prev.next = l;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    92
            prev = l;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    93
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    94
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    95
        void remove() {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    96
            if (prev == null)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    97
                firstLine = next;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    98
            else
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
    99
                prev.next = next;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   100
            if (next == null)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   101
                lastLine = prev;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   102
            else
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   103
                next.prev = prev;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   104
            prev = null;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   105
            next = null;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   106
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   107
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   108
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   109
    /**
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   110
     * A message within the message file.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   111
     * A message is a series of lines containing a "name=value" property,
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   112
     * optionally preceded by a comment describing the use of placeholders
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   113
     * such as {0}, {1}, etc within the property value.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   114
     */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   115
    static final class Message {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   116
        final Line firstLine;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   117
        private Info info;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   118
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   119
        Message(Line l) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   120
            firstLine = l;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   121
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   122
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   123
        boolean needInfo() {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   124
            Line l = firstLine;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   125
            while (true) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   126
                if (l.text.matches(".*\\{[0-9]+\\}.*"))
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   127
                    return true;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   128
                if (!l.hasContinuation())
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   129
                    return false;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   130
                l = l.next;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   131
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   132
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   133
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   134
        Set<Integer> getPlaceholders() {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   135
            Pattern p = Pattern.compile("\\{([0-9]+)\\}");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   136
            Set<Integer> results = new TreeSet<Integer>();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   137
            Line l = firstLine;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   138
            while (true) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   139
                Matcher m = p.matcher(l.text);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   140
                while (m.find())
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   141
                    results.add(Integer.parseInt(m.group(1)));
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   142
                if (!l.hasContinuation())
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   143
                    return results;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   144
                l = l.next;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   145
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   146
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   147
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   148
        /**
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   149
         * Get the Info object for this message. It may be empty if there
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   150
         * if no comment preceding the property specification.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   151
         */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   152
        Info getInfo() {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   153
            if (info == null) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   154
                Line l = firstLine.prev;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   155
                if (l != null && l.isInfo())
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   156
                    info = new Info(l.text);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   157
                else
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   158
                    info = new Info();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   159
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   160
            return info;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   161
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   162
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   163
        /**
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   164
         * Set the Info for this message.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   165
         * If there was an info comment preceding the property specification,
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   166
         * it will be updated; otherwise, one will be inserted.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   167
         */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   168
        void setInfo(Info info) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   169
            this.info = info;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   170
            Line l = firstLine.prev;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   171
            if (l != null && l.isInfo())
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   172
                l.text = info.toComment();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   173
            else
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   174
                firstLine.insertBefore(info.toComment());
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   175
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   176
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   177
        /**
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   178
         * Get all the lines pertaining to this message.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   179
         */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   180
        List<Line> getLines(boolean includeAllPrecedingComments) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   181
            List<Line> lines = new ArrayList<Line>();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   182
            Line l = firstLine;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   183
            if (includeAllPrecedingComments) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   184
                // scan back to find end of prev message
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   185
                while (l.prev != null && l.prev.isEmptyOrComment())
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   186
                    l = l.prev;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   187
                // skip leading blank lines
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   188
                while (l.text.isEmpty())
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   189
                    l = l.next;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   190
            } else {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   191
                if (l.prev != null && l.prev.isInfo())
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   192
                    l = l.prev;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   193
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   194
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   195
            // include any preceding lines
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   196
            for ( ; l != firstLine; l = l.next)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   197
                lines.add(l);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   198
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   199
            // include message lines
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   200
            for (l = firstLine; l != null && l.hasContinuation(); l = l.next)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   201
                lines.add(l);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   202
            lines.add(l);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   203
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   204
            // include trailing blank line if present
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   205
            l = l.next;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   206
            if (l != null && l.text.isEmpty())
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   207
                lines.add(l);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   208
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   209
            return lines;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   210
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   211
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   212
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   213
    /**
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   214
     * An object to represent the comment that may precede the property
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   215
     * specification in a Message.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   216
     * The comment is modelled as a list of fields, where the fields correspond
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   217
     * to the placeholder values (e.g. {0}, {1}, etc) within the message value.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   218
     */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   219
    static final class Info {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   220
        /**
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   221
         * An ordered set of descriptions for a placeholder value in a
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   222
         * message.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   223
         */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   224
        static class Field {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   225
            boolean unused;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   226
            Set<String> values;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   227
            boolean listOfAny = false;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   228
            boolean setOfAny = false;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   229
            Field(String s) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   230
                s = s.substring(s.indexOf(": ") + 2);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   231
                values = new LinkedHashSet<String>(Arrays.asList(s.split(" or ")));
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   232
                for (String v: values) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   233
                    if (v.startsWith("list of"))
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   234
                        listOfAny = true;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   235
                    if (v.startsWith("set of"))
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   236
                        setOfAny = true;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   237
                }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   238
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   239
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   240
            /**
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   241
             * Return true if this field logically contains all the values of
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   242
             * another field.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   243
             */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   244
            boolean contains(Field other) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   245
                if (unused != other.unused)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   246
                    return false;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   247
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   248
                for (String v: other.values) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   249
                    if (values.contains(v))
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   250
                        continue;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   251
                    if (v.equals("null") || v.equals("string"))
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   252
                        continue;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   253
                    if (v.equals("list") && listOfAny)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   254
                        continue;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   255
                    if (v.equals("set") && setOfAny)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   256
                        continue;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   257
                    return false;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   258
                }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   259
                return true;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   260
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   261
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   262
            /**
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   263
             * Merge the values of another field into this field.
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   264
             */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   265
            void merge(Field other) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   266
                unused |= other.unused;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   267
                values.addAll(other.values);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   268
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   269
                // cleanup unnecessary entries
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   270
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   271
                if (values.contains("null") && values.size() > 1) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   272
                    // "null" is superceded by anything else
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   273
                    values.remove("null");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   274
                }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   275
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   276
                if (values.contains("string") && values.size() > 1) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   277
                    // "string" is superceded by anything else
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   278
                    values.remove("string");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   279
                }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   280
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   281
                if (values.contains("list")) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   282
                    // list is superceded by "list of ..."
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   283
                    for (String s: values) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   284
                        if (s.startsWith("list of ")) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   285
                            values.remove("list");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   286
                            break;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   287
                        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   288
                    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   289
                }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   290
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   291
                if (values.contains("set")) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   292
                    // set is superceded by "set of ..."
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   293
                    for (String s: values) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   294
                        if (s.startsWith("set of ")) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   295
                            values.remove("set");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   296
                            break;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   297
                        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   298
                    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   299
                }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   300
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   301
                if (other.values.contains("unused")) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   302
                    values.clear();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   303
                    values.add("unused");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   304
                }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   305
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   306
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   307
            void markUnused() {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   308
                values = new LinkedHashSet<String>();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   309
                values.add("unused");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   310
                listOfAny = false;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   311
                setOfAny = false;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   312
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   313
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   314
            @Override
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   315
            public String toString() {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   316
                return values.toString();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   317
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   318
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   319
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   320
        /** The fields of the Info object. */
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   321
        List<Field> fields = new ArrayList<Field>();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   322
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   323
        Info() { }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   324
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   325
        Info(String text) throws IllegalArgumentException {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   326
            if (!text.startsWith("# "))
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   327
                throw new IllegalArgumentException();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   328
            String[] segs = text.substring(2).split(", ");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   329
            fields = new ArrayList<Field>();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   330
            for (String seg: segs) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   331
                fields.add(new Field(seg));
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   332
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   333
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   334
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   335
        Info(Set<String> infos) throws IllegalArgumentException {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   336
            for (String s: infos)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   337
                merge(new Info(s));
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   338
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   339
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   340
        boolean isEmpty() {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   341
            return fields.isEmpty();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   342
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   343
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   344
        boolean contains(Info other) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   345
            if (other.isEmpty())
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   346
                return true;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   347
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   348
            if (fields.size() != other.fields.size())
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   349
                return false;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   350
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   351
            Iterator<Field> oIter = other.fields.iterator();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   352
            for (Field values: fields) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   353
                if (!values.contains(oIter.next()))
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   354
                    return false;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   355
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   356
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   357
            return true;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   358
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   359
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   360
        void merge(Info other) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   361
            if (fields.isEmpty()) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   362
                fields.addAll(other.fields);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   363
                return;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   364
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   365
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   366
            if (other.fields.size() != fields.size())
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   367
                throw new IllegalArgumentException();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   368
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   369
            Iterator<Field> oIter = other.fields.iterator();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   370
            for (Field d: fields) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   371
                d.merge(oIter.next());
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   372
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   373
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   374
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   375
        void markUnused(Set<Integer> used) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   376
            for (int i = 0; i < fields.size(); i++) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   377
                if (!used.contains(i))
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   378
                    fields.get(i).markUnused();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   379
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   380
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   381
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   382
        @Override
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   383
        public String toString() {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   384
            return fields.toString();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   385
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   386
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   387
        String toComment() {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   388
            StringBuilder sb = new StringBuilder();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   389
            sb.append("# ");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   390
            String sep = "";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   391
            int i = 0;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   392
            for (Field f: fields) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   393
                sb.append(sep);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   394
                sb.append(i++);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   395
                sb.append(": ");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   396
                sep = "";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   397
                for (String s: f.values) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   398
                    sb.append(sep);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   399
                    sb.append(s);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   400
                    sep = " or ";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   401
                }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   402
                sep = ", ";
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   403
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   404
            return sb.toString();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   405
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   406
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   407
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   408
    Line firstLine;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   409
    Line lastLine;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   410
    Map<String, Message> messages = new TreeMap<String, Message>();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   411
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   412
    MessageFile(File file) throws IOException {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   413
        Reader in = new FileReader(file);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   414
        try {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   415
            read(in);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   416
        } finally {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   417
            in.close();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   418
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   419
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   420
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   421
    MessageFile(Reader in) throws IOException {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   422
        read(in);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   423
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   424
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   425
    final void read(Reader in) throws IOException {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   426
        BufferedReader br = (in instanceof BufferedReader)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   427
                ? (BufferedReader) in
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   428
                : new BufferedReader(in);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   429
        String line;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   430
        while ((line = br.readLine()) != null) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   431
            Line l;
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   432
            if (firstLine == null)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   433
                l = firstLine = lastLine = new Line(line);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   434
            else
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   435
                l = lastLine.insertAfter(line);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   436
            if (line.startsWith("compiler.")) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   437
                int eq = line.indexOf("=");
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   438
                if (eq > 0)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   439
                    messages.put(line.substring(0, eq), new Message(l));
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   440
            }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   441
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   442
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   443
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   444
    void write(File file) throws IOException {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   445
        Writer out = new FileWriter(file);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   446
        try {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   447
            write(out);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   448
        } finally {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   449
            out.close();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   450
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   451
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   452
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   453
    void write(Writer out) throws IOException {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   454
        BufferedWriter bw = (out instanceof BufferedWriter)
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   455
                ? (BufferedWriter) out
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   456
                : new BufferedWriter(out);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   457
        for (Line l = firstLine; l != null; l = l.next) {
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   458
            bw.write(l.text);
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   459
            bw.write("\n"); // always use Unix line endings
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   460
        }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   461
        bw.flush();
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   462
    }
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
diff changeset
   463
}