Commit | Line | Data |
---|---|---|
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 | *******************************************************************************/ | |
9 | package org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl; | |
10 | ||
11 | import java.util.List; | |
12 | ||
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 | ||
17 | /** | |
18 | * Type specifier list string parser, parses a list of names | |
19 | * | |
20 | * @author Matthew Khouzam | |
21 | * | |
22 | */ | |
4055c3a1 | 23 | public final class TypeSpecifierListStringParser implements ICommonTreeParser { |
b1ea73b5 MK |
24 | |
25 | /** | |
26 | * Instance | |
27 | */ | |
28 | public static final TypeSpecifierListStringParser INSTANCE = new TypeSpecifierListStringParser(); | |
29 | ||
30 | private TypeSpecifierListStringParser() { | |
31 | } | |
32 | ||
33 | /** | |
34 | * Creates the string representation of a type specifier. | |
35 | * | |
36 | * @param typeSpecifierList | |
37 | * A TYPE_SPECIFIER node. | |
38 | * @param param | |
39 | * unused | |
40 | * | |
41 | * @return A StringBuilder to which will be appended the string. | |
42 | * @throws ParseException | |
43 | * invalid node | |
44 | */ | |
45 | @Override | |
46 | public StringBuilder parse(CommonTree typeSpecifierList, ICommonTreeParserParameter param) throws ParseException { | |
47 | StringBuilder sb = new StringBuilder(); | |
48 | List<CommonTree> children = typeSpecifierList.getChildren(); | |
49 | ||
50 | boolean firstItem = true; | |
51 | ||
52 | for (CommonTree child : children) { | |
53 | if (!firstItem) { | |
54 | sb.append(' '); | |
55 | ||
56 | } | |
57 | ||
58 | firstItem = false; | |
59 | ||
60 | /* Append the string that represents this type specifier. */ | |
61 | sb.append(TypeSpecifierListNameParser.INSTANCE.parse(child, null)); | |
62 | } | |
63 | return sb; | |
64 | } | |
65 | ||
66 | } |