3c0ca255fef513b9a29ff404faa9e76086df1a4c
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / types / ArrayDefinition.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others
3 *
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
8 *
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.ctf.core.event.types;
14
15 import java.util.List;
16
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;
21
22 import com.google.common.base.Joiner;
23 import com.google.common.collect.ImmutableList;
24
25 /**
26 * A CTF array definition
27 *
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.
32 *
33 * @deprecated use {@link AbstractArrayDefinition}
34 * @version 1.0
35 * @author Matthew Khouzam
36 * @author Simon Marchi
37 */
38 @NonNullByDefault
39 @Deprecated
40 public final class ArrayDefinition extends AbstractArrayDefinition{
41
42 // ------------------------------------------------------------------------
43 // Attributes
44 // ------------------------------------------------------------------------
45
46 private final ImmutableList<Definition> fDefinitions;
47
48 // ------------------------------------------------------------------------
49 // Constructors
50 // ------------------------------------------------------------------------
51
52 /**
53 * Constructor
54 *
55 * @param declaration
56 * the parent declaration
57 * @param definitionScope
58 * the parent scope
59 * @param fieldName
60 * the field name
61 * @param definitions
62 * the content of the array
63 * @since 3.0
64 */
65 public ArrayDefinition(ArrayDeclaration declaration,
66 @Nullable IDefinitionScope definitionScope,
67 String fieldName,
68 List<Definition> definitions) {
69 super(declaration, definitionScope, fieldName);
70 @SuppressWarnings("null")
71 @NonNull ImmutableList<Definition> list = ImmutableList.copyOf(definitions);
72 fDefinitions = list;
73
74 }
75
76 // ------------------------------------------------------------------------
77 // Getters/Setters/Predicates
78 // ------------------------------------------------------------------------
79
80 @Override
81 public List<Definition> getDefinitions() {
82 return fDefinitions;
83 }
84
85 /**
86 * Get the element at i
87 *
88 * @param i the index (cannot be negative)
89 * @return The element at I, if I &gt; length, null, if I &lt; 0, the method throws an out of bounds exception
90 */
91 @Nullable
92 public Definition getElem(int i) {
93 if (i > fDefinitions.size()) {
94 return null;
95 }
96
97 return fDefinitions.get(i);
98 }
99
100 @Override
101 public ArrayDeclaration getDeclaration() {
102 return (ArrayDeclaration) super.getDeclaration();
103 }
104
105 // ------------------------------------------------------------------------
106 // Operations
107 // ------------------------------------------------------------------------
108
109 @Override
110 public String toString() {
111 StringBuilder b = new StringBuilder();
112
113 if (getDeclaration().isString()) {
114 for (Definition def : fDefinitions) {
115 IntegerDefinition character = (IntegerDefinition) def;
116
117 if (character.getValue() == 0) {
118 break;
119 }
120
121 b.append(character.toString());
122 }
123 } else {
124 b.append('[');
125 Joiner joiner = Joiner.on(", ").skipNulls(); //$NON-NLS-1$
126 b.append(joiner.join(fDefinitions));
127 b.append(']');
128 }
129
130 @SuppressWarnings("null")
131 @NonNull String ret = b.toString();
132 return ret;
133 }
134 }
This page took 0.045476 seconds and 4 git commands to generate.