| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Token |
|
| 1.625;1.625 | ||||
| Token$ID |
|
| 1.625;1.625 |
| 1 | /** | |
| 2 | * Copyright (c) 2008-2012, 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 | package org.yaml.snakeyaml.tokens; | |
| 17 | ||
| 18 | import org.yaml.snakeyaml.error.Mark; | |
| 19 | import org.yaml.snakeyaml.error.YAMLException; | |
| 20 | ||
| 21 | public abstract class Token { | |
| 22 | 21 | public enum ID { |
| 23 | 1 | Alias, Anchor, BlockEnd, BlockEntry, BlockMappingStart, BlockSequenceStart, Directive, DocumentEnd, DocumentStart, FlowEntry, FlowMappingEnd, FlowMappingStart, FlowSequenceEnd, FlowSequenceStart, Key, Scalar, StreamEnd, StreamStart, Tag, Value |
| 24 | } | |
| 25 | ||
| 26 | private final Mark startMark; | |
| 27 | private final Mark endMark; | |
| 28 | ||
| 29 | 1240560 | public Token(Mark startMark, Mark endMark) { |
| 30 | 1240560 | if (startMark == null || endMark == null) { |
| 31 | 2 | throw new YAMLException("Token requires marks."); |
| 32 | } | |
| 33 | 1240558 | this.startMark = startMark; |
| 34 | 1240558 | this.endMark = endMark; |
| 35 | 1240558 | } |
| 36 | ||
| 37 | public String toString() { | |
| 38 | 16 | return "<" + this.getClass().getName() + "(" + getArguments() + ")>"; |
| 39 | } | |
| 40 | ||
| 41 | public Mark getStartMark() { | |
| 42 | 1149047 | return startMark; |
| 43 | } | |
| 44 | ||
| 45 | public Mark getEndMark() { | |
| 46 | 824536 | return endMark; |
| 47 | } | |
| 48 | ||
| 49 | /** | |
| 50 | * @see "__repr__ for Token in PyYAML" | |
| 51 | */ | |
| 52 | protected String getArguments() { | |
| 53 | 13 | return ""; |
| 54 | } | |
| 55 | ||
| 56 | /** | |
| 57 | * For error reporting. | |
| 58 | * | |
| 59 | * @see "class variable 'id' in PyYAML" | |
| 60 | */ | |
| 61 | public abstract Token.ID getTokenId(); | |
| 62 | ||
| 63 | /* | |
| 64 | * for tests only | |
| 65 | */ | |
| 66 | @Override | |
| 67 | public boolean equals(Object obj) { | |
| 68 | 9 | if (obj instanceof Token) { |
| 69 | 8 | return toString().equals(obj.toString()); |
| 70 | } else { | |
| 71 | 1 | return false; |
| 72 | } | |
| 73 | } | |
| 74 | ||
| 75 | /* | |
| 76 | * for tests only | |
| 77 | */ | |
| 78 | @Override | |
| 79 | public int hashCode() { | |
| 80 | 0 | return toString().hashCode(); |
| 81 | } | |
| 82 | } |