Changeset 12303
- Timestamp:
- 12/23/09 20:53:57 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/Java.java
r12302 r12303 449 449 LispObject classRef = args[0]; 450 450 try { 451 Constructor constructor = (Constructor) JavaObject.getObject(classRef); 451 Constructor constructor; 452 if(classRef instanceof AbstractString) { 453 constructor = findConstructor(javaClass(classRef), args); 454 } else { 455 constructor = (Constructor) JavaObject.getObject(classRef); 456 } 452 457 Class[] argTypes = constructor.getParameterTypes(); 453 458 Object[] initargs = new Object[args.length-1]; … … 677 682 } 678 683 679 private static Method findMethod(Class<?> c, String methodName, LispObject[] args) throws NoSuchMethodException { 680 int argCount = args.length - 2; 684 private static Object[] translateMethodArguments(LispObject[] args) { 685 return translateMethodArguments(args, 0); 686 } 687 688 private static Object[] translateMethodArguments(LispObject[] args, int offs) { 689 int argCount = args.length - offs; 681 690 Object[] javaArgs = new Object[argCount]; 682 691 for (int i = 0; i < argCount; ++i) { 683 Object x = args[i + 2];692 Object x = args[i + offs]; 684 693 if (x == NIL) { 685 694 javaArgs[i] = null; … … 688 697 } 689 698 } 699 return javaArgs; 700 } 701 702 private static Method findMethod(Class<?> c, String methodName, LispObject[] args) throws NoSuchMethodException { 703 int argCount = args.length - 2; 704 Object[] javaArgs = translateMethodArguments(args, 2); 690 705 Method[] methods = c.getMethods(); 691 706 Method result = null; … … 702 717 continue; 703 718 } 704 if (result == null || isMoreSpecialized(method , result)) {719 if (result == null || isMoreSpecialized(methodTypes, result.getParameterTypes())) { 705 720 result = method; 706 721 } … … 708 723 if (result == null) { 709 724 throw new NoSuchMethodException(methodName); 725 } 726 return result; 727 } 728 729 private static Constructor findConstructor(Class<?> c, LispObject[] args) throws NoSuchMethodException { 730 int argCount = args.length - 1; 731 Object[] javaArgs = translateMethodArguments(args, 1); 732 Constructor[] ctors = c.getConstructors(); 733 Constructor result = null; 734 for (int i = ctors.length; i-- > 0;) { 735 Constructor ctor = ctors[i]; 736 if (ctor.getParameterTypes().length != argCount) { 737 continue; 738 } 739 Class<?>[] methodTypes = (Class<?>[]) ctor.getParameterTypes(); 740 if (!isApplicableMethod(methodTypes, javaArgs)) { 741 continue; 742 } 743 if (result == null || isMoreSpecialized(methodTypes, result.getParameterTypes())) { 744 result = ctor; 745 } 746 } 747 if (result == null) { 748 throw new NoSuchMethodException(c.getSimpleName()); 710 749 } 711 750 return result; … … 729 768 } 730 769 731 private static boolean isMoreSpecialized(Method x, Method y) { 732 Class<?>[] xtypes = x.getParameterTypes(); 733 Class<?>[] ytypes = y.getParameterTypes(); 770 private static boolean isMoreSpecialized(Class<?>[] xtypes, Class<?>[] ytypes) { 734 771 for (int i = 0; i < xtypes.length; ++i) { 735 772 Class<?> xtype = xtypes[i];
Note: See TracChangeset
for help on using the changeset viewer.