Debian Codegraph @

src/main/java/com/eprosima/idl/parser/tree/AnnotationDeclaration.java

raw
1 // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package com.eprosima.idl.parser.tree;
16
17 import com.eprosima.idl.context.Context;
18 import com.eprosima.idl.parser.typecode.TypeCode;
19 import com.eprosima.idl.parser.typecode.EnumTypeCode;
20 import com.eprosima.idl.parser.typecode.AliasTypeCode;
21 import com.eprosima.idl.parser.tree.ConstDeclaration;
22
23 import java.util.List;
24 import java.util.ArrayList;
25 import java.util.Vector;
26 import java.util.HashMap;
27 import org.antlr.v4.runtime.Token;
28
29 public class AnnotationDeclaration extends TreeNode implements Definition
30 {
31 public AnnotationDeclaration(String scopeFile, boolean isInScope, String scope, String name, Token token)
32 {
33 super(scopeFile, isInScope, scope, name, token);
34 m_members = new HashMap<String, AnnotationMember>();
35 m_enums = new Vector<EnumTypeCode>();
36 m_consts = new Vector<ConstDeclaration>();
37 m_typedefs = new Vector<AliasTypeCode>();
38 }
39
40 public List<AnnotationMember> getMembers()
41 {
42 return new ArrayList<AnnotationMember>(m_members.values());
43 }
44
45 public int getMembersSize()
46 {
47 return m_members.values().size();
48 }
49
50 public void addMembers(AnnotationDeclaration annotation)
51 {
52 m_members.putAll(annotation.m_members);
53 }
54
55 public boolean addMember(AnnotationMember member)
56 {
57 // Check that in case of an Enum the given value is in the enumeration.
58 // ParseException is thrown otherwise.
59 member.getEnumStringValue();
60 if(!m_members.containsKey(member.getName()))
61 {
62 m_members.put(member.getName(), member);
63 return true;
64 }
65
66 return false;
67 }
68
69 public void setParent(Object obj)
70 {
71 m_parent = obj;
72 }
73
74 public Object getParent()
75 {
76 return m_parent;
77 }
78
79 @Override
80 public boolean isIsModule()
81 {
82 return false;
83 }
84
85 @Override
86 public boolean isIsException()
87 {
88 return false;
89 }
90
91 @Override
92 public boolean isIsInterface()
93 {
94 return false;
95 }
96
97 @Override
98 public boolean isIsTypeDeclaration()
99 {
100 return false;
101 }
102
103 @Override
104 public boolean isIsConstDeclaration()
105 {
106 return false;
107 }
108
109 @Override
110 public boolean isIsAnnotation()
111 {
112 return true;
113 }
114
115 public void addEnums(Vector<TypeCode> enums)
116 {
117 for (TypeCode tc : enums)
118 {
119 m_enums.add((EnumTypeCode)tc);
120 }
121 }
122
123 public void addConstDecl(ConstDeclaration consts)
124 {
125 m_consts.add(consts);
126 }
127
128 public void addTypeDefs(Vector<TypeCode> typedefs)
129 {
130 for (TypeCode tc : typedefs)
131 {
132 m_typedefs.add((AliasTypeCode)tc);
133 }
134 }
135
136 public List<EnumTypeCode> getEnums()
137 {
138 return new ArrayList<EnumTypeCode>(m_enums);
139 }
140
141 public EnumTypeCode getEnum(String name)
142 {
143 for (EnumTypeCode etc : m_enums)
144 {
145 if (etc.getName().equals(name))
146 {
147 return etc;
148 }
149 }
150 return null;
151 }
152
153 public List<ConstDeclaration> getConstDecls()
154 {
155 return new ArrayList<ConstDeclaration>(m_consts);
156 }
157
158 public ConstDeclaration getConstDecl(String name)
159 {
160 for (ConstDeclaration cdcl : m_consts)
161 {
162 if (cdcl.getName().equals(name))
163 {
164 return cdcl;
165 }
166 }
167 return null;
168 }
169
170 public List<AliasTypeCode> getTypeDefs()
171 {
172 return new ArrayList<AliasTypeCode>(m_typedefs);
173 }
174
175 public AliasTypeCode getTypeDef(String name)
176 {
177 for (AliasTypeCode atc : m_typedefs)
178 {
179 if (atc.getName().equals(name))
180 {
181 return atc;
182 }
183 }
184 return null;
185 }
186
187 public TypeCode getTypeCode(String name)
188 {
189 TypeCode result = getTypeDef(name);
190 if (result == null)
191 {
192 result = getEnum(name);
193 }
194 return result;
195 }
196
197 private Object m_parent = null;
198 private HashMap<String, AnnotationMember> m_members = null;
199 private Vector<EnumTypeCode> m_enums = null;
200 private Vector<ConstDeclaration> m_consts = null;
201 private Vector<AliasTypeCode> m_typedefs = null;
202 }