ctf: make all parser implementations final classes
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / internal / ctf / core / event / metadata / tsdl / stream / StreamIdParser.java
CommitLineData
b1ea73b5
MK
1/*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9package org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.stream;
10
11import static org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.TsdlUtils.isUnaryInteger;
12
13import org.antlr.runtime.tree.CommonTree;
14import org.eclipse.tracecompass.internal.ctf.core.event.metadata.ICommonTreeParser;
15import org.eclipse.tracecompass.internal.ctf.core.event.metadata.ParseException;
16import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.UnaryIntegerParser;
17
18/**
19 * <strong>Stream ID</strong>, used as reference to stream description in
20 * metadata. This field is optional if there is only one stream description in
21 * the metadata, but becomes required if there are more than one stream in the
22 * TSDL metadata description.
23 *
24 * @author Matthew Khouzam
25 * @author Efficios - Javadoc
26 *
27 */
4055c3a1 28public final class StreamIdParser implements ICommonTreeParser {
b1ea73b5
MK
29
30 /** Instance */
31 public static final StreamIdParser INSTANCE = new StreamIdParser();
32
33 private StreamIdParser() {
34 }
35
36 /**
37 * Parses a stream id
38 *
39 * @param tree
40 * the AST node with "id = N;"
41 * @return the value of the stream as a {@link Long}
42 */
43 @Override
44 public Long parse(CommonTree tree, ICommonTreeParserParameter param) throws ParseException {
45 CommonTree firstChild = (CommonTree) tree.getChild(0);
46 if (isUnaryInteger(firstChild)) {
47 if (tree.getChildCount() > 1) {
48 throw new ParseException("invalid value for stream id"); //$NON-NLS-1$
49 }
50 long intval = UnaryIntegerParser.INSTANCE.parse(firstChild, null);
51 return intval;
52 }
53 throw new ParseException("invalid value for stream id"); //$NON-NLS-1$
54 }
55
56}
This page took 0.031214 seconds and 5 git commands to generate.