Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 451983146344e330d145dc0ca28caf0debd76846 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*******************************************************************************
 * Copyright (c) 2014 Ericsson
 *
 * All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Matthew Khouzam - Initial API and implementation
 *******************************************************************************/

package org.eclipse.linuxtools.ctf.core.event.types;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;

/**
 * Scoped defintion. a defintion where you can lookup various datatypes
 *
 * TODO: replace by default methods and an interface when java 8 is upon us
 *
 * @author Matthew Khouzam
 * @since 3.1
 */
@NonNullByDefault
public abstract class ScopedDefinition extends Definition implements IDefinitionScope {

    /**
     * Constructor
     *
     * @param declaration
     *            the event declaration
     * @param definitionScope
     *            the definition is in a scope, (normally a struct) what is it?
     * @param fieldName
     *            the name of the definition. (it is a field in the parent
     *            scope)
     */
    public ScopedDefinition(IDeclaration declaration, @Nullable IDefinitionScope definitionScope, String fieldName) {
        super(declaration, definitionScope, fieldName);
    }

    /**
     * Constructor This one takes the scope and thus speeds up definition
     * creation
     *
     * @param declaration
     *            the parent declaration
     * @param definitionScope
     *            the parent scope
     * @param fieldName
     *            the field name
     * @param scope
     *            the lexical scope
     * @since 3.1
     */
    public ScopedDefinition(StructDeclaration declaration, @Nullable IDefinitionScope definitionScope, String fieldName, LexicalScope scope) {
        super(declaration, definitionScope, fieldName, scope);
    }

    /**
     * Lookup an array in a struct. If the name returns a non-array (like an
     * int) then the method returns null
     *
     * @param name
     *            the name of the array
     * @return the array or null.
     */
    public @Nullable AbstractArrayDefinition lookupArrayDefinition(String name) {
        Definition def = lookupDefinition(name);
        return (AbstractArrayDefinition) ((def instanceof AbstractArrayDefinition) ? def : null);
    }

    /**
     * Lookup an array in a struct. If the name returns a non-array (like an
     * int) then the method returns null
     *
     * @param name
     *            the name of the array
     * @return the array or null.
     * @deprecated use {@link ScopedDefinition#lookupArrayDefinition(String)}
     */
    @Deprecated
    @Nullable
    public ArrayDefinition lookupArray(String name) {
        Definition def = lookupDefinition(name);
        return (ArrayDefinition) ((def instanceof ArrayDefinition) ? def : null);
    }

    /**
     * Lookup an enum in a struct. If the name returns a non-enum (like an int)
     * then the method returns null
     *
     * @param name
     *            the name of the enum
     * @return the enum or null if a definition is not found or it does not
     *         match the desired datatype.
     */
    @Nullable
    public EnumDefinition lookupEnum(String name) {
        Definition def = lookupDefinition(name);
        return (EnumDefinition) ((def instanceof EnumDefinition) ? def : null);
    }

    /**
     * Lookup an integer in a struct. If the name returns a non-integer (like an
     * float) then the method returns null
     *
     * @param name
     *            the name of the integer
     * @return the integer or null if a definition is not found or it does not
     *         match the desired datatype.
     */
    @Nullable
    public IntegerDefinition lookupInteger(String name) {
        Definition def = lookupDefinition(name);
        return (IntegerDefinition) ((def instanceof IntegerDefinition) ? def : null);
    }

    /**
     * Lookup a sequence in a struct. If the name returns a non-sequence (like
     * an int) then the method returns null
     *
     * @param name
     *            the name of the sequence
     * @return the sequence or null if a definition is not found or it does not
     *         match the desired datatype.
     * @since 3.0
     * @deprecated use {@link ScopedDefinition#lookupArrayDefinition(String)}
     */
    @Deprecated
    @Nullable
    public SequenceDefinition lookupSequence(String name) {
        Definition def = lookupDefinition(name);
        return (SequenceDefinition) ((def instanceof SequenceDefinition) ? def : null);
    }

    /**
     * Lookup a string in a struct. If the name returns a non-string (like an
     * int) then the method returns null
     *
     * @param name
     *            the name of the string
     * @return the string or null if a definition is not found or it does not
     *         match the desired datatype.
     */
    @Nullable
    public StringDefinition lookupString(String name) {
        Definition def = lookupDefinition(name);
        return (StringDefinition) ((def instanceof StringDefinition) ? def : null);
    }

    /**
     * Lookup a struct in a struct. If the name returns a non-struct (like an
     * int) then the method returns null
     *
     * @param name
     *            the name of the struct
     * @return the struct or null if a definition is not found or it does not
     *         match the desired datatype.
     */
    @Nullable
    public StructDefinition lookupStruct(String name) {
        Definition def = lookupDefinition(name);
        return (StructDefinition) ((def instanceof StructDefinition) ? def : null);
    }

    /**
     * Lookup a variant in a struct. If the name returns a non-variant (like an
     * int) then the method returns null
     *
     * @param name
     *            the name of the variant
     * @return the variant or null if a definition is not found or it does not
     *         match the desired datatype.
     */
    @Nullable
    public VariantDefinition lookupVariant(String name) {
        Definition def = lookupDefinition(name);
        return (VariantDefinition) ((def instanceof VariantDefinition) ? def : null);
    }
}

Back to the top