2424import java .util .List ;
2525import java .util .Locale ;
2626import java .util .Map ;
27+ import org .mozilla .javascript .lc .type .TypeInfo ;
28+ import org .mozilla .javascript .lc .type .TypeInfoFactory ;
2729
2830/**
2931 * @author Mike Shaver
@@ -102,7 +104,7 @@ Object get(Scriptable scope, String name, Object javaObject, boolean isStatic) {
102104 BeanProperty bp = (BeanProperty ) member ;
103105 if (bp .getter == null ) return Scriptable .NOT_FOUND ;
104106 rval = bp .getter .invoke (javaObject , ScriptRuntime .emptyArgs );
105- type = bp .getter .method ().getReturnType ();
107+ type = bp .getter .getReturnType ().asClass ();
106108 } else {
107109 Field field = (Field ) member ;
108110 rval = field .get (isStatic ? null : javaObject );
@@ -139,7 +141,7 @@ void put(Scriptable scope, String name, Object javaObject, Object value, boolean
139141 // main setter. Otherwise, let the NativeJavaMethod decide which
140142 // setter to use:
141143 if (bp .setters == null || value == null ) {
142- Class <?> setType = bp .setter .argTypes [ 0 ] ;
144+ var setType = bp .setter .getArgTypes (). get ( 0 ) ;
143145 Object [] args = {Context .jsToJava (value , setType )};
144146 try {
145147 bp .setter .invoke (javaObject , args );
@@ -209,21 +211,24 @@ static String javaSignature(Class<?> type) {
209211 return sb .toString ();
210212 }
211213
212- static String liveConnectSignature (Class <?>[] argTypes ) {
213- int N = argTypes .length ;
214- if (N == 0 ) {
214+ static String liveConnectSignature (List <TypeInfo > argTypes ) {
215+ if (argTypes .isEmpty ()) {
215216 return "()" ;
216217 }
217- StringBuilder sb = new StringBuilder ();
218- sb .append ('(' );
219- for (int i = 0 ; i != N ; ++i ) {
220- if (i != 0 ) {
221- sb .append (',' );
218+
219+ var builder = new StringBuilder ();
220+
221+ builder .append ('(' );
222+ var iter = argTypes .iterator ();
223+ if (iter .hasNext ()) {
224+ builder .append (javaSignature (iter .next ().asClass ()));
225+ while (iter .hasNext ()) {
226+ builder .append (',' ).append (javaSignature (iter .next ().asClass ()));
222227 }
223- sb .append (javaSignature (argTypes [i ]));
224228 }
225- sb .append (')' );
226- return sb .toString ();
229+ builder .append (')' );
230+
231+ return builder .toString ();
227232 }
228233
229234 private MemberBox findExplicitFunction (String name , boolean isStatic ) {
@@ -255,8 +260,7 @@ private MemberBox findExplicitFunction(String name, boolean isStatic) {
255260
256261 if (methodsOrCtors != null ) {
257262 for (MemberBox methodsOrCtor : methodsOrCtors ) {
258- Class <?>[] type = methodsOrCtor .argTypes ;
259- String sig = liveConnectSignature (type );
263+ String sig = liveConnectSignature (methodsOrCtor .getArgTypes ());
260264 if (sigStart + sig .length () == name .length ()
261265 && name .regionMatches (sigStart , sig , 0 , sig .length ())) {
262266 return methodsOrCtor ;
@@ -433,6 +437,7 @@ private void reflect(
433437 // We reflect methods first, because we want overloaded field/method
434438 // names to be allocated to the NativeJavaMethod before the field
435439 // gets in the way.
440+ var typeFactory = TypeInfoFactory .get (scope );
436441
437442 Method [] methods = discoverAccessibleMethods (cl , includeProtected , includePrivate );
438443 for (Method method : methods ) {
@@ -469,15 +474,15 @@ private void reflect(
469474 Object value = entry .getValue ();
470475 if (value instanceof Method ) {
471476 methodBoxes = new MemberBox [1 ];
472- methodBoxes [0 ] = new MemberBox ((Method ) value );
477+ methodBoxes [0 ] = new MemberBox ((Method ) value , typeFactory );
473478 } else {
474479 ArrayList <Object > overloadedMethods = (ArrayList <Object >) value ;
475480 int N = overloadedMethods .size ();
476481 if (N < 2 ) Kit .codeBug ();
477482 methodBoxes = new MemberBox [N ];
478483 for (int i = 0 ; i != N ; ++i ) {
479484 Method method = (Method ) overloadedMethods .get (i );
480- methodBoxes [i ] = new MemberBox (method );
485+ methodBoxes [i ] = new MemberBox (method , typeFactory );
481486 }
482487 }
483488 NativeJavaMethod fun = new NativeJavaMethod (methodBoxes );
@@ -609,7 +614,7 @@ private void reflect(
609614 if (getter != null ) {
610615 // We have a getter. Now, do we have a matching
611616 // setter?
612- Class <?> type = getter . method () .getReturnType ();
617+ var type = getter .getReturnType ();
613618 setter = extractSetMethod (type , njmSet .methods , isStatic );
614619 } else {
615620 // No getter, find any set method
@@ -633,7 +638,7 @@ private void reflect(
633638 Constructor <?>[] constructors = getAccessibleConstructors (includePrivate );
634639 MemberBox [] ctorMembers = new MemberBox [constructors .length ];
635640 for (int i = 0 ; i != constructors .length ; ++i ) {
636- ctorMembers [i ] = new MemberBox (constructors [i ]);
641+ ctorMembers [i ] = new MemberBox (constructors [i ], typeFactory );
637642 }
638643 ctors = new NativeJavaMethod (ctorMembers , cl .getSimpleName ());
639644 }
@@ -708,9 +713,9 @@ private static MemberBox extractGetMethod(MemberBox[] methods, boolean isStatic)
708713 for (MemberBox method : methods ) {
709714 // Does getter method have an empty parameter list with a return
710715 // value (eg. a getSomething() or isSomething())?
711- if (method .argTypes . length == 0 && (!isStatic || method .isStatic ())) {
712- Class <?> type = method . method () .getReturnType ();
713- if (type != Void . TYPE ) {
716+ if (method .getArgTypes (). isEmpty () && (!isStatic || method .isStatic ())) {
717+ var type = method .getReturnType ();
718+ if (! type . isVoid () ) {
714719 return method ;
715720 }
716721 break ;
@@ -720,7 +725,7 @@ private static MemberBox extractGetMethod(MemberBox[] methods, boolean isStatic)
720725 }
721726
722727 private static MemberBox extractSetMethod (
723- Class <?> type , MemberBox [] methods , boolean isStatic ) {
728+ TypeInfo type , MemberBox [] methods , boolean isStatic ) {
724729 //
725730 // Note: it may be preferable to allow NativeJavaMethod.findFunction()
726731 // to find the appropriate setter; unfortunately, it requires an
@@ -730,13 +735,14 @@ private static MemberBox extractSetMethod(
730735 MemberBox acceptableMatch = null ;
731736 for (MemberBox method : methods ) {
732737 if (!isStatic || method .isStatic ()) {
733- Class <?>[] params = method .argTypes ;
734- if (params . length == 1 ) {
735- if (params [ 0 ] == type ) {
738+ var argTypes = method .getArgTypes () ;
739+ if (argTypes . size () == 1 ) {
740+ if (type . is ( argTypes . get ( 0 ). asClass ()) ) {
736741 // perfect match, no need to continue scanning
737742 return method ;
738743 }
739- if (acceptableMatch == null && params [0 ].isAssignableFrom (type )) {
744+ if (acceptableMatch == null
745+ && argTypes .get (0 ).asClass ().isAssignableFrom (type .asClass ())) {
740746 // do not return at this point, there can still be perfect match
741747 acceptableMatch = method ;
742748 }
@@ -750,8 +756,8 @@ private static MemberBox extractSetMethod(MemberBox[] methods, boolean isStatic)
750756
751757 for (MemberBox method : methods ) {
752758 if (!isStatic || method .isStatic ()) {
753- if (method .method ().getReturnType () == Void . TYPE ) {
754- if (method .argTypes . length == 1 ) {
759+ if (method .getReturnType ().isVoid () ) {
760+ if (method .getArgTypes (). size () == 1 ) {
755761 return method ;
756762 }
757763 }
0 commit comments