ctf: introducing the ICompositeDefinition
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / types / Definition.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 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.jdt.annotation.NonNull;
16 import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
17 import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
18
19 /**
20 * A CTF definition
21 *
22 * A definition is like an object of a declaration class. It fills the
23 * declaration with values. <br>
24 * An example: <br>
25 * int i = 0; <br>
26 * <b>int</b> is the declaration.<br>
27 * <b>i</b> is the definition.<br>
28 * <b>0</b> is the value assigned to the definition, not the declaration.<br>
29 *
30 * @version 1.0
31 * @author Matthew Khouzam
32 * @author Simon Marchi
33 */
34 public abstract class Definition implements IDefinition {
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
39
40 private final String fFieldName;
41
42 /** The complete path of this field */
43 private final @NonNull LexicalScope fPath;
44
45 private final IDefinitionScope fDefinitionScope;
46
47 @NonNull
48 private final IDeclaration fDeclaration;
49
50 // ------------------------------------------------------------------------
51 // Constructors
52 // ------------------------------------------------------------------------
53
54 /**
55 * Constructor
56 *
57 * @param declaration
58 * the event declaration
59 *
60 * @param definitionScope
61 * the definition is in a scope, (normally a struct) what is it?
62 * @param fieldName
63 * the name of the definition. (it is a field in the parent
64 * scope)
65 * @since 3.0
66 */
67 public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName) {
68 this(declaration, definitionScope, fieldName, declaration.getPath(definitionScope, fieldName));
69 }
70
71 /**
72 * Constructor This one takes the scope and thus speeds up definition
73 * creation
74 *
75 *
76 * @param declaration
77 * the event declaration
78 *
79 * @param definitionScope
80 * the definition is in a scope, (normally a struct) what is it?
81 *
82 * @param fieldName
83 * the name of the defintions. it is a field in the parent scope.
84 *
85 * @param scope
86 * the scope
87 * @since 3.1
88 */
89 public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName, @NonNull LexicalScope scope) {
90 fDeclaration = declaration;
91 fDefinitionScope = definitionScope;
92 fFieldName = fieldName;
93 fPath = scope;
94 }
95
96 // ------------------------------------------------------------------------
97 // Getters
98 // ------------------------------------------------------------------------
99
100 /**
101 * Get the field name in its container.
102 *
103 * @return The field name
104 * @since 2.0
105 */
106 protected String getFieldName() {
107 return fFieldName;
108 }
109
110 @Override
111 public LexicalScope getScopePath() {
112 return fPath;
113 }
114
115 /**
116 * Get the definition scope in which this definition is found.
117 *
118 * The complete path of a definition is thus the path of the definition
119 * scope DOT the name of the definition (name of the field in its container)
120 *
121 * @return The definition scope
122 * @since 3.0
123 */
124 protected IDefinitionScope getDefinitionScope() {
125 return fDefinitionScope;
126 }
127
128 // ------------------------------------------------------------------------
129 // Operations
130 // ------------------------------------------------------------------------
131
132 @Override
133 public IDeclaration getDeclaration() {
134 return fDeclaration;
135 }
136
137 @Override
138 public String toString() {
139 return fPath.toString() + '[' + Integer.toHexString(hashCode()) + ']';
140 }
141 }
This page took 0.071794 seconds and 5 git commands to generate.