Commit | Line | Data |
---|---|---|
7b4f13e6 MK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 Ericsson | |
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: | |
10 | * Matthew Khouzam - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
f357bcd4 | 13 | package org.eclipse.tracecompass.internal.ctf.core.event.types; |
7b4f13e6 | 14 | |
5db5a3a4 AM |
15 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
16 | ||
7b4f13e6 MK |
17 | import java.util.List; |
18 | ||
7b4f13e6 MK |
19 | import org.eclipse.jdt.annotation.NonNullByDefault; |
20 | import org.eclipse.jdt.annotation.Nullable; | |
f357bcd4 AM |
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; | |
7b4f13e6 MK |
25 | |
26 | import com.google.common.base.Joiner; | |
27 | import com.google.common.collect.ImmutableList; | |
28 | ||
29 | /** | |
30 | * A CTF array definition | |
31 | * | |
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. | |
36 | * | |
7b4f13e6 | 37 | * @author Matthew Khouzam |
7b4f13e6 MK |
38 | */ |
39 | @NonNullByDefault | |
40 | public final class ArrayDefinition extends AbstractArrayDefinition { | |
41 | ||
42 | // ------------------------------------------------------------------------ | |
43 | // Attributes | |
44 | // ------------------------------------------------------------------------ | |
45 | ||
5db5a3a4 | 46 | private final List<Definition> fDefinitions; |
7b4f13e6 MK |
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 | */ | |
64 | public ArrayDefinition(CompoundDeclaration declaration, | |
65 | @Nullable IDefinitionScope definitionScope, | |
66 | String fieldName, | |
67 | List<Definition> definitions) { | |
68 | super(declaration, definitionScope, fieldName); | |
5db5a3a4 | 69 | fDefinitions = checkNotNull(ImmutableList.copyOf(definitions)); |
7b4f13e6 MK |
70 | } |
71 | ||
72 | // ------------------------------------------------------------------------ | |
73 | // Getters/Setters/Predicates | |
74 | // ------------------------------------------------------------------------ | |
75 | ||
76 | @Override | |
77 | public List<Definition> getDefinitions() { | |
78 | return fDefinitions; | |
79 | } | |
80 | ||
81 | /** | |
82 | * Get the the number of elements in the array | |
83 | * | |
84 | * @return how many elements in the array | |
85 | */ | |
86 | public int getLength() { | |
87 | return fDefinitions.size(); | |
88 | } | |
89 | ||
90 | // ------------------------------------------------------------------------ | |
91 | // Operations | |
92 | // ------------------------------------------------------------------------ | |
93 | ||
94 | @Override | |
95 | public String toString() { | |
96 | StringBuilder b = new StringBuilder(); | |
97 | b.append('['); | |
98 | Joiner joiner = Joiner.on(", ").skipNulls(); //$NON-NLS-1$ | |
99 | b.append(joiner.join(fDefinitions)); | |
100 | b.append(']'); | |
5db5a3a4 | 101 | return checkNotNull(b.toString()); |
7b4f13e6 MK |
102 | } |
103 | } |