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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.enumeration
;
12 import java
.util
.List
;
14 import org
.antlr
.runtime
.tree
.CommonTree
;
15 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
16 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.EnumDeclaration
;
17 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.ICommonTreeParser
;
18 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.ParseException
;
21 * Body parser for an enumeration, this parses the list of elements in an enum
23 * @author Matthew Khouzam
26 public class EnumBodyParser
implements ICommonTreeParser
{
29 * Enum declaration parameter object
31 * @author Matthew Khouzam
35 public static final class Param
implements ICommonTreeParserParameter
{
37 private final EnumDeclaration fEnumDeclaration
;
42 * @param enumDeclaration
45 public Param(EnumDeclaration enumDeclaration
) {
46 fEnumDeclaration
= enumDeclaration
;
54 public static final EnumBodyParser INSTANCE
= new EnumBodyParser();
56 private EnumBodyParser() {
60 public EnumDeclaration
parse(CommonTree tree
, ICommonTreeParserParameter param
) throws ParseException
{
61 if (!(param
instanceof Param
)) {
62 throw new IllegalArgumentException("Param must be a " + Param
.class.getCanonicalName()); //$NON-NLS-1$
64 Param parameter
= (Param
) param
;
65 EnumDeclaration enumDeclaration
= parameter
.fEnumDeclaration
;
66 List
<CommonTree
> enumerators
= tree
.getChildren();
68 * Start at -1, so that if the first enumrator has no explicit value, it
71 for (CommonTree enumerator
: enumerators
) {
72 EnumeratorParser
.INSTANCE
.parse(enumerator
, new EnumeratorParser
.Param(enumDeclaration
));
74 return enumDeclaration
;