Debian Codegraph @

src/main/java/com/eprosima/idl/parser/tree/Param.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.parser.typecode.TypeCode;
18 import com.eprosima.idl.context.Context;
19
20 import java.util.Map;
21 import java.util.HashMap;
22
23 public class Param implements Notebook
24 {
25 public enum Kind
26 {
27 IN_PARAM,
28 OUT_PARAM,
29 INOUT_PARAM
30 };
31
32 public boolean isInput()
33 {
34 if(m_kind == Kind.IN_PARAM || m_kind == Kind.INOUT_PARAM)
35 {
36 return true;
37 }
38
39 return false;
40 }
41
42 public boolean isOutput()
43 {
44 if(m_kind == Kind.OUT_PARAM || m_kind == Kind.INOUT_PARAM)
45 {
46 return true;
47 }
48
49 return false;
50 }
51
52 public boolean isOnlyOutput()
53 {
54 if(m_kind == Kind.OUT_PARAM)
55 {
56 return true;
57 }
58
59 return false;
60 }
61
62 public String getComment()
63 {
64 if(m_kind == Kind.IN_PARAM)
65 return "in";
66 else if(m_kind == Kind.OUT_PARAM)
67 return "out";
68 else if(m_kind == Kind. INOUT_PARAM)
69 return "inout";
70
71 return "error";
72 }
73
74 public Param(String name, TypeCode typecode, Kind kind)
75 {
76 m_name = name;
77 m_typecode = typecode;
78 m_kind = kind;
79 }
80
81 public Param(String name, Definition definition, Kind kind)
82 {
83 m_name = name;
84 m_definition = definition;
85 m_kind = kind;
86 }
87
88 public String getName()
89 {
90 return m_name;
91 }
92
93 public TypeCode getTypecode()
94 {
95 return m_typecode;
96 }
97
98 public Definition getDefinition()
99 {
100 return m_definition;
101 }
102
103 public void setParent(Object obj)
104 {
105 m_parent = obj;
106 }
107
108 public Object getParent()
109 {
110 return m_parent;
111 }
112
113 @Override
114 public void addAnnotation(Context ctx, Annotation annotation)
115 {
116 if(annotation != null)
117 {
118 m_annotations.put(annotation.getName(), annotation);
119 }
120 }
121
122 @Override
123 public Map<String, Annotation> getAnnotations()
124 {
125 return m_annotations;
126 }
127
128 private Kind m_kind = Kind.IN_PARAM;
129 private String m_name = null;
130 private TypeCode m_typecode = null;
131 private Definition m_definition = null;
132 private Object m_parent = null;
133 //! Map that stores the annotations of the parameter.
134 private HashMap<String, Annotation> m_annotations = new HashMap<String, Annotation>();
135 }