ctf: Fix some Sonar warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / types / Definition.java
1 /*******************************************************************************
2 * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
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
13 package org.eclipse.linuxtools.ctf.core.event.types;
14
15 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
16
17 /**
18 * A CTF definiton
19 *
20 * A definition is like an object of a declaration class. It fills the declaration
21 * with values. <br>
22 * An example: <br>
23 * int i = 0; <br>
24 * <b>int</b> is the declaration.<br>
25 * <b>i</b> is the definition.<br>
26 * <b>0</b> is the value assigned to the definition, not the declaration.<br>
27 *
28 * @version 1.0
29 * @author Matthew Khouzam
30 * @author Simon Marchi
31 */
32 public abstract class Definition {
33
34 // ------------------------------------------------------------------------
35 // Attributes
36 // ------------------------------------------------------------------------
37
38 private final String fieldName;
39
40 /** The complete path of this field */
41 private final String path;
42
43 /**
44 *
45 */
46 private final IDefinitionScope definitionScope;
47
48 // ------------------------------------------------------------------------
49 // Constructors
50 // ------------------------------------------------------------------------
51
52 /**
53 * Constructor
54 *
55 * @param definitionScope
56 * the definition is in a scope, (normally a struct) what is it?
57 * @param fieldName
58 * the name of the definition. (it is a field in the parent
59 * scope)
60 */
61 public Definition(IDefinitionScope definitionScope, String fieldName) {
62 this.definitionScope = definitionScope;
63 this.fieldName = fieldName;
64 if (definitionScope != null) {
65 String parentPath = definitionScope.getPath();
66 if (parentPath.length() > 0) {
67 path = parentPath + "." + fieldName; //$NON-NLS-1$
68 } else {
69 path = fieldName;
70 }
71 } else {
72 path = fieldName;
73 }
74 }
75
76 // ------------------------------------------------------------------------
77 // Getters
78 // ------------------------------------------------------------------------
79
80 /**
81 * Get the field name in its container.
82 *
83 * @return The field name
84 * @since 2.0
85 */
86 protected String getFieldName() {
87 return fieldName;
88 }
89
90 /**
91 * Get the complete path of this field.
92 *
93 * @return The path
94 * @since 2.0
95 */
96 public String getPath() {
97 return path;
98 }
99
100 /**
101 * Get the definition scope in which this definition is found.
102 *
103 * The complete path of a definition is thus the path of the definition
104 * scope DOT the name of the definition (name of the field in its container)
105 *
106 * @return The definition scope
107 * @since 2.0
108 */
109 protected IDefinitionScope getDefinitionScope() {
110 return definitionScope;
111 }
112
113 // ------------------------------------------------------------------------
114 // Operations
115 // ------------------------------------------------------------------------
116
117 /**
118 *
119 * @return gets the declaration of a datatype
120 *
121 */
122 public abstract IDeclaration getDeclaration();
123
124 /**
125 * Read the definition from a bitbuffer
126 *
127 * @param input
128 * the bitbuffer containing the data to read.
129 * @since 2.0
130 */
131 public abstract void read(BitBuffer input);
132
133 @Override
134 public String toString() {
135 return path + '[' + Integer.toHexString(hashCode()) + ']';
136 }
137 }
This page took 0.034098 seconds and 5 git commands to generate.