2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #import <objc/objc-api.h>
25 #import <objc/Protocol.h>
27 #if NeXT_RUNTIME || APPLE_RUNTIME
28 # import <objc/objc.h>
29 # import <objc/objc-class.h>
31 # import <objc/encoding.h>
34 @implementation NSObject(Reflection)
36 + (void)_addSelectorsOfClassToArray:(NSMutableSet *)_sels {
40 for (methods = ((Class)self)->methods; methods;
41 methods = methods->method_next) {
44 for (i = 0; i < methods->method_count; i++) {
45 Method_t internalMethod;
49 internalMethod = &(methods->method_list[i]);
50 sel = internalMethod->method_name;
51 selName = NSStringFromSelector(sel);
53 if ([selName length] == 0) {
54 NSLog(@"WARNING(%s): did not get selector for method 0x%08X",
55 __PRETTY_FUNCTION__, internalMethod);
59 [_sels addObject:selName];
63 struct objc_method_list *mlist;
64 void *iterator = NULL;
66 //NSLog(@"adding selectors of class: %@", NSStringFromClass(self));
68 while ((mlist = class_nextMethodList(self, &iterator)) != NULL) {
71 //NSLog(@" processing %i selectors ...", mlist->method_count);
73 for (mcount = mlist->method_count; mcount > 0; mcount--) {
77 if ((sel = mlist->method_list[mcount - 1].method_name) == NULL)
80 selName = NSStringFromSelector(sel);
81 if ([selName length] == 0) {
82 NSLog(@"WARNING(%s): did not get selector for method 0x%08X",
83 __PRETTY_FUNCTION__, mlist->method_list[mcount - 1]);
86 [_sels addObject:selName];
92 + (NSArray *)classImplementsSelectors {
95 a = [[[NSMutableSet alloc] initWithCapacity:32] autorelease];
96 [self _addSelectorsOfClassToArray:a];
97 return [a allObjects];
100 + (NSArray *)instancesRespondToSelectors {
104 a = [NSMutableSet setWithCapacity:128];
105 for (clazz = self; clazz; clazz = [clazz superclass])
106 [clazz _addSelectorsOfClassToArray:a];
107 return [a allObjects];
110 - (NSArray *)respondsToSelectors {
111 return [[self class] instancesRespondToSelectors];
114 @end /* NSObject(Reflection) */