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.
33 * @deprecated use {@link AbstractArrayDefinition}
35 * @author Matthew Khouzam
36 * @author Simon Marchi
40 public final class ArrayDefinition
extends AbstractArrayDefinition
{
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 private final ImmutableList
<Definition
> fDefinitions
;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
56 * the parent declaration
57 * @param definitionScope
62 * the content of the array
65 public ArrayDefinition(ArrayDeclaration declaration
,
66 @Nullable IDefinitionScope definitionScope
,
68 List
<Definition
> definitions
) {
69 super(declaration
, definitionScope
, fieldName
);
70 @SuppressWarnings("null")
71 @NonNull ImmutableList
<Definition
> list
= ImmutableList
.copyOf(definitions
);
76 // ------------------------------------------------------------------------
77 // Getters/Setters/Predicates
78 // ------------------------------------------------------------------------
81 public List
<Definition
> getDefinitions() {
86 * Get the element at i
88 * @param i the index (cannot be negative)
89 * @return The element at I, if I > length, null, if I < 0, the method throws an out of bounds exception
92 public Definition
getElem(int i
) {
93 if (i
> fDefinitions
.size()) {
97 return fDefinitions
.get(i
);
101 public ArrayDeclaration
getDeclaration() {
102 return (ArrayDeclaration
) super.getDeclaration();
105 // ------------------------------------------------------------------------
107 // ------------------------------------------------------------------------
110 public String
toString() {
111 StringBuilder b
= new StringBuilder();
113 if (getDeclaration().isString()) {
114 for (Definition def
: fDefinitions
) {
115 IntegerDefinition character
= (IntegerDefinition
) def
;
117 if (character
.getValue() == 0) {
121 b
.append(character
.toString());
125 Joiner joiner
= Joiner
.on(", ").skipNulls(); //$NON-NLS-1$
126 b
.append(joiner
.join(fDefinitions
));
130 @SuppressWarnings("null")
131 @NonNull String ret
= b
.toString();