1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.ctf
.core
.event
.types
;
15 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
16 import org
.eclipse
.jdt
.annotation
.Nullable
;
17 import org
.eclipse
.linuxtools
.ctf
.core
.event
.scope
.IDefinitionScope
;
18 import org
.eclipse
.linuxtools
.ctf
.core
.event
.scope
.LexicalScope
;
21 * Scoped defintion. a defintion where you can lookup various datatypes
23 * TODO: replace by default methods and an interface when java 8 is upon us
25 * @author Matthew Khouzam
29 public abstract class ScopedDefinition
extends Definition
implements IDefinitionScope
{
35 * the event declaration
36 * @param definitionScope
37 * the definition is in a scope, (normally a struct) what is it?
39 * the name of the definition. (it is a field in the parent
42 public ScopedDefinition(IDeclaration declaration
, @Nullable IDefinitionScope definitionScope
, String fieldName
) {
43 super(declaration
, definitionScope
, fieldName
);
47 * Constructor This one takes the scope and thus speeds up definition
51 * the parent declaration
52 * @param definitionScope
60 public ScopedDefinition(StructDeclaration declaration
, @Nullable IDefinitionScope definitionScope
, String fieldName
, LexicalScope scope
) {
61 super(declaration
, definitionScope
, fieldName
, scope
);
65 * Lookup an array in a struct. If the name returns a non-array (like an
66 * int) then the method returns null
69 * the name of the array
70 * @return the array or null.
72 public @Nullable AbstractArrayDefinition
lookupArrayDefinition(String name
) {
73 Definition def
= lookupDefinition(name
);
74 return (AbstractArrayDefinition
) ((def
instanceof AbstractArrayDefinition
) ? def
: null);
78 * Lookup an array in a struct. If the name returns a non-array (like an
79 * int) then the method returns null
82 * the name of the array
83 * @return the array or null.
84 * @deprecated use {@link ScopedDefinition#lookupArrayDefinition(String)}
88 public ArrayDefinition
lookupArray(String name
) {
89 Definition def
= lookupDefinition(name
);
90 return (ArrayDefinition
) ((def
instanceof ArrayDefinition
) ? def
: null);
94 * Lookup an enum in a struct. If the name returns a non-enum (like an int)
95 * then the method returns null
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.
103 public EnumDefinition
lookupEnum(String name
) {
104 Definition def
= lookupDefinition(name
);
105 return (EnumDefinition
) ((def
instanceof EnumDefinition
) ? def
: null);
109 * Lookup an integer in a struct. If the name returns a non-integer (like an
110 * float) then the method returns null
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.
118 public IntegerDefinition
lookupInteger(String name
) {
119 Definition def
= lookupDefinition(name
);
120 return (IntegerDefinition
) ((def
instanceof IntegerDefinition
) ? def
: null);
124 * Lookup a sequence in a struct. If the name returns a non-sequence (like
125 * an int) then the method returns null
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.
132 * @deprecated use {@link ScopedDefinition#lookupArrayDefinition(String)}
136 public SequenceDefinition
lookupSequence(String name
) {
137 Definition def
= lookupDefinition(name
);
138 return (SequenceDefinition
) ((def
instanceof SequenceDefinition
) ? def
: null);
142 * Lookup a string in a struct. If the name returns a non-string (like an
143 * int) then the method returns null
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.
151 public StringDefinition
lookupString(String name
) {
152 Definition def
= lookupDefinition(name
);
153 return (StringDefinition
) ((def
instanceof StringDefinition
) ? def
: null);
157 * Lookup a struct in a struct. If the name returns a non-struct (like an
158 * int) then the method returns null
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.
166 public StructDefinition
lookupStruct(String name
) {
167 Definition def
= lookupDefinition(name
);
168 return (StructDefinition
) ((def
instanceof StructDefinition
) ? def
: null);
172 * Lookup a variant in a struct. If the name returns a non-variant (like an
173 * int) then the method returns null
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.
181 public VariantDefinition
lookupVariant(String name
) {
182 Definition def
= lookupDefinition(name
);
183 return (VariantDefinition
) ((def
instanceof VariantDefinition
) ? def
: null);