author | vasya |
Mon, 14 Dec 2015 20:18:19 +0100 | |
changeset 34752 | 9c262a013456 |
parent 28334 | 1633de6070ae |
permissions | -rw-r--r-- |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
1 |
/* |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
4 |
* |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
8 |
* |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
13 |
* accompanied this code). |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
14 |
* |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
18 |
* |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
21 |
* questions. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
22 |
*/ |
34752
9c262a013456
8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents:
28334
diff
changeset
|
23 |
|
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
24 |
package propertiesparser.parser; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
25 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
26 |
import java.util.ArrayList; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
27 |
import java.util.List; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
28 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
29 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
30 |
* A message within the message file. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
31 |
* A message is a series of lines containing a "name=value" property, |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
32 |
* optionally preceded by a comment describing the use of placeholders |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
33 |
* such as {0}, {1}, etc within the property value. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
34 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
35 |
public final class Message { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
36 |
final MessageLine firstLine; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
37 |
private MessageInfo messageInfo; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
38 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
39 |
Message(MessageLine l) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
40 |
firstLine = l; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
41 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
42 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
43 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
44 |
* Get the Info object for this message. It may be empty if there |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
45 |
* if no comment preceding the property specification. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
46 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
47 |
public MessageInfo getMessageInfo() { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
48 |
if (messageInfo == null) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
49 |
MessageLine l = firstLine.prev; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
50 |
if (l != null && l.isInfo()) |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
51 |
messageInfo = new MessageInfo(l.text); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
52 |
else |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
53 |
messageInfo = MessageInfo.dummyInfo; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
54 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
55 |
return messageInfo; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
56 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
57 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
58 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
59 |
* Get all the lines pertaining to this message. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
60 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
61 |
public List<MessageLine> getLines(boolean includeAllPrecedingComments) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
62 |
List<MessageLine> lines = new ArrayList<>(); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
63 |
MessageLine l = firstLine; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
64 |
if (includeAllPrecedingComments) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
65 |
// scan back to find end of prev message |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
66 |
while (l.prev != null && l.prev.isEmptyOrComment()) |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
67 |
l = l.prev; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
68 |
// skip leading blank lines |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
69 |
while (l.text.isEmpty()) |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
70 |
l = l.next; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
71 |
} else { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
72 |
if (l.prev != null && l.prev.isInfo()) |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
73 |
l = l.prev; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
74 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
75 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
76 |
// include any preceding lines |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
77 |
for ( ; l != firstLine; l = l.next) |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
78 |
lines.add(l); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
79 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
80 |
// include message lines |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
81 |
for (l = firstLine; l != null && l.hasContinuation(); l = l.next) |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
82 |
lines.add(l); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
83 |
lines.add(l); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
84 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
85 |
// include trailing blank line if present |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
86 |
l = l.next; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
87 |
if (l != null && l.text.isEmpty()) |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
88 |
lines.add(l); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
89 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
90 |
return lines; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
91 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
92 |
} |