author | mcimadamore |
Thu, 08 Jan 2015 14:43:05 +0000 | |
changeset 28334 | 1633de6070ae |
child 34752 | 9c262a013456 |
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 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
23 |
package propertiesparser.parser; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
24 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
25 |
import java.util.regex.Pattern; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
26 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
27 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
28 |
* A line of text within the message file. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
29 |
* The lines form a doubly linked list for simple navigation. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
30 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
31 |
public class MessageLine { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
32 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
33 |
static final Pattern emptyOrCommentPattern = Pattern.compile("( *#.*)?"); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
34 |
static final Pattern typePattern = Pattern.compile("[-\\\\'A-Z\\.a-z ]+( \\([A-Za-z 0-9]+\\))?"); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
35 |
static final Pattern infoPattern = Pattern.compile(String.format("# ([0-9]+: %s, )*[0-9]+: %s", |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
36 |
typePattern.pattern(), typePattern.pattern())); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
37 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
38 |
public String text; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
39 |
MessageLine prev; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
40 |
MessageLine next; |
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 |
MessageLine(String text) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
43 |
this.text = text; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
44 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
45 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
46 |
public boolean isEmptyOrComment() { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
47 |
return emptyOrCommentPattern.matcher(text).matches(); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
48 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
49 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
50 |
public boolean isInfo() { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
51 |
return infoPattern.matcher(text).matches(); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
52 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
53 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
54 |
boolean hasContinuation() { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
55 |
return (next != null) && text.endsWith("\\"); |
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 |
MessageLine append(String text) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
59 |
MessageLine l = new MessageLine(text); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
60 |
append(l); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
61 |
return l; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
62 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
63 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
64 |
void append(MessageLine l) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
65 |
assert l.prev == null && l.next == null; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
66 |
l.prev = this; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
67 |
l.next = next; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
68 |
if (next != null) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
69 |
next.prev = l; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
70 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
71 |
next = l; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
72 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
diff
changeset
|
73 |
} |