Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Token |
|
| 1.7142857142857142;1.714 | ||||
Token$ID |
|
| 1.7142857142857142;1.714 |
1 | /** | |
2 | * Copyright (c) 2008-2011, http://www.snakeyaml.org | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | package org.yaml.snakeyaml.tokens; | |
18 | ||
19 | import org.yaml.snakeyaml.error.Mark; | |
20 | import org.yaml.snakeyaml.error.YAMLException; | |
21 | ||
22 | public abstract class Token { | |
23 | 21 | public enum ID { |
24 | 1 | Alias, Anchor, BlockEnd, BlockEntry, BlockMappingStart, BlockSequenceStart, Directive, DocumentEnd, DocumentStart, FlowEntry, FlowMappingEnd, FlowMappingStart, FlowSequenceEnd, FlowSequenceStart, Key, Scalar, StreamEnd, StreamStart, Tag, Value |
25 | } | |
26 | ||
27 | private final Mark startMark; | |
28 | private final Mark endMark; | |
29 | ||
30 | 849907 | public Token(Mark startMark, Mark endMark) { |
31 | 849907 | if (startMark == null || endMark == null) { |
32 | 2 | throw new YAMLException("Token requires marks."); |
33 | } | |
34 | 849905 | this.startMark = startMark; |
35 | 849905 | this.endMark = endMark; |
36 | 849905 | } |
37 | ||
38 | public String toString() { | |
39 | 16 | return "<" + this.getClass().getName() + "(" + getArguments() + ")>"; |
40 | } | |
41 | ||
42 | public Mark getStartMark() { | |
43 | 503827 | return startMark; |
44 | } | |
45 | ||
46 | public Mark getEndMark() { | |
47 | 437346 | return endMark; |
48 | } | |
49 | ||
50 | /** | |
51 | * @see __repr__ for Token in PyYAML | |
52 | */ | |
53 | protected String getArguments() { | |
54 | 13 | return ""; |
55 | } | |
56 | ||
57 | /** | |
58 | * For error reporting. | |
59 | * | |
60 | * @see class variable 'id' in PyYAML | |
61 | */ | |
62 | public abstract Token.ID getTokenId(); | |
63 | ||
64 | /* | |
65 | * for tests only | |
66 | */ | |
67 | @Override | |
68 | public boolean equals(Object obj) { | |
69 | 9 | if (obj instanceof Token) { |
70 | 8 | return toString().equals(obj.toString()); |
71 | } else { | |
72 | 1 | return false; |
73 | } | |
74 | } | |
75 | } |