Remove unneeded checkNotNull() calls
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / ctf / core / event / types / VariantDefinition.java
CommitLineData
866e5b51 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others
866e5b51
FC
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
f357bcd4 13package org.eclipse.tracecompass.ctf.core.event.types;
866e5b51 14
a4fa4e36 15import org.eclipse.jdt.annotation.NonNull;
f357bcd4 16import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope;
866e5b51
FC
17
18/**
d37aaa7f 19 * A CTF variant definition (similar to a C union).
486efb2e 20 *
d37aaa7f
FC
21 * A variant is similar to a C union, only taking the minimum size of the types,
22 * it is a compound data type that contains other datatypes in fields. they are
23 * stored in an hashmap and indexed by names which are strings.
24 *
25 * @version 1.0
26 * @author Matthew Khouzam
27 * @author Simon Marchi
866e5b51 28 */
163354ef 29public final class VariantDefinition extends ScopedDefinition {
866e5b51
FC
30
31 // ------------------------------------------------------------------------
32 // Attributes
33 // ------------------------------------------------------------------------
34
a4fa4e36
MK
35 private final Definition fDefinition;
36 private final String fCurrentField;
37 private final String fFieldName;
866e5b51
FC
38
39 // ------------------------------------------------------------------------
40 // Constructors
41 // ------------------------------------------------------------------------
42
9ac2eb62
MK
43 /**
44 * Constructor
a4fa4e36
MK
45 *
46 * @param declaration
47 * the parent declaration
48 * @param definitionScope
49 * the parent scope
50 * @param selectedField
51 * the selected field
52 * @param fieldName
53 * the field name
54 * @param fieldValue
55 * the field value
9ac2eb62 56 */
a4fa4e36
MK
57 public VariantDefinition(@NonNull VariantDeclaration declaration,
58 IDefinitionScope definitionScope, String selectedField, @NonNull String fieldName, Definition fieldValue) {
59 super(declaration, definitionScope, fieldName);
866e5b51 60
a4fa4e36
MK
61 fFieldName = fieldName;
62 fCurrentField = selectedField;
63 fDefinition = fieldValue;
866e5b51 64
866e5b51
FC
65 }
66
67 // ------------------------------------------------------------------------
68 // Getters/Setters/Predicates
69 // ------------------------------------------------------------------------
70
9ac2eb62 71 @Override
866e5b51 72 public VariantDeclaration getDeclaration() {
a4fa4e36 73 return (VariantDeclaration) super.getDeclaration();
866e5b51
FC
74 }
75
9ac2eb62
MK
76 /**
77 * Get the current field name
a4fa4e36 78 *
9ac2eb62
MK
79 * @return the current field name
80 */
81 public String getCurrentFieldName() {
a4fa4e36 82 return fCurrentField;
9ac2eb62
MK
83 }
84
85 /**
86 * Get the current field
a4fa4e36 87 *
9ac2eb62
MK
88 * @return the current field
89 */
90 public Definition getCurrentField() {
a4fa4e36 91 return fDefinition;
9ac2eb62
MK
92 }
93
866e5b51
FC
94 // ------------------------------------------------------------------------
95 // Operations
96 // ------------------------------------------------------------------------
97
fa533f33
MK
98 /**
99 * @since 1.0
100 */
866e5b51 101 @Override
fa533f33 102 public IDefinition lookupDefinition(String lookupPath) {
a4fa4e36
MK
103 if (lookupPath == null) {
104 return null;
105 }
106 if (lookupPath.equals(fFieldName)) {
107 return fDefinition;
108 }
5b341dc8
MK
109 if (fDefinition instanceof ScopedDefinition) {
110 IDefinition def = ((ScopedDefinition) fDefinition).lookupDefinition(lookupPath);
111 if (def != null) {
112 return def;
113 }
114 }
115 final IDefinitionScope definitionScope = getDefinitionScope();
116 if (definitionScope instanceof StructDefinition) {
117 StructDefinition structDefinition = (StructDefinition) definitionScope;
118 return structDefinition.lookupDefinition(lookupPath, this);
119 }
120 return definitionScope.lookupDefinition(lookupPath);
866e5b51
FC
121 }
122
419f09a8
SM
123 @Override
124 public String toString() {
125 return "{ " + getCurrentFieldName() + //$NON-NLS-1$
126 " = " + getCurrentField() + //$NON-NLS-1$
127 " }"; //$NON-NLS-1$
128 }
866e5b51 129}
This page took 0.070834 seconds and 5 git commands to generate.