Populate parser/ hierarchy
[yangtools.git] / parser / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / antlr / Token12122.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  * Smallest 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, while others are cut
17  * down to unsigned shorts.
18  *
19  * <p>
20  * This class ends up costing 24/40/32/32 bytes instead of 48/64/48/48 bytes, a saving of 33-50%, while being sufficient
21  * in most scenarios.
22  */
23 final class Token12122 extends AbstractSourceToken {
24     private final byte type;
25     private final short line;
26     private final byte charPositionInLine;
27     private final short startIndex;
28     private final short stopIndex;
29
30     Token12122(final Pair<TokenSource, CharStream> source, final int type, final int line, final int charPositionInLine,
31             final int startIndex, final int stopIndex) {
32         super(source);
33         this.type = (byte) type;
34         this.line = (short) line;
35         this.charPositionInLine = (byte) charPositionInLine;
36         this.startIndex = (short) startIndex;
37         this.stopIndex = (short) stopIndex;
38     }
39
40     @Override
41     public int getType() {
42         return type;
43     }
44
45     @Override
46     public int getLine() {
47         return Short.toUnsignedInt(line);
48     }
49
50     @Override
51     public int getCharPositionInLine() {
52         return Byte.toUnsignedInt(charPositionInLine);
53     }
54
55     @Override
56     public int getStartIndex() {
57         return Short.toUnsignedInt(startIndex);
58     }
59
60     @Override
61     public int getStopIndex() {
62         return Short.toUnsignedInt(stopIndex);
63     }
64 }