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
;
11 import java
.util
.List
;
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
;
18 * Type declaration String parser
20 * @author Matthew Khouzam
23 public class TypeDeclarationStringParser
implements ICommonTreeParser
{
26 * Parameter Object with a list of common trees
28 * @author Matthew Khouzam
31 public static final class Param
implements ICommonTreeParserParameter
{
32 private final List
<CommonTree
> fList
;
40 public Param(List
<CommonTree
> list
) {
48 public static final TypeDeclarationStringParser INSTANCE
= new TypeDeclarationStringParser();
50 private TypeDeclarationStringParser() {
54 * Creates the string representation of a type specifier.
56 * @param typeSpecifierList
57 * A TYPE_SPECIFIER node.
59 * @return A StringBuilder to which will be appended the string.
60 * @throws ParseException
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$
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
);
76 sb
.append(PointerListStringParser
.INSTANCE
.parse(temp
, null));