[77] | 1 | package com.framsticks.params; |
---|
| 2 | |
---|
[86] | 3 | import com.framsticks.params.annotations.FramsClassAnnotation; |
---|
| 4 | import com.framsticks.params.annotations.ParamAnnotation; |
---|
[77] | 5 | import com.framsticks.params.types.*; |
---|
[88] | 6 | import com.framsticks.util.Builder; |
---|
[87] | 7 | import com.framsticks.util.FramsticksException; |
---|
[96] | 8 | import com.framsticks.util.Misc; |
---|
[99] | 9 | import com.framsticks.util.lang.FlagsUtil; |
---|
[87] | 10 | import com.framsticks.util.lang.Strings; |
---|
[84] | 11 | |
---|
[77] | 12 | import org.apache.log4j.Logger; |
---|
| 13 | |
---|
[87] | 14 | import java.lang.reflect.InvocationTargetException; |
---|
[90] | 15 | import java.util.ArrayList; |
---|
[77] | 16 | import java.util.Arrays; |
---|
[87] | 17 | import java.util.List; |
---|
[90] | 18 | import java.util.regex.Matcher; |
---|
| 19 | import java.util.regex.Pattern; |
---|
[77] | 20 | |
---|
[90] | 21 | import javax.annotation.Nonnull; |
---|
| 22 | |
---|
[77] | 23 | /** |
---|
| 24 | * The class ParamBuilder helps building Param objects. |
---|
[84] | 25 | * |
---|
[77] | 26 | * @author Mateusz Jarus <name.surname@gmail.com> (please replace name and |
---|
| 27 | * surname with my personal data) |
---|
| 28 | * |
---|
| 29 | * @author Piotr Śniegowski |
---|
| 30 | */ |
---|
| 31 | |
---|
[86] | 32 | @FramsClassAnnotation(name = "prop", id = "prop") |
---|
[88] | 33 | public class ParamBuilder implements Builder<Param> { |
---|
[84] | 34 | private final static Logger log = Logger.getLogger(ParamBuilder.class.getName()); |
---|
[77] | 35 | |
---|
| 36 | private static final String ID_FIELD = "id"; |
---|
| 37 | private static final String NAME_FIELD = "name"; |
---|
| 38 | private static final String HELP_FIELD = "help"; |
---|
| 39 | private static final String GROUP_FIELD = "group"; |
---|
| 40 | private static final String TYPE_FIELD = "type"; |
---|
| 41 | private static final String FLAGS_FIELD = "flags"; |
---|
| 42 | |
---|
[86] | 43 | /** The parameter id. */ |
---|
[77] | 44 | private String id; |
---|
| 45 | |
---|
| 46 | /** The number of group, that parameter belongs to. */ |
---|
[90] | 47 | private Integer group; |
---|
[77] | 48 | |
---|
[86] | 49 | /** The flags stored as a bit sum. */ |
---|
[96] | 50 | private int flags = 0; |
---|
[77] | 51 | |
---|
[86] | 52 | /** The parameter name. */ |
---|
[77] | 53 | private String name; |
---|
| 54 | |
---|
[86] | 55 | /** The help (description) concerning parameter. */ |
---|
[77] | 56 | private String help; |
---|
| 57 | |
---|
[86] | 58 | /** The type of parameter. */ |
---|
[84] | 59 | private Class<? extends Param> paramType; |
---|
[77] | 60 | |
---|
[87] | 61 | private Object min; |
---|
[77] | 62 | |
---|
[87] | 63 | private Object max; |
---|
| 64 | |
---|
| 65 | private Object def; |
---|
| 66 | |
---|
[96] | 67 | private int extra = 0; |
---|
[88] | 68 | |
---|
[99] | 69 | protected String containedTypeName; |
---|
[87] | 70 | |
---|
[99] | 71 | protected String eventArgumentTypeName; |
---|
| 72 | |
---|
[88] | 73 | protected Class<?> storageType; |
---|
| 74 | |
---|
[87] | 75 | protected FramsClassBuilder classBuilder; |
---|
| 76 | |
---|
[86] | 77 | public ParamBuilder() { |
---|
[87] | 78 | this(null); |
---|
[85] | 79 | } |
---|
| 80 | |
---|
[90] | 81 | protected ValueParam resultType; |
---|
[87] | 82 | |
---|
[90] | 83 | protected List<ValueParam> argumentsType; |
---|
| 84 | |
---|
[77] | 85 | /** |
---|
[87] | 86 | * @param classBuilder |
---|
| 87 | */ |
---|
| 88 | public ParamBuilder(FramsClassBuilder classBuilder) { |
---|
| 89 | this.classBuilder = classBuilder; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | /** |
---|
| 94 | * @return the min |
---|
| 95 | */ |
---|
[88] | 96 | @ParamAnnotation |
---|
[87] | 97 | public Object getMin() { |
---|
| 98 | return min; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | /** |
---|
| 102 | * @return the max |
---|
| 103 | */ |
---|
[88] | 104 | @ParamAnnotation |
---|
[87] | 105 | public Object getMax() { |
---|
| 106 | return max; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | /** |
---|
| 110 | * @return the def |
---|
| 111 | */ |
---|
[88] | 112 | @ParamAnnotation |
---|
[87] | 113 | public Object getDef() { |
---|
| 114 | return def; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | public String getContainedTypeName() { |
---|
| 118 | return Strings.notEmpty(containedTypeName) ? containedTypeName : null; |
---|
| 119 | } |
---|
| 120 | |
---|
[99] | 121 | public ParamBuilder containedTypeName(String containedTypeName) { |
---|
| 122 | this.containedTypeName = containedTypeName; |
---|
| 123 | return this; |
---|
| 124 | } |
---|
| 125 | |
---|
[87] | 126 | /** |
---|
[90] | 127 | * @return the resultType |
---|
[87] | 128 | */ |
---|
[90] | 129 | public ValueParam getResultType() { |
---|
| 130 | return resultType; |
---|
[87] | 131 | } |
---|
| 132 | |
---|
[90] | 133 | |
---|
[87] | 134 | /** |
---|
[90] | 135 | * @param resultType the resultType to set |
---|
[87] | 136 | */ |
---|
[90] | 137 | public ParamBuilder resultType(ValueParam resultType) { |
---|
| 138 | this.resultType = resultType; |
---|
| 139 | return this; |
---|
[87] | 140 | } |
---|
| 141 | |
---|
| 142 | /** |
---|
[90] | 143 | * @return the argumentsType |
---|
| 144 | */ |
---|
| 145 | public List<ValueParam> getArgumentsType() { |
---|
| 146 | return argumentsType; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | /** |
---|
| 151 | * @param argumentsType the argumentsType to set |
---|
| 152 | */ |
---|
| 153 | public ParamBuilder argumentsType(List<ValueParam> argumentsType) { |
---|
| 154 | this.argumentsType = argumentsType; |
---|
| 155 | return this; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | /** |
---|
| 159 | * @return the enumValues |
---|
| 160 | */ |
---|
| 161 | public List<String> getEnumValues() { |
---|
| 162 | return enumValues; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | /** |
---|
[87] | 166 | * @return the uid |
---|
| 167 | */ |
---|
| 168 | public String getUid() { |
---|
| 169 | return uid; |
---|
| 170 | } |
---|
| 171 | |
---|
[99] | 172 | public ParamBuilder uid(String uid) { |
---|
| 173 | this.uid = uid; |
---|
| 174 | return this; |
---|
| 175 | } |
---|
| 176 | |
---|
[90] | 177 | public @Nonnull <T extends Param> T finish(Class<T> requested) { |
---|
| 178 | Param param = finish(); |
---|
| 179 | if (!requested.isInstance(param)) { |
---|
| 180 | throw new FramsticksException().msg("param is of wrong type").arg("requested", requested).arg("actual", param.getClass()); |
---|
| 181 | } |
---|
| 182 | return requested.cast(param); |
---|
| 183 | } |
---|
| 184 | |
---|
[87] | 185 | /** |
---|
[77] | 186 | * Build Param based on provided data. |
---|
[84] | 187 | * |
---|
[77] | 188 | * @return Param object |
---|
| 189 | * @throws Exception |
---|
| 190 | * when Param getType is not defined |
---|
| 191 | */ |
---|
[90] | 192 | public @Nonnull Param finish() { |
---|
[87] | 193 | try { |
---|
[88] | 194 | if (paramType == null) { |
---|
[96] | 195 | throw new FramsticksException().msg("trying to finish incomplete param while type is missing"); |
---|
[88] | 196 | } |
---|
[87] | 197 | return paramType.getConstructor(ParamBuilder.class).newInstance(this); |
---|
[88] | 198 | } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | FramsticksException e) { |
---|
[87] | 199 | throw new FramsticksException().msg("failed to create param").cause(e).arg("name", name); |
---|
| 200 | } |
---|
[77] | 201 | } |
---|
| 202 | |
---|
[86] | 203 | @ParamAnnotation |
---|
[85] | 204 | public ParamBuilder id(String id) { |
---|
[77] | 205 | this.id = id; |
---|
| 206 | return this; |
---|
| 207 | } |
---|
| 208 | |
---|
[85] | 209 | public <T extends Param> ParamBuilder type(Class<T> type) { |
---|
[86] | 210 | assert type != null; |
---|
[87] | 211 | this.paramType = type; |
---|
[77] | 212 | return this; |
---|
| 213 | } |
---|
| 214 | |
---|
[86] | 215 | /** |
---|
| 216 | * @return the id |
---|
| 217 | */ |
---|
| 218 | @ParamAnnotation |
---|
| 219 | public String getId() { |
---|
| 220 | return id; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | @ParamAnnotation |
---|
[85] | 224 | public ParamBuilder group(Integer group) { |
---|
[77] | 225 | this.group = group; |
---|
| 226 | return this; |
---|
| 227 | } |
---|
| 228 | |
---|
[86] | 229 | @ParamAnnotation |
---|
[96] | 230 | public ParamBuilder flags(int flags) { |
---|
[77] | 231 | this.flags = flags; |
---|
| 232 | return this; |
---|
| 233 | } |
---|
| 234 | |
---|
[86] | 235 | @ParamAnnotation |
---|
[85] | 236 | public ParamBuilder name(String name) { |
---|
[77] | 237 | this.name = name; |
---|
| 238 | return this; |
---|
| 239 | } |
---|
| 240 | |
---|
[90] | 241 | protected <T extends Number> void parseMinMaxDefNumber(Class<T> type, String second, String third, String fourth) { |
---|
[84] | 242 | if (second != null) { |
---|
[87] | 243 | min = second; |
---|
[84] | 244 | } |
---|
| 245 | if (third != null) { |
---|
[87] | 246 | max = third; |
---|
[84] | 247 | } |
---|
[90] | 248 | if (fourth != null) { |
---|
| 249 | def = fourth; |
---|
| 250 | } |
---|
[84] | 251 | } |
---|
| 252 | |
---|
[87] | 253 | protected List<String> enumValues; |
---|
| 254 | |
---|
| 255 | public ParamBuilder enums(List<String> values) { |
---|
| 256 | enumValues = values; |
---|
| 257 | return type(EnumParam.class); |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | protected String uid; |
---|
| 261 | |
---|
[86] | 262 | @ParamAnnotation |
---|
[85] | 263 | public ParamBuilder type(String type) { |
---|
[87] | 264 | // typeString = type; |
---|
[88] | 265 | assert type != null; |
---|
[77] | 266 | |
---|
[84] | 267 | log.trace("parsing type: " + type); |
---|
[77] | 268 | |
---|
| 269 | String[] typeSplitted = type.split(" "); |
---|
| 270 | String first = typeSplitted[0]; |
---|
| 271 | String second = typeSplitted.length > 1 ? typeSplitted[1] : null; |
---|
| 272 | String third = typeSplitted.length > 2 ? typeSplitted[2] : null; |
---|
[90] | 273 | String fourth = typeSplitted.length > 3 ? typeSplitted[3] : null; |
---|
[77] | 274 | |
---|
| 275 | switch (first.charAt(0)) { |
---|
| 276 | case 'o': { |
---|
[87] | 277 | containedTypeName = second != null ? second : first.substring(1); |
---|
| 278 | type(ObjectParam.class); |
---|
[77] | 279 | break; |
---|
| 280 | } |
---|
| 281 | case 'p': { |
---|
[87] | 282 | type(ProcedureParam.class); |
---|
[90] | 283 | signature(type.substring(1)); |
---|
[77] | 284 | break; |
---|
| 285 | } |
---|
| 286 | case 'd': { |
---|
| 287 | |
---|
| 288 | int tildeIndex = type.indexOf("~"); |
---|
| 289 | if (tildeIndex != -1) { |
---|
[87] | 290 | enums(Arrays.asList(type.substring(tildeIndex + 1).split("~"))); |
---|
[77] | 291 | } else { |
---|
| 292 | if (first.length() >= 2) { |
---|
[85] | 293 | switch (first.charAt(1)) { |
---|
[77] | 294 | case 'b': { |
---|
[85] | 295 | type(BinaryParam.class); |
---|
[77] | 296 | break; |
---|
| 297 | } |
---|
| 298 | case 'c': { |
---|
[85] | 299 | type(ColorParam.class); |
---|
[77] | 300 | break; |
---|
| 301 | } |
---|
[85] | 302 | default: { |
---|
| 303 | log.error("unknown type: " + first); |
---|
| 304 | return this; |
---|
| 305 | } |
---|
[77] | 306 | } |
---|
| 307 | } |
---|
[84] | 308 | if ("0".equals(second) && "1".equals(third)) { |
---|
[85] | 309 | type(BooleanParam.class); |
---|
[84] | 310 | } |
---|
[87] | 311 | if (paramType == null) { |
---|
[85] | 312 | type(DecimalParam.class); |
---|
[77] | 313 | } |
---|
| 314 | } |
---|
[87] | 315 | if (DecimalParam.class.isAssignableFrom(this.paramType)) { |
---|
[90] | 316 | parseMinMaxDefNumber(Integer.class, second, third, fourth); |
---|
[77] | 317 | } |
---|
| 318 | break; |
---|
| 319 | } |
---|
| 320 | case 'f': { |
---|
[85] | 321 | type(FloatParam.class); |
---|
[90] | 322 | parseMinMaxDefNumber(Double.class, second, third, fourth); |
---|
[77] | 323 | break; |
---|
| 324 | } |
---|
| 325 | case 'x': { |
---|
[85] | 326 | type(UniversalParam.class); |
---|
[77] | 327 | break; |
---|
| 328 | } |
---|
| 329 | case 's': { |
---|
[85] | 330 | type(StringParam.class); |
---|
| 331 | min(second); |
---|
| 332 | max(third); |
---|
[77] | 333 | break; |
---|
| 334 | } |
---|
| 335 | case 'e': { |
---|
[85] | 336 | type(EventParam.class); |
---|
[99] | 337 | eventArgumentTypeName(second); |
---|
| 338 | break; |
---|
| 339 | } |
---|
| 340 | case 'l': { |
---|
| 341 | containedTypeName = second; |
---|
| 342 | if (third != null) { |
---|
| 343 | type(UniqueListParam.class); |
---|
| 344 | uid = third; |
---|
| 345 | } else { |
---|
| 346 | type(ArrayListParam.class); |
---|
[77] | 347 | } |
---|
[99] | 348 | break; |
---|
[77] | 349 | } |
---|
[99] | 350 | default: { |
---|
| 351 | log.error("unknown type: " + first); |
---|
| 352 | return this; |
---|
| 353 | } |
---|
| 354 | } |
---|
[77] | 355 | return this; |
---|
| 356 | } |
---|
| 357 | |
---|
[99] | 358 | public ParamBuilder eventArgumentTypeName(String eventArgumentTypeName) { |
---|
| 359 | this.eventArgumentTypeName = eventArgumentTypeName; |
---|
| 360 | return this; |
---|
| 361 | } |
---|
| 362 | |
---|
[86] | 363 | @ParamAnnotation |
---|
[85] | 364 | public ParamBuilder help(String help) { |
---|
[77] | 365 | this.help = help; |
---|
| 366 | return this; |
---|
| 367 | } |
---|
| 368 | |
---|
[84] | 369 | /** |
---|
[86] | 370 | * @return the group |
---|
| 371 | */ |
---|
| 372 | @ParamAnnotation |
---|
| 373 | public Integer getGroup() { |
---|
| 374 | return group; |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | /** |
---|
| 378 | * @return the flags |
---|
| 379 | */ |
---|
| 380 | @ParamAnnotation |
---|
[96] | 381 | public int getFlags() { |
---|
[86] | 382 | return flags; |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | /** |
---|
| 386 | * @return the name |
---|
| 387 | */ |
---|
| 388 | @ParamAnnotation |
---|
| 389 | public String getName() { |
---|
| 390 | return name; |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | /** |
---|
| 394 | * @return the help |
---|
| 395 | */ |
---|
| 396 | @ParamAnnotation |
---|
| 397 | public String getHelp() { |
---|
| 398 | return help; |
---|
| 399 | } |
---|
| 400 | |
---|
| 401 | @ParamAnnotation |
---|
| 402 | public String getType() { |
---|
[87] | 403 | return "?"; |
---|
[86] | 404 | } |
---|
| 405 | |
---|
[88] | 406 | @ParamAnnotation(id = "xtra") |
---|
[96] | 407 | public int getExtra() { |
---|
[88] | 408 | return extra; |
---|
| 409 | } |
---|
| 410 | |
---|
[86] | 411 | /** |
---|
[84] | 412 | * @return the paramType |
---|
| 413 | */ |
---|
| 414 | public Class<? extends Param> getParamType() { |
---|
| 415 | return paramType; |
---|
| 416 | } |
---|
| 417 | |
---|
[88] | 418 | @ParamAnnotation(id = "xtra") |
---|
[96] | 419 | public ParamBuilder extra(int extra) { |
---|
[88] | 420 | this.extra = extra; |
---|
| 421 | return this; |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | @ParamAnnotation |
---|
[87] | 425 | public ParamBuilder min(Object min) { |
---|
| 426 | this.min = min; |
---|
[77] | 427 | return this; |
---|
| 428 | } |
---|
| 429 | |
---|
[88] | 430 | @ParamAnnotation |
---|
[87] | 431 | public ParamBuilder max(Object max) { |
---|
| 432 | this.max = max; |
---|
[77] | 433 | return this; |
---|
| 434 | } |
---|
| 435 | |
---|
[88] | 436 | @ParamAnnotation |
---|
[87] | 437 | public ParamBuilder def(Object def) { |
---|
| 438 | this.def = def; |
---|
[77] | 439 | return this; |
---|
| 440 | } |
---|
| 441 | |
---|
[84] | 442 | |
---|
[77] | 443 | public Param build(String line) throws Exception { |
---|
| 444 | String[] paramEntryValues = line.split(","); |
---|
| 445 | |
---|
| 446 | if (paramEntryValues.length == 0) { |
---|
[84] | 447 | log.warn("field empty or wrong format (" + line |
---|
[77] | 448 | + ") - omitting"); |
---|
| 449 | return null; |
---|
| 450 | } |
---|
| 451 | |
---|
| 452 | for (int i = 0; i < paramEntryValues.length; ++i) { |
---|
| 453 | paramEntryValues[i] = paramEntryValues[i].trim(); |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | try { |
---|
[85] | 457 | id(paramEntryValues[0]); |
---|
| 458 | group(Integer.valueOf(paramEntryValues[1])); |
---|
[99] | 459 | flags(FlagsUtil.read(ParamFlags.class, paramEntryValues[2])); |
---|
[85] | 460 | name(paramEntryValues[3]); |
---|
| 461 | type(paramEntryValues[4]); |
---|
| 462 | help(paramEntryValues[6]); |
---|
[77] | 463 | } catch (IndexOutOfBoundsException e) { |
---|
| 464 | /** everything is ok, parameters have just finished*/ |
---|
| 465 | } catch (NumberFormatException ex) { |
---|
[84] | 466 | log.warn("wrong format of entry: " + line |
---|
[77] | 467 | + ", omitting"); |
---|
| 468 | return null; |
---|
| 469 | } |
---|
[85] | 470 | return finish(); |
---|
[77] | 471 | } |
---|
| 472 | |
---|
| 473 | public void setField(String key, String value) { |
---|
[85] | 474 | switch (key) { |
---|
| 475 | case ID_FIELD: |
---|
| 476 | id(value); |
---|
| 477 | break; |
---|
| 478 | case NAME_FIELD: |
---|
| 479 | name(value); |
---|
| 480 | break; |
---|
| 481 | case TYPE_FIELD: |
---|
| 482 | type(value); |
---|
| 483 | break; |
---|
| 484 | case FLAGS_FIELD: |
---|
[99] | 485 | flags(FlagsUtil.read(ParamFlags.class, value)); |
---|
[85] | 486 | break; |
---|
| 487 | case HELP_FIELD: |
---|
| 488 | help(value); |
---|
| 489 | break; |
---|
| 490 | case GROUP_FIELD: |
---|
| 491 | group(Integer.valueOf(value)); |
---|
| 492 | break; |
---|
| 493 | default: |
---|
| 494 | log.error("unknown field for Param: " + key); |
---|
| 495 | break; |
---|
[77] | 496 | } |
---|
| 497 | } |
---|
| 498 | |
---|
[88] | 499 | public ParamBuilder fillDef(Object def) { |
---|
[87] | 500 | if (this.def == null) { |
---|
| 501 | return def(def); |
---|
| 502 | } |
---|
| 503 | return this; |
---|
| 504 | } |
---|
[77] | 505 | |
---|
[88] | 506 | public ParamBuilder fillStorageType(Class<?> storageType) { |
---|
| 507 | if (this.storageType == null) { |
---|
| 508 | this.storageType = storageType; |
---|
| 509 | } |
---|
| 510 | return this; |
---|
| 511 | } |
---|
| 512 | |
---|
[99] | 513 | /** |
---|
| 514 | * @return the eventArgumentTypeName |
---|
| 515 | */ |
---|
| 516 | public String getEventArgumentTypeName() { |
---|
| 517 | return eventArgumentTypeName; |
---|
| 518 | } |
---|
| 519 | |
---|
[88] | 520 | public Class<?> getStorageType() { |
---|
| 521 | return storageType; |
---|
| 522 | } |
---|
[90] | 523 | |
---|
| 524 | protected static ValueParam parseProcedureTypePart(String type, String name) { |
---|
| 525 | return Param.build().type(type).name(name).id(name).finish(ValueParam.class); |
---|
| 526 | } |
---|
| 527 | |
---|
[97] | 528 | private static Pattern signaturePattern = Pattern.compile("^([^\\(]+)?\\(([^\\)]*)\\)$"); |
---|
[90] | 529 | |
---|
| 530 | public ParamBuilder signature(String signature) { |
---|
| 531 | argumentsType = new ArrayList<>(); |
---|
| 532 | |
---|
| 533 | if (!Strings.notEmpty(signature)) { |
---|
| 534 | resultType = null; |
---|
| 535 | return this; |
---|
| 536 | } |
---|
[97] | 537 | Matcher matcher = signaturePattern.matcher(signature); |
---|
[90] | 538 | if (!matcher.matches()) { |
---|
| 539 | throw new FramsticksException().msg("invalid signature"); |
---|
| 540 | } |
---|
| 541 | String result = Strings.collapse(matcher.group(1)); |
---|
[96] | 542 | if (result != null) { |
---|
| 543 | resultType = Param.build().type(result).finish(ValueParam.class); |
---|
| 544 | } else { |
---|
| 545 | resultType = null; |
---|
| 546 | } |
---|
[90] | 547 | String arguments = matcher.group(2); |
---|
| 548 | if (!Strings.notEmpty(arguments)) { |
---|
| 549 | return this; |
---|
| 550 | } |
---|
| 551 | int number = 0; |
---|
| 552 | for (String a : arguments.split(",")) { |
---|
[96] | 553 | ParamBuilder arg = Param.build(); |
---|
| 554 | |
---|
[90] | 555 | int space = a.indexOf(' '); |
---|
| 556 | if (space == -1) { |
---|
[96] | 557 | arg.type(a).id("arg" + number); |
---|
[90] | 558 | } else { |
---|
[96] | 559 | String name = a.substring(space + 1); |
---|
| 560 | arg.type(a.substring(0, space)).id(name).name(name); |
---|
[90] | 561 | } |
---|
[96] | 562 | argumentsType.add(arg.finish(ValueParam.class)); |
---|
[90] | 563 | ++number; |
---|
| 564 | } |
---|
| 565 | return this; |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | |
---|
| 569 | public ParamBuilder idAndName(String name) { |
---|
| 570 | id(name); |
---|
| 571 | name(name); |
---|
| 572 | return this; |
---|
| 573 | } |
---|
[96] | 574 | |
---|
| 575 | @Override |
---|
| 576 | public String toString() { |
---|
| 577 | return "ParamBuilder for " + Misc.returnNotNull(id, "<not yet known>"); |
---|
| 578 | } |
---|
[77] | 579 | } |
---|
[88] | 580 | |
---|