1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others
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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.ctf
.core
.event
.types
;
15 import org
.eclipse
.jdt
.annotation
.NonNull
;
16 import org
.eclipse
.linuxtools
.ctf
.core
.event
.scope
.IDefinitionScope
;
19 * A CTF variant definition (similar to a C union).
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.
26 * @author Matthew Khouzam
27 * @author Simon Marchi
29 public final class VariantDefinition
extends ScopedDefinition
{
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
35 private final Definition fDefinition
;
36 private final String fCurrentField
;
37 private final String fFieldName
;
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
47 * the parent declaration
48 * @param definitionScope
50 * @param selectedField
58 public VariantDefinition(@NonNull VariantDeclaration declaration
,
59 IDefinitionScope definitionScope
, String selectedField
, @NonNull String fieldName
, Definition fieldValue
) {
60 super(declaration
, definitionScope
, fieldName
);
62 fFieldName
= fieldName
;
63 fCurrentField
= selectedField
;
64 fDefinition
= fieldValue
;
68 // ------------------------------------------------------------------------
69 // Getters/Setters/Predicates
70 // ------------------------------------------------------------------------
73 public VariantDeclaration
getDeclaration() {
74 return (VariantDeclaration
) super.getDeclaration();
78 * Get the current field name
80 * @return the current field name
82 public String
getCurrentFieldName() {
87 * Get the current field
89 * @return the current field
91 public Definition
getCurrentField() {
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
100 public Definition
lookupDefinition(String lookupPath
) {
101 if (lookupPath
== null) {
104 if (lookupPath
.equals(fFieldName
)) {
107 return getDefinitionScope().lookupDefinition(lookupPath
);
111 public String
toString() {
112 return "{ " + getCurrentFieldName() + //$NON-NLS-1$
113 " = " + getCurrentField() + //$NON-NLS-1$