1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others
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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.ctf
.core
.event
.types
;
15 import java
.util
.List
;
17 import org
.eclipse
.jdt
.annotation
.NonNull
;
18 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
19 import org
.eclipse
.jdt
.annotation
.Nullable
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.scope
.IDefinitionScope
;
22 import com
.google
.common
.base
.Joiner
;
23 import com
.google
.common
.collect
.ImmutableList
;
26 * A CTF array definition
28 * Arrays are fixed-length. Their length is declared in the type declaration
29 * within the meta-data. They contain an array of "inner type" elements, which
30 * can refer to any type not containing the type of the array being declared (no
31 * circular dependency). The length is the number of elements in an array.
34 * @author Matthew Khouzam
35 * @author Simon Marchi
38 public final class ArrayDefinition
extends Definition
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
44 private final ImmutableList
<Definition
> fDefinitions
;
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
54 * the parent declaration
55 * @param definitionScope
60 * the content of the array
63 public ArrayDefinition(ArrayDeclaration declaration
,
64 @Nullable IDefinitionScope definitionScope
,
66 List
<Definition
> definitions
) {
67 super(declaration
, definitionScope
, fieldName
);
68 @SuppressWarnings("null")
69 @NonNull ImmutableList
<Definition
> list
= ImmutableList
.copyOf(definitions
);
74 // ------------------------------------------------------------------------
75 // Getters/Setters/Predicates
76 // ------------------------------------------------------------------------
79 * @return the definitions
82 public List
<Definition
> getDefinitions() {
87 * Get the element at i
89 * @param i the index (cannot be negative)
90 * @return The element at I, if I > length, null, if I < 0, the method throws an out of bounds exception
93 public Definition
getElem(int i
) {
94 if (i
> fDefinitions
.size()) {
98 return fDefinitions
.get(i
);
102 public ArrayDeclaration
getDeclaration() {
103 return (ArrayDeclaration
) super.getDeclaration();
106 // ------------------------------------------------------------------------
108 // ------------------------------------------------------------------------
111 public String
toString() {
112 StringBuilder b
= new StringBuilder();
114 if (getDeclaration().isString()) {
115 for (Definition def
: fDefinitions
) {
116 IntegerDefinition character
= (IntegerDefinition
) def
;
118 if (character
.getValue() == 0) {
122 b
.append(character
.toString());
126 Joiner joiner
= Joiner
.on(", ").skipNulls(); //$NON-NLS-1$
127 b
.append(joiner
.join(fDefinitions
));
131 @SuppressWarnings("null")
132 @NonNull String ret
= b
.toString();