1 /* 2 * Copyright (c) 2025 Shenzhen Kaihong Digital. 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 16 package grammar; 17 18 import utils.TsToken; 19 20 import java.util.List; 21 import java.util.concurrent.CopyOnWriteArrayList; 22 23 /** 24 * <h3>类名:该类用于xxx</h3> 25 * description function of grammar 26 * 27 * @author Administrator 28 * date 2025-02-28 29 * @version 1.0 30 * @since 2025-02-28 31 */ 32 public class FuncObj extends GBaseObject { 33 /** 34 * 访问方式: public, protected, private 35 */ 36 private String accessor; 37 38 /** 39 * 访问类型:async,get,set 40 */ 41 private String type; 42 43 /** 44 * 方法名称 45 */ 46 private String name; 47 48 /** 49 * 方法别名:可以是函数指针 50 */ 51 private String alias; 52 53 /** 54 * 方法返回值 55 */ 56 private String retValue; 57 58 /** 59 * 方法参数 60 */ 61 private List<ParamObj> paramList; 62 63 /** 64 * 限定 65 */ 66 private String qualifier; 67 68 /** 69 * 模板类型列表 70 */ 71 private List<String> tempList; 72 73 /** 74 * 声明类型 75 */ 76 private List<String> decList; 77 78 /** 79 * 构造函数 80 */ FuncObj()81 public FuncObj() { 82 this.token = TsToken.TS_TOKEN_FUNCTION; 83 this.accessor = TsToken.TS_TOKEN_PUBLIC; 84 this.type = ""; 85 this.retValue = TsToken.TS_TOKEN_VOID; 86 this.paramList = new CopyOnWriteArrayList<>(); 87 this.tempList = new CopyOnWriteArrayList<>(); 88 this.decList = new CopyOnWriteArrayList<>(); 89 } 90 91 /** 92 * 构造函数 93 * 94 * @param tv 类型 95 * @param nv 名字 96 * @param rv 返回值 97 * @param pl 参数 98 */ FuncObj(String tv, String nv, String rv, List<ParamObj> pl)99 public FuncObj(String tv, String nv, String rv, List<ParamObj> pl) { 100 this(); 101 102 this.type = tv; 103 this.name = nv; 104 this.retValue = rv; 105 this.paramList = pl; 106 } 107 108 /** 109 * 设置类型 110 * 111 * @param type 类型 112 */ setType(String type)113 public void setType(String type) { 114 this.type = type; 115 } 116 117 /** 118 * 获取类型 119 * 120 * @return 类型 121 */ getType()122 public String getType() { 123 return type; 124 } 125 126 /** 127 * 获取模板类 128 * 129 * @return 模板类列表 130 */ getTempList()131 public List<String> getTempList() { 132 return tempList; 133 } 134 135 /** 136 * 设置模板类 137 * 138 * @param tempList 模板类列表 139 */ setTempList(List<String> tempList)140 public void setTempList(List<String> tempList) { 141 this.tempList = tempList; 142 } 143 144 /** 145 * 获取模板类 146 * 147 * @param i 游标 148 * @return 模板类 149 */ getTemplate(int i)150 public String getTemplate(int i) { 151 return this.tempList.get(i); 152 } 153 154 /** 155 * 增加模板 156 * 157 * @param temp 模板 158 */ addTemplate(String temp)159 public void addTemplate(String temp) { 160 this.tempList.add(temp); 161 } 162 163 /** 164 * 设置限定 165 * 166 * @param qualifier 限定 167 */ setQualifier(String qualifier)168 public void setQualifier(String qualifier) { 169 this.qualifier = qualifier; 170 } 171 172 /** 173 * 获取限定 174 * 175 * @return 限定 176 */ getQualifier()177 public String getQualifier() { 178 return qualifier; 179 } 180 181 /** 182 * 设置alias 183 * 184 * @param alias 函数别名 185 */ setAlias(String alias)186 public void setAlias(String alias) { 187 this.alias = alias; 188 } 189 190 /** 191 * 获取alias 192 * 193 * @return 返回函数别名 194 */ getAlias()195 public String getAlias() { 196 return this.alias; 197 } 198 199 /** 200 * 设置访问属性 201 * 202 * @param accessor 访问属性 203 */ setAccessor(String accessor)204 public void setAccessor(String accessor) { 205 this.accessor = accessor; 206 } 207 208 /** 209 * 获取访问属性 210 * 211 * @return 访问属性 212 */ getAccessor()213 public String getAccessor() { 214 return accessor; 215 } 216 217 /** 218 * 设置名称 219 * 220 * @param name 名称 221 */ setName(String name)222 public void setName(String name) { 223 this.name = name; 224 } 225 226 /** 227 * 获取名称 228 * 229 * @return 名称 230 */ getName()231 public String getName() { 232 return name; 233 } 234 235 /** 236 * 设置返回值 237 * 238 * @param retValue 返回值 239 */ setRetValue(String retValue)240 public void setRetValue(String retValue) { 241 this.retValue = retValue; 242 } 243 244 /** 245 * 获取返回值 246 * 247 * @return 返回值 248 */ getRetValue()249 public String getRetValue() { 250 return retValue; 251 } 252 253 /** 254 * 设置参数 255 * 256 * @param paramList 参数 257 */ setParamList(List<ParamObj> paramList)258 public void setParamList(List<ParamObj> paramList) { 259 this.paramList = paramList; 260 } 261 262 /** 263 * 获取参数 264 * 265 * @return 参数 266 */ getParamList()267 public List<ParamObj> getParamList() { 268 return paramList; 269 } 270 271 /** 272 * 增加函数参数 273 * 274 * @param po 参数 275 */ addParam(ParamObj po)276 public void addParam(ParamObj po) { 277 this.paramList.add(po); 278 } 279 280 /** 281 * 增加函数参数 282 * 283 * @param name 参数名称 284 * @param type 参数类型 285 */ addParam(String name, String type)286 public void addParam(String name, String type) { 287 ParamObj po = new ParamObj(); 288 po.setName(name); 289 po.setType(type); 290 this.paramList.add(po); 291 } 292 293 /** 294 * 添加参数 295 * 296 * @param name 名字 297 * @param type 类型 298 * @param decorator 修饰 299 */ addParam(String name, String type, String decorator)300 public void addParam(String name, String type, String decorator) { 301 ParamObj po = new ParamObj(); 302 po.setName(name); 303 po.setType(type); 304 po.setDecorator(decorator); 305 this.paramList.add(po); 306 } 307 308 /** 309 * 添加声明类型 310 * 311 * @param decName 声明 312 */ addDecl(String decName)313 public void addDecl(String decName) { 314 this.decList.add(decName); 315 } 316 } 317