Commit | Line | Data |
---|---|---|
163354ef MK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 Ericsson | |
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: | |
10 | * Matthew Khouzam - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.ctf.core.event.types; | |
14 | ||
15 | import org.eclipse.jdt.annotation.NonNullByDefault; | |
16 | import org.eclipse.jdt.annotation.Nullable; | |
17 | import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; | |
70f60307 | 18 | import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope; |
163354ef MK |
19 | |
20 | /** | |
21 | * Scoped defintion. a defintion where you can lookup various datatypes | |
22 | * | |
23 | * TODO: replace by default methods and an interface when java 8 is upon us | |
24 | * | |
25 | * @author Matthew Khouzam | |
26 | * @since 3.1 | |
27 | */ | |
28 | @NonNullByDefault | |
29 | public abstract class ScopedDefinition extends Definition implements IDefinitionScope { | |
30 | ||
31 | /** | |
32 | * Constructor | |
33 | * | |
34 | * @param declaration | |
35 | * the event declaration | |
36 | * @param definitionScope | |
37 | * the definition is in a scope, (normally a struct) what is it? | |
38 | * @param fieldName | |
39 | * the name of the definition. (it is a field in the parent | |
40 | * scope) | |
41 | */ | |
42 | public ScopedDefinition(IDeclaration declaration, @Nullable IDefinitionScope definitionScope, String fieldName) { | |
43 | super(declaration, definitionScope, fieldName); | |
44 | } | |
45 | ||
70f60307 MK |
46 | /** |
47 | * Constructor This one takes the scope and thus speeds up definition | |
48 | * creation | |
49 | * | |
50 | * @param declaration | |
51 | * the parent declaration | |
52 | * @param definitionScope | |
53 | * the parent scope | |
54 | * @param fieldName | |
55 | * the field name | |
56 | * @param scope | |
57 | * the lexical scope | |
58 | * @since 3.1 | |
59 | */ | |
60 | public ScopedDefinition(StructDeclaration declaration, @Nullable IDefinitionScope definitionScope, String fieldName, LexicalScope scope) { | |
61 | super(declaration, definitionScope, fieldName, scope); | |
62 | } | |
63 | ||
163354ef MK |
64 | /** |
65 | * Lookup an array in a struct. If the name returns a non-array (like an | |
66 | * int) then the method returns null | |
67 | * | |
68 | * @param name | |
69 | * the name of the array | |
7b4f13e6 MK |
70 | * @return the array or null. |
71 | */ | |
70f60307 | 72 | public @Nullable AbstractArrayDefinition lookupArrayDefinition(String name) { |
7b4f13e6 MK |
73 | Definition def = lookupDefinition(name); |
74 | return (AbstractArrayDefinition) ((def instanceof AbstractArrayDefinition) ? def : null); | |
75 | } | |
76 | ||
77 | /** | |
78 | * Lookup an array in a struct. If the name returns a non-array (like an | |
79 | * int) then the method returns null | |
80 | * | |
81 | * @param name | |
82 | * the name of the array | |
83 | * @return the array or null. | |
70f60307 | 84 | * @deprecated use {@link ScopedDefinition#lookupArrayDefinition(String)} |
163354ef | 85 | */ |
7b4f13e6 | 86 | @Deprecated |
163354ef MK |
87 | @Nullable |
88 | public ArrayDefinition lookupArray(String name) { | |
89 | Definition def = lookupDefinition(name); | |
90 | return (ArrayDefinition) ((def instanceof ArrayDefinition) ? def : null); | |
91 | } | |
92 | ||
93 | /** | |
94 | * Lookup an enum in a struct. If the name returns a non-enum (like an int) | |
95 | * then the method returns null | |
96 | * | |
97 | * @param name | |
98 | * the name of the enum | |
99 | * @return the enum or null if a definition is not found or it does not | |
100 | * match the desired datatype. | |
101 | */ | |
102 | @Nullable | |
103 | public EnumDefinition lookupEnum(String name) { | |
104 | Definition def = lookupDefinition(name); | |
105 | return (EnumDefinition) ((def instanceof EnumDefinition) ? def : null); | |
106 | } | |
107 | ||
108 | /** | |
109 | * Lookup an integer in a struct. If the name returns a non-integer (like an | |
110 | * float) then the method returns null | |
111 | * | |
112 | * @param name | |
113 | * the name of the integer | |
114 | * @return the integer or null if a definition is not found or it does not | |
115 | * match the desired datatype. | |
116 | */ | |
117 | @Nullable | |
118 | public IntegerDefinition lookupInteger(String name) { | |
119 | Definition def = lookupDefinition(name); | |
120 | return (IntegerDefinition) ((def instanceof IntegerDefinition) ? def : null); | |
121 | } | |
122 | ||
123 | /** | |
124 | * Lookup a sequence in a struct. If the name returns a non-sequence (like | |
125 | * an int) then the method returns null | |
126 | * | |
127 | * @param name | |
128 | * the name of the sequence | |
129 | * @return the sequence or null if a definition is not found or it does not | |
130 | * match the desired datatype. | |
131 | * @since 3.0 | |
70f60307 | 132 | * @deprecated use {@link ScopedDefinition#lookupArrayDefinition(String)} |
163354ef | 133 | */ |
7b4f13e6 | 134 | @Deprecated |
163354ef MK |
135 | @Nullable |
136 | public SequenceDefinition lookupSequence(String name) { | |
137 | Definition def = lookupDefinition(name); | |
138 | return (SequenceDefinition) ((def instanceof SequenceDefinition) ? def : null); | |
139 | } | |
140 | ||
141 | /** | |
142 | * Lookup a string in a struct. If the name returns a non-string (like an | |
143 | * int) then the method returns null | |
144 | * | |
145 | * @param name | |
146 | * the name of the string | |
147 | * @return the string or null if a definition is not found or it does not | |
148 | * match the desired datatype. | |
149 | */ | |
150 | @Nullable | |
151 | public StringDefinition lookupString(String name) { | |
152 | Definition def = lookupDefinition(name); | |
153 | return (StringDefinition) ((def instanceof StringDefinition) ? def : null); | |
154 | } | |
155 | ||
156 | /** | |
157 | * Lookup a struct in a struct. If the name returns a non-struct (like an | |
158 | * int) then the method returns null | |
159 | * | |
160 | * @param name | |
161 | * the name of the struct | |
162 | * @return the struct or null if a definition is not found or it does not | |
163 | * match the desired datatype. | |
164 | */ | |
165 | @Nullable | |
166 | public StructDefinition lookupStruct(String name) { | |
167 | Definition def = lookupDefinition(name); | |
168 | return (StructDefinition) ((def instanceof StructDefinition) ? def : null); | |
169 | } | |
170 | ||
171 | /** | |
172 | * Lookup a variant in a struct. If the name returns a non-variant (like an | |
173 | * int) then the method returns null | |
174 | * | |
175 | * @param name | |
176 | * the name of the variant | |
177 | * @return the variant or null if a definition is not found or it does not | |
178 | * match the desired datatype. | |
179 | */ | |
180 | @Nullable | |
181 | public VariantDefinition lookupVariant(String name) { | |
182 | Definition def = lookupDefinition(name); | |
183 | return (VariantDefinition) ((def instanceof VariantDefinition) ? def : null); | |
184 | } | |
185 | } |