Mercurial Hosting > luan
comparison core/src/luan/LuanJavaFunction.java @ 408:1b38de2b1845
merge LuanTableImpl into LuanTable
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 29 Apr 2015 13:15:17 -0600 |
parents | ba8b0aae6453 |
children | 3ffe8ba5b297 |
comparison
equal
deleted
inserted
replaced
407:7fd9f1b7b878 | 408:1b38de2b1845 |
---|---|
199 return null; | 199 return null; |
200 Object[] a = new Object[Array.getLength(obj)]; | 200 Object[] a = new Object[Array.getLength(obj)]; |
201 for( int i=0; i<a.length; i++ ) { | 201 for( int i=0; i<a.length; i++ ) { |
202 a[i] = Array.get(obj,i); | 202 a[i] = Array.get(obj,i); |
203 } | 203 } |
204 return new LuanTableImpl(new ArrayList<Object>(Arrays.asList(a))); | 204 return new LuanTable(new ArrayList<Object>(Arrays.asList(a))); |
205 } | 205 } |
206 }; | 206 }; |
207 | 207 |
208 private static RtnConverter getRtnConverter(JavaMethod m) { | 208 private static RtnConverter getRtnConverter(JavaMethod m) { |
209 Class<?> rtnType = m.getReturnType(); | 209 Class<?> rtnType = m.getReturnType(); |
395 if( obj == null ) | 395 if( obj == null ) |
396 return null; | 396 return null; |
397 if( obj instanceof List ) { | 397 if( obj instanceof List ) { |
398 @SuppressWarnings("unchecked") | 398 @SuppressWarnings("unchecked") |
399 List<Object> list = (List<Object>)obj; | 399 List<Object> list = (List<Object>)obj; |
400 return new LuanTableImpl(list); | 400 return new LuanTable(list); |
401 } | 401 } |
402 if( obj instanceof Map ) { | 402 if( obj instanceof Map ) { |
403 @SuppressWarnings("unchecked") | 403 @SuppressWarnings("unchecked") |
404 Map<Object,Object> map = (Map<Object,Object>)obj; | 404 Map<Object,Object> map = (Map<Object,Object>)obj; |
405 return new LuanTableImpl(map); | 405 return new LuanTable(map); |
406 } | 406 } |
407 if( obj instanceof Set ) { | 407 if( obj instanceof Set ) { |
408 @SuppressWarnings("unchecked") | 408 @SuppressWarnings("unchecked") |
409 Set<Object> set = (Set<Object>)obj; | 409 Set<Object> set = (Set<Object>)obj; |
410 return new LuanTableImpl(set); | 410 return new LuanTable(set); |
411 } | 411 } |
412 Class cls = obj.getClass(); | 412 Class cls = obj.getClass(); |
413 if( cls.isArray() && !cls.getComponentType().isPrimitive() ) { | 413 if( cls.isArray() && !cls.getComponentType().isPrimitive() ) { |
414 Object[] a = (Object[])obj; | 414 Object[] a = (Object[])obj; |
415 return new LuanTableImpl(Arrays.asList(a)); | 415 return new LuanTable(Arrays.asList(a)); |
416 } | 416 } |
417 return obj; | 417 return obj; |
418 } | 418 } |
419 @Override public String toString() { | 419 @Override public String toString() { |
420 return "ARG_TABLE"; | 420 return "ARG_TABLE"; |
421 } | 421 } |
422 }; | 422 }; |
423 | 423 |
424 private static final ArgConverter ARG_MAP = new ArgConverter() { | 424 private static final ArgConverter ARG_MAP = new ArgConverter() { |
425 public Object convert(Object obj) { | 425 public Object convert(Object obj) { |
426 if( obj instanceof LuanTableImpl ) { | 426 if( obj instanceof LuanTable ) { |
427 LuanTableImpl t = (LuanTableImpl)obj; | 427 LuanTable t = (LuanTable)obj; |
428 return t.asMap(); | 428 return t.asMap(); |
429 } | 429 } |
430 return obj; | 430 return obj; |
431 } | 431 } |
432 @Override public String toString() { | 432 @Override public String toString() { |
434 } | 434 } |
435 }; | 435 }; |
436 | 436 |
437 private static final ArgConverter ARG_LIST = new ArgConverter() { | 437 private static final ArgConverter ARG_LIST = new ArgConverter() { |
438 public Object convert(Object obj) { | 438 public Object convert(Object obj) { |
439 if( obj instanceof LuanTableImpl ) { | 439 if( obj instanceof LuanTable ) { |
440 LuanTableImpl t = (LuanTableImpl)obj; | 440 LuanTable t = (LuanTable)obj; |
441 if( t.isList() ) | 441 if( t.isList() ) |
442 return t.asList(); | 442 return t.asList(); |
443 } | 443 } |
444 return obj; | 444 return obj; |
445 } | 445 } |
448 } | 448 } |
449 }; | 449 }; |
450 | 450 |
451 private static final ArgConverter ARG_SET = new ArgConverter() { | 451 private static final ArgConverter ARG_SET = new ArgConverter() { |
452 public Object convert(Object obj) { | 452 public Object convert(Object obj) { |
453 if( obj instanceof LuanTableImpl ) { | 453 if( obj instanceof LuanTable ) { |
454 LuanTableImpl t = (LuanTableImpl)obj; | 454 LuanTable t = (LuanTable)obj; |
455 if( t.isSet() ) | 455 if( t.isSet() ) |
456 return t.asSet(); | 456 return t.asSet(); |
457 } | 457 } |
458 return obj; | 458 return obj; |
459 } | 459 } |
462 } | 462 } |
463 }; | 463 }; |
464 | 464 |
465 private static final ArgConverter ARG_COLLECTION = new ArgConverter() { | 465 private static final ArgConverter ARG_COLLECTION = new ArgConverter() { |
466 public Object convert(Object obj) { | 466 public Object convert(Object obj) { |
467 if( obj instanceof LuanTableImpl ) { | 467 if( obj instanceof LuanTable ) { |
468 LuanTableImpl t = (LuanTableImpl)obj; | 468 LuanTable t = (LuanTable)obj; |
469 if( t.isList() ) | 469 if( t.isList() ) |
470 return t.asList(); | 470 return t.asList(); |
471 if( t.isSet() ) | 471 if( t.isSet() ) |
472 return t.asSet(); | 472 return t.asSet(); |
473 } | 473 } |
484 ArgArray(Class cls) { | 484 ArgArray(Class cls) { |
485 a = (Object[])Array.newInstance(cls.getComponentType(),0); | 485 a = (Object[])Array.newInstance(cls.getComponentType(),0); |
486 } | 486 } |
487 | 487 |
488 public Object convert(Object obj) { | 488 public Object convert(Object obj) { |
489 if( obj instanceof LuanTableImpl ) { | 489 if( obj instanceof LuanTable ) { |
490 LuanTableImpl t = (LuanTableImpl)obj; | 490 LuanTable t = (LuanTable)obj; |
491 if( t.isList() ) { | 491 if( t.isList() ) { |
492 try { | 492 try { |
493 return t.asList().toArray(a); | 493 return t.asList().toArray(a); |
494 } catch(ArrayStoreException e) {} | 494 } catch(ArrayStoreException e) {} |
495 } | 495 } |