rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / ctf / core / event / types / Definition.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 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.tracecompass.ctf.core.event.types;
14
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope;
17 import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope;
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 ILexicalScope 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 * @param definitionScope
60 * the definition is in a scope, (normally a struct) what is it?
61 * @param fieldName
62 * the name of the definition. (it is a field in the parent
63 * scope)
64 */
65 public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName) {
66 this(declaration, definitionScope, fieldName, declaration.getPath(definitionScope, fieldName));
67 }
68
69 /**
70 * Constructor This one takes the scope and thus speeds up definition
71 * creation
72 *
73 *
74 * @param declaration
75 * the event declaration
76 *
77 * @param definitionScope
78 * the definition is in a scope, (normally a struct) what is it?
79 *
80 * @param fieldName
81 * the name of the defintions. it is a field in the parent scope.
82 *
83 * @param scope
84 * the scope
85 * @since 1.0
86 */
87 public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName, @NonNull ILexicalScope scope) {
88 fDeclaration = declaration;
89 fDefinitionScope = definitionScope;
90 fFieldName = fieldName;
91 fPath = scope;
92 }
93
94 // ------------------------------------------------------------------------
95 // Getters
96 // ------------------------------------------------------------------------
97
98 /**
99 * Get the field name in its container.
100 *
101 * @return The field name
102 */
103 protected String getFieldName() {
104 return fFieldName;
105 }
106
107 /**
108 * @since 1.0
109 */
110 @Override
111 public ILexicalScope 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 */
123 protected IDefinitionScope getDefinitionScope() {
124 return fDefinitionScope;
125 }
126
127 // ------------------------------------------------------------------------
128 // Operations
129 // ------------------------------------------------------------------------
130
131 @Override
132 public IDeclaration getDeclaration() {
133 return fDeclaration;
134 }
135
136 @Override
137 public String toString() {
138 return fPath.getPath() + '[' + Integer.toHexString(hashCode()) + ']';
139 }
140 }
This page took 0.033634 seconds and 5 git commands to generate.