1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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 *******************************************************************************/
9 package org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.stream
;
11 import static org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.TsdlUtils
.isUnaryInteger
;
13 import org
.antlr
.runtime
.tree
.CommonTree
;
14 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.ICommonTreeParser
;
15 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.ParseException
;
16 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.UnaryIntegerParser
;
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.
24 * @author Matthew Khouzam
25 * @author Efficios - Javadoc
28 public class StreamIdParser
implements ICommonTreeParser
{
31 public static final StreamIdParser INSTANCE
= new StreamIdParser();
33 private StreamIdParser() {
40 * the AST node with "id = N;"
41 * @return the value of the stream as a {@link Long}
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$
50 long intval
= UnaryIntegerParser
.INSTANCE
.parse(firstChild
, null);
53 throw new ParseException("invalid value for stream id"); //$NON-NLS-1$