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
.tracecompass
.ctf
.core
.event
.types
;
15 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
16 import org
.eclipse
.jdt
.annotation
.Nullable
;
17 import org
.eclipse
.tracecompass
.ctf
.core
.event
.scope
.IDefinitionScope
;
18 import org
.eclipse
.tracecompass
.ctf
.core
.event
.scope
.ILexicalScope
;
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
28 public abstract class ScopedDefinition
extends Definition
implements IDefinitionScope
{
34 * the event declaration
35 * @param definitionScope
36 * the definition is in a scope, (normally a struct) what is it?
38 * the name of the definition. (it is a field in the parent
41 public ScopedDefinition(IDeclaration declaration
, @Nullable IDefinitionScope definitionScope
, String fieldName
) {
42 super(declaration
, definitionScope
, fieldName
);
46 * Constructor This one takes the scope and thus speeds up definition
50 * the parent declaration
51 * @param definitionScope
59 public ScopedDefinition(StructDeclaration declaration
, @Nullable IDefinitionScope definitionScope
, String fieldName
, ILexicalScope scope
) {
60 super(declaration
, definitionScope
, fieldName
, scope
);
64 * Lookup an array in a struct. If the name returns a non-array (like an
65 * int) then the method returns null
68 * the name of the array
69 * @return the array or null.
71 public @Nullable AbstractArrayDefinition
lookupArrayDefinition(String name
) {
72 IDefinition def
= lookupDefinition(name
);
73 return (AbstractArrayDefinition
) ((def
instanceof AbstractArrayDefinition
) ? def
: null);
78 * Lookup an enum in a struct. If the name returns a non-enum (like an int)
79 * then the method returns null
82 * the name of the enum
83 * @return the enum or null if a definition is not found or it does not
84 * match the desired datatype.
87 public EnumDefinition
lookupEnum(String name
) {
88 IDefinition def
= lookupDefinition(name
);
89 return (EnumDefinition
) ((def
instanceof EnumDefinition
) ? def
: null);
93 * Lookup an integer in a struct. If the name returns a non-integer (like an
94 * float) then the method returns null
97 * the name of the integer
98 * @return the integer or null if a definition is not found or it does not
99 * match the desired datatype.
102 public IntegerDefinition
lookupInteger(String name
) {
103 IDefinition def
= lookupDefinition(name
);
104 return (IntegerDefinition
) ((def
instanceof IntegerDefinition
) ? def
: null);
108 * Lookup a string in a struct. If the name returns a non-string (like an
109 * int) then the method returns null
112 * the name of the string
113 * @return the string or null if a definition is not found or it does not
114 * match the desired datatype.
117 public StringDefinition
lookupString(String name
) {
118 IDefinition def
= lookupDefinition(name
);
119 return (StringDefinition
) ((def
instanceof StringDefinition
) ? def
: null);
123 * Lookup a struct in a struct. If the name returns a non-struct (like an
124 * int) then the method returns null
127 * the name of the struct
128 * @return the struct or null if a definition is not found or it does not
129 * match the desired datatype.
132 public StructDefinition
lookupStruct(String name
) {
133 IDefinition def
= lookupDefinition(name
);
134 return (StructDefinition
) ((def
instanceof StructDefinition
) ? def
: null);
138 * Lookup a variant in a struct. If the name returns a non-variant (like an
139 * int) then the method returns null
142 * the name of the variant
143 * @return the variant or null if a definition is not found or it does not
144 * match the desired datatype.
147 public VariantDefinition
lookupVariant(String name
) {
148 IDefinition def
= lookupDefinition(name
);
149 return (VariantDefinition
) ((def
instanceof VariantDefinition
) ? def
: null);