@@ -106,6 +106,8 @@ -(NSMethodSignature*)methodSignatureForSelector:(SEL)sel
106106
107107-(void )forwardInvocation : (NSInvocation *)invocation
108108{
109+ NSLog (@" forwardInvocation: %@ " , invocation);
110+
109111 JNIEnv *env=0 ;
110112 SEL aSelector = [invocation selector ];
111113 int attach = (*jvm)->AttachCurrentThread (jvm, (void **)&env, NULL );
@@ -160,7 +162,7 @@ -(jobject)javaPeer
160162 }
161163}
162164
163- + (NSSet <NSString *> *)keyPathsForValuesAffectingValueForKey : (NSString *)key {
165+ // + (NSSet<NSString *> *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
164166// SEL theSelector = @selector(keyPathsForValuesAffectingValueForKey:);
165167// NSMethodSignature *aSignature = [NSObject methodSignatureForSelector:theSelector];
166168// NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature:aSignature];
@@ -177,8 +179,55 @@ -(jobject)javaPeer
177179// return result;
178180
179181
180- NSSet *keyPaths = [[NSSet alloc ] initWithObjects: key];
181- return keyPaths;
182+ // return [NSSet set];
183+ // }
184+
185+ - (id )valueForKey : (NSString *)key {
186+ NSLog (@" Calling valueForKey: %@ " , key);
187+ SEL aSelector = @selector (valueForKey: );
188+ return [self forwardInvocationForSelector: aSelector withTarget: nil withArguments: &key, nil ];
189+ }
190+
191+ - (id )valueForUndefinedKey : (NSString *)key {
192+ NSLog (@" Calling valueForUndefinedKey: %@ " , key);
193+ SEL aSelector = @selector (valueForUndefinedKey: );
194+ return [self forwardInvocationForSelector: aSelector withTarget: nil withArguments: &key, nil ];
195+ }
196+
197+ - (id )forwardInvocationForSelector : (SEL )aSelector withTarget : (id _Nullable)aTarget withArguments : (id * _Nullable)args , ... NS_REQUIRES_NIL_TERMINATION {
198+
199+ NSString * sel = NSStringFromSelector (aSelector);
200+ NSLog (@" Forwarding selector: %@ " , sel);
201+
202+ NSMethodSignature *aSignature = [self methodSignatureForSelector: aSelector];
203+ NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: aSignature];
204+
205+ [anInvocation setTarget: aTarget];
206+ [anInvocation setSelector: aSelector];
207+
208+ va_list varArgs;
209+ va_start (varArgs, args);
210+
211+ NSLog (@" Settings arguments for selector: %@ " , sel);
212+ int i = 2 ;
213+ for (id *arg = args; arg != nil ; arg = va_arg (varArgs, id *)) {
214+ NSLog (@" Settings argument %d to: %p " , i, arg);
215+ [anInvocation setArgument: &arg atIndex: i];
216+ i++;
217+ }
218+
219+ NSLog (@" Forwarding selector to java object: %@ " , sel);
220+ [self forwardInvocation: anInvocation];
221+
222+ NSUInteger length = [[anInvocation methodSignature ] methodReturnLength ];
223+ void *result = (void *)malloc (length);
224+
225+ NSLog (@" Getting return value for selector: %@ " , sel);
226+ [anInvocation getReturnValue: result];
227+
228+ va_end (varArgs);
229+
230+ return result;
182231}
183232
184233@end
0 commit comments