1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.types
;
15 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
17 import java
.util
.List
;
19 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
20 import org
.eclipse
.jdt
.annotation
.Nullable
;
21 import org
.eclipse
.tracecompass
.ctf
.core
.event
.scope
.IDefinitionScope
;
22 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.AbstractArrayDefinition
;
23 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.CompoundDeclaration
;
24 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.Definition
;
26 import com
.google
.common
.base
.Joiner
;
27 import com
.google
.common
.collect
.ImmutableList
;
30 * A CTF array definition
32 * Arrays are fixed-length. Their length is declared in the type declaration
33 * within the meta-data. They contain an array of "inner type" elements, which
34 * can refer to any type not containing the type of the array being declared (no
35 * circular dependency). The length is the number of elements in an array.
37 * @author Matthew Khouzam
40 public final class ArrayDefinition
extends AbstractArrayDefinition
{
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 private final List
<Definition
> fDefinitions
;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
56 * the parent declaration
57 * @param definitionScope
62 * the content of the array
64 public ArrayDefinition(CompoundDeclaration declaration
,
65 @Nullable IDefinitionScope definitionScope
,
67 List
<Definition
> definitions
) {
68 super(declaration
, definitionScope
, fieldName
);
69 fDefinitions
= checkNotNull(ImmutableList
.copyOf(definitions
));
72 // ------------------------------------------------------------------------
73 // Getters/Setters/Predicates
74 // ------------------------------------------------------------------------
77 public List
<Definition
> getDefinitions() {
82 * Get the the number of elements in the array
84 * @return how many elements in the array
86 public int getLength() {
87 return fDefinitions
.size();
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
95 public String
toString() {
96 StringBuilder b
= new StringBuilder();
98 Joiner joiner
= Joiner
.on(", ").skipNulls(); //$NON-NLS-1$
99 b
.append(joiner
.join(fDefinitions
));
101 return checkNotNull(b
.toString());