2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.rfc7950.antlr;
10 import org.antlr.v4.runtime.CharStream;
11 import org.antlr.v4.runtime.TokenSource;
12 import org.antlr.v4.runtime.misc.Pair;
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.
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
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;
30 Token12122(final Pair<TokenSource, CharStream> source, final int type, final int line, final int charPositionInLine,
31 final int startIndex, final int stopIndex) {
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;
41 public int getType() {
46 public int getLine() {
47 return Short.toUnsignedInt(line);
51 public int getCharPositionInLine() {
52 return Byte.toUnsignedInt(charPositionInLine);
56 public int getStartIndex() {
57 return Short.toUnsignedInt(startIndex);
61 public int getStopIndex() {
62 return Short.toUnsignedInt(stopIndex);