Debian Codegraph @

src/main/java/com/eprosima/idl/parser/tree/Operation.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.tree.Param;
20
21 import java.util.ArrayList;
22 import org.antlr.v4.runtime.Token;
23
24 public class Operation extends TreeNode implements Export
25 {
26 public Operation(String scopeFile, boolean isInScope, String scope, String name, Token tk)
27 {
28 super(scopeFile, isInScope, scope, name, tk);
29
30 m_params = new ArrayList<Param>();
31 m_exceptions = new ArrayList<com.eprosima.idl.parser.tree.Exception>();
32 m_unresolvedExceptions = new ArrayList<String>();
33 }
34
35 public void setParent(Object obj)
36 {
37 m_parent = obj;
38 }
39
40 public Object getParent()
41 {
42 return m_parent;
43 }
44
45 public boolean isIsOperation()
46 {
47 return true;
48 }
49
50 @Override
51 public boolean isIsException()
52 {
53 return false;
54 }
55
56 @Override
57 public boolean isIsTypeDeclaration()
58 {
59 return false;
60 }
61
62 @Override
63 public boolean isIsConstDeclaration()
64 {
65 return false;
66 }
67
68 public void setOneway(boolean b)
69 {
70 m_isOneway = b;
71 }
72
73 public boolean isOneway()
74 {
75 return m_isOneway;
76 }
77
78 public void add(Param param)
79 {
80 m_params.add(param);
81 param.setParent(this);
82 }
83
84 public ArrayList<Param> getParameters()
85 {
86 return m_params;
87 }
88
89 public ArrayList<Param> getInputparam()
90 {
91 ArrayList<Param> input = new ArrayList<Param>();
92
93 for(int count = 0; count < m_params.size(); ++count)
94 if(m_params.get(count).isInput())
95 input.add(m_params.get(count));
96
97 return input;
98 }
99
100 public ArrayList<Param> getOutputparam()
101 {
102 ArrayList<Param> output = new ArrayList<Param>();
103
104 for(int count = 0; count < m_params.size(); ++count)
105 if(m_params.get(count).isOutput())
106 output.add(m_params.get(count));
107
108 return output;
109 }
110
111 public ArrayList<Param> getInoutputparam()
112 {
113 ArrayList<Param> inoutput = new ArrayList<Param>();
114
115 for(int count = 0; count < m_params.size(); ++count)
116 if(m_params.get(count).isInput() && m_params.get(count).isOutput())
117 inoutput.add(m_params.get(count));
118
119 return inoutput;
120 }
121
122 // TODO Delete when standard change.
123 public void setRettype(TypeCode rettype)
124 {
125 if(rettype != null)
126 {
127 m_rettype = rettype;
128 m_rettypeparam = new Param("return_", m_rettype, Param.Kind.OUT_PARAM);
129 }
130 }
131
132 public TypeCode getRettype()
133 {
134 return m_rettype;
135 }
136
137 public Param getRettypeparam()
138 {
139 return m_rettypeparam;
140 }
141
142 public void addException(com.eprosima.idl.parser.tree.Exception exception)
143 {
144 m_exceptions.add(exception);
145 }
146
147 public ArrayList<com.eprosima.idl.parser.tree.Exception> getExceptions()
148 {
149 return m_exceptions;
150 }
151
152 public void addUnresolvedException(String ename)
153 {
154 m_unresolvedExceptions.add(ename);
155 }
156
157 @Override
158 public boolean resolve(Context ctx)
159 {
160 //Resolve unresolved exceptions. This unresolved exceptions should be exceptions of the parent interface.
161
162 if(m_parent != null)
163 {
164 if(m_parent instanceof Interface)
165 {
166 Interface ifc = (Interface)m_parent;
167
168 for(int count = 0; count < m_unresolvedExceptions.size(); ++count)
169 {
170 com.eprosima.idl.parser.tree.Exception ex = ifc.getException(ctx.getScope(), m_unresolvedExceptions.get(count));
171
172 if(ex != null)
173 {
174
175 m_exceptions.add(ex);
176 }
177 else
178 {
179 System.out.println("ERROR: The definition of exception " + m_unresolvedExceptions.get(count) +
180 " was not found");
181 //TODO
182 //return false;
183 }
184 }
185
186 return true;
187 }
188 else
189 {
190 System.out.println("ERROR<Operation::resolve>: Parent is not an interface");
191 }
192 }
193 else
194 {
195 System.out.println("ERROR<Operation::resolve>: Not parent for operation");
196 }
197
198 return false;
199 }
200
201 @Override
202 protected boolean isDeclaredInsideInterface()
203 {
204 return true;
205 }
206
207 private Object m_parent = null;
208 private boolean m_isOneway = false;
209 private ArrayList<Param> m_params;
210 private ArrayList<com.eprosima.idl.parser.tree.Exception> m_exceptions;
211 private ArrayList<String> m_unresolvedExceptions;
212 private TypeCode m_rettype = null;
213 private Param m_rettypeparam = null;
214 }