1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 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
;
17 import org
.eclipse
.linuxtools
.ctf
.core
.event
.scope
.LexicalScope
;
22 * A definition is like an object of a declaration class. It fills the
23 * declaration with values. <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>
31 * @author Matthew Khouzam
32 * @author Simon Marchi
34 public abstract class Definition
implements IDefinition
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
40 private final String fFieldName
;
42 /** The complete path of this field */
43 private final @NonNull LexicalScope fPath
;
45 private final IDefinitionScope fDefinitionScope
;
48 private final IDeclaration fDeclaration
;
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
58 * the event declaration
59 * @param definitionScope
60 * the definition is in a scope, (normally a struct) what is it?
62 * the name of the definition. (it is a field in the parent
66 public Definition(@NonNull IDeclaration declaration
, IDefinitionScope definitionScope
, @NonNull String fieldName
) {
67 this(declaration
, definitionScope
, fieldName
, declaration
.getPath(definitionScope
, fieldName
));
71 * Constructor This one takes the scope and thus speeds up definition
76 * the event declaration
78 * @param definitionScope
79 * the definition is in a scope, (normally a struct) what is it?
82 * the name of the defintions. it is a field in the parent scope.
88 public Definition(@NonNull IDeclaration declaration
, IDefinitionScope definitionScope
, @NonNull String fieldName
, @NonNull LexicalScope scope
) {
89 fDeclaration
= declaration
;
90 fDefinitionScope
= definitionScope
;
91 fFieldName
= fieldName
;
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
100 * Get the field name in its container.
102 * @return The field name
105 protected String
getFieldName() {
110 public LexicalScope
getScopePath() {
115 * Get the definition scope in which this definition is found.
117 * The complete path of a definition is thus the path of the definition
118 * scope DOT the name of the definition (name of the field in its container)
120 * @return The definition scope
123 protected IDefinitionScope
getDefinitionScope() {
124 return fDefinitionScope
;
127 // ------------------------------------------------------------------------
129 // ------------------------------------------------------------------------
132 public IDeclaration
getDeclaration() {
137 public String
toString() {
138 return fPath
.toString() + '[' + Integer
.toHexString(hashCode()) + ']';