ctf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / internal / ctf / core / event / types / ArrayDefinition.java
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.tracecompass.internal.ctf.core.event.types;
14
15 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
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;
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 *
37 * @author Matthew Khouzam
38 */
39 @NonNullByDefault
40 public final class ArrayDefinition extends AbstractArrayDefinition {
41
42 // ------------------------------------------------------------------------
43 // Attributes
44 // ------------------------------------------------------------------------
45
46 private final List<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 */
64 public ArrayDefinition(CompoundDeclaration declaration,
65 @Nullable IDefinitionScope definitionScope,
66 String fieldName,
67 List<Definition> definitions) {
68 super(declaration, definitionScope, fieldName);
69 fDefinitions = checkNotNull(ImmutableList.copyOf(definitions));
70 }
71
72 // ------------------------------------------------------------------------
73 // Getters/Setters/Predicates
74 // ------------------------------------------------------------------------
75
76 @Override
77 public List<Definition> getDefinitions() {
78 return fDefinitions;
79 }
80
81 @Override
82 public int getLength() {
83 return fDefinitions.size();
84 }
85
86 // ------------------------------------------------------------------------
87 // Operations
88 // ------------------------------------------------------------------------
89
90 @Override
91 public String toString() {
92 StringBuilder b = new StringBuilder();
93 b.append('[');
94 Joiner joiner = Joiner.on(", ").skipNulls(); //$NON-NLS-1$
95 b.append(joiner.join(fDefinitions));
96 b.append(']');
97 return checkNotNull(b.toString());
98 }
99 }
This page took 0.03719 seconds and 5 git commands to generate.