@@ -106,6 +106,8 @@ -(NSMethodSignature*)methodSignatureForSelector:(SEL)sel
106
106
107
107
-(void )forwardInvocation : (NSInvocation *)invocation
108
108
{
109
+ NSLog (@" forwardInvocation: %@ " , invocation);
110
+
109
111
JNIEnv *env=0 ;
110
112
SEL aSelector = [invocation selector ];
111
113
int attach = (*jvm)->AttachCurrentThread (jvm, (void **)&env, NULL );
@@ -160,7 +162,7 @@ -(jobject)javaPeer
160
162
}
161
163
}
162
164
163
- + (NSSet <NSString *> *)keyPathsForValuesAffectingValueForKey : (NSString *)key {
165
+ // + (NSSet<NSString *> *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
164
166
// SEL theSelector = @selector(keyPathsForValuesAffectingValueForKey:);
165
167
// NSMethodSignature *aSignature = [NSObject methodSignatureForSelector:theSelector];
166
168
// NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature:aSignature];
@@ -177,8 +179,55 @@ -(jobject)javaPeer
177
179
// return result;
178
180
179
181
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;
182
231
}
183
232
184
233
@end
0 commit comments