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 declaration String parser | |
19 | * | |
20 | * @author Matthew Khouzam | |
21 | * | |
22 | */ | |
4055c3a1 | 23 | public final class TypeDeclarationStringParser implements ICommonTreeParser { |
b1ea73b5 MK |
24 | |
25 | /** | |
26 | * Parameter Object with a list of common trees | |
27 | * | |
28 | * @author Matthew Khouzam | |
29 | * | |
30 | */ | |
31 | public static final class Param implements ICommonTreeParserParameter { | |
32 | private final List<CommonTree> fList; | |
33 | ||
34 | /** | |
35 | * Constructor | |
36 | * | |
37 | * @param list | |
38 | * List of trees | |
39 | */ | |
40 | public Param(List<CommonTree> list) { | |
41 | fList = list; | |
42 | } | |
43 | } | |
44 | ||
45 | /** | |
46 | * Instance | |
47 | */ | |
48 | public static final TypeDeclarationStringParser INSTANCE = new TypeDeclarationStringParser(); | |
49 | ||
50 | private TypeDeclarationStringParser() { | |
51 | } | |
52 | ||
53 | /** | |
54 | * Creates the string representation of a type specifier. | |
55 | * | |
56 | * @param typeSpecifierList | |
57 | * A TYPE_SPECIFIER node. | |
58 | * | |
59 | * @return A StringBuilder to which will be appended the string. | |
60 | * @throws ParseException | |
61 | * invalid node | |
62 | */ | |
63 | @Override | |
64 | public String parse(CommonTree typeSpecifierList, ICommonTreeParserParameter param) throws ParseException { | |
65 | if (!(param instanceof Param)) { | |
66 | throw new IllegalArgumentException("Param must be a " + Param.class.getCanonicalName()); //$NON-NLS-1$ | |
67 | } | |
68 | List<CommonTree> pointers = ((Param) param).fList; | |
69 | StringBuilder sb = new StringBuilder(); | |
70 | sb.append(TypeSpecifierListStringParser.INSTANCE.parse(typeSpecifierList, null)); | |
71 | if (pointers != null) { | |
72 | CommonTree temp = new CommonTree(); | |
73 | for (CommonTree pointer : pointers) { | |
74 | temp.addChild(pointer); | |
75 | } | |
76 | sb.append(PointerListStringParser.INSTANCE.parse(temp, null)); | |
77 | } | |
78 | return sb.toString(); | |
79 | } | |
80 | ||
81 | } |