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 | ||
13 | package org.eclipse.linuxtools.internal.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 | import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition; | |
22 | import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration; | |
23 | import org.eclipse.linuxtools.ctf.core.event.types.Definition; | |
24 | ||
25 | import com.google.common.base.Joiner; | |
26 | import com.google.common.collect.ImmutableList; | |
27 | ||
28 | /** | |
29 | * A CTF array definition | |
30 | * | |
31 | * Arrays are fixed-length. Their length is declared in the type declaration | |
32 | * within the meta-data. They contain an array of "inner type" elements, which | |
33 | * can refer to any type not containing the type of the array being declared (no | |
34 | * circular dependency). The length is the number of elements in an array. | |
35 | * | |
36 | * @version 1.0 | |
37 | * @author Matthew Khouzam | |
38 | * @since 3.1 | |
39 | */ | |
40 | @NonNullByDefault | |
41 | public final class ArrayDefinition extends AbstractArrayDefinition { | |
42 | ||
43 | // ------------------------------------------------------------------------ | |
44 | // Attributes | |
45 | // ------------------------------------------------------------------------ | |
46 | ||
47 | private final ImmutableList<Definition> fDefinitions; | |
48 | ||
49 | // ------------------------------------------------------------------------ | |
50 | // Constructors | |
51 | // ------------------------------------------------------------------------ | |
52 | ||
53 | /** | |
54 | * Constructor | |
55 | * | |
56 | * @param declaration | |
57 | * the parent declaration | |
58 | * @param definitionScope | |
59 | * the parent scope | |
60 | * @param fieldName | |
61 | * the field name | |
62 | * @param definitions | |
63 | * the content of the array | |
64 | */ | |
65 | public ArrayDefinition(CompoundDeclaration 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 | // Getters/Setters/Predicates | |
77 | // ------------------------------------------------------------------------ | |
78 | ||
79 | @Override | |
80 | public List<Definition> getDefinitions() { | |
81 | return fDefinitions; | |
82 | } | |
83 | ||
84 | /** | |
85 | * Get the the number of elements in the array | |
86 | * | |
87 | * @return how many elements in the array | |
88 | */ | |
89 | public int getLength() { | |
90 | return fDefinitions.size(); | |
91 | } | |
92 | ||
93 | // ------------------------------------------------------------------------ | |
94 | // Operations | |
95 | // ------------------------------------------------------------------------ | |
96 | ||
97 | @Override | |
98 | public String toString() { | |
99 | StringBuilder b = new StringBuilder(); | |
100 | b.append('['); | |
101 | Joiner joiner = Joiner.on(", ").skipNulls(); //$NON-NLS-1$ | |
102 | b.append(joiner.join(fDefinitions)); | |
103 | b.append(']'); | |
104 | @SuppressWarnings("null") | |
105 | @NonNull String ret = b.toString(); | |
106 | return ret; | |
107 | } | |
108 | } |