Populate parser/ hierarchy
[yangtools.git] / parser / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / antlr / Token12144.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.parser.rfc7950.antlr;
9
10 import org.antlr.v4.runtime.CharStream;
11 import org.antlr.v4.runtime.TokenSource;
12 import org.antlr.v4.runtime.misc.Pair;
13
14 /**
15  * Intermediate general token implementation. This cuts {@code channel}, {@code text} fields completely, as we typically
16  * we do not use them. {@code type} and {@code charPositionInLine} are cut down to a single byte, and {@code line} is
17  * cut down to an unsigned short. {@code startIndex} and {@code stopIndex} are kept at full four-byte range, this making
18  * this implementation useful beyond 64K-char file mark.
19  *
20  * <p>
21  * This class ends up costing 32/48/32/32 bytes instead of 48/64/48/48 bytes, a saving of 33% in the same scenarios as
22  * {@link Token12122} across all possible file sizes.
23  */
24 final class Token12144 extends AbstractSourceToken {
25     private final byte type;
26     private final short line;
27     private final byte charPositionInLine;
28
29     private final int startIndex;
30     private final int stopIndex;
31
32     Token12144(final Pair<TokenSource, CharStream> source, final int type, final int line, final int charPositionInLine,
33             final int startIndex, final int stopIndex) {
34         super(source);
35         this.type = (byte) type;
36         this.line = (short) line;
37         this.charPositionInLine = (byte) charPositionInLine;
38         this.startIndex = startIndex;
39         this.stopIndex = stopIndex;
40     }
41
42     @Override
43     public int getType() {
44         return type;
45     }
46
47     @Override
48     public int getLine() {
49         return Short.toUnsignedInt(line);
50     }
51
52     @Override
53     public int getCharPositionInLine() {
54         return Byte.toUnsignedInt(charPositionInLine);
55     }
56
57     @Override
58     public int getStartIndex() {
59         return startIndex;
60     }
61
62     @Override
63     public int getStopIndex() {
64         return stopIndex;
65     }
66 }