e8b90446a91ebf5b2cc5083147d4d550fc4f4f3b
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / internal / ctf / core / event / metadata / tsdl / enumeration / EnumBodyParser.java
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 *******************************************************************************/
9
10 package org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.enumeration;
11
12 import java.util.List;
13
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;
19
20 /**
21 * Body parser for an enumeration, this parses the list of elements in an enum
22 *
23 * @author Matthew Khouzam
24 *
25 */
26 public class EnumBodyParser implements ICommonTreeParser {
27
28 /**
29 * Enum declaration parameter object
30 *
31 * @author Matthew Khouzam
32 *
33 */
34 @NonNullByDefault
35 public static final class Param implements ICommonTreeParserParameter {
36
37 private final EnumDeclaration fEnumDeclaration;
38
39 /**
40 * Constructor
41 *
42 * @param enumDeclaration
43 * the enumeration
44 */
45 public Param(EnumDeclaration enumDeclaration) {
46 fEnumDeclaration = enumDeclaration;
47 }
48
49 }
50
51 /**
52 * The instance
53 */
54 public static final EnumBodyParser INSTANCE = new EnumBodyParser();
55
56 private EnumBodyParser() {
57 }
58
59 @Override
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$
63 }
64 Param parameter = (Param) param;
65 EnumDeclaration enumDeclaration = parameter.fEnumDeclaration;
66 List<CommonTree> enumerators = tree.getChildren();
67 /*
68 * Start at -1, so that if the first enumrator has no explicit value, it
69 * will choose 0
70 */
71 for (CommonTree enumerator : enumerators) {
72 EnumeratorParser.INSTANCE.parse(enumerator, new EnumeratorParser.Param(enumDeclaration));
73 }
74 return enumDeclaration;
75 }
76
77 }
This page took 0.033015 seconds and 4 git commands to generate.