2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #import <objc/objc-api.h>
26 #import <objc/Protocol.h>
28 #if NeXT_RUNTIME || APPLE_RUNTIME
29 # import <objc/objc.h>
30 # import <objc/objc-class.h>
32 # import <objc/encoding.h>
35 @implementation NSObject(Reflection)
37 + (void)_addSelectorsOfClassToArray:(NSMutableSet *)_sels {
41 for (methods = ((Class)self)->methods; methods;
42 methods = methods->method_next) {
45 for (i = 0; i < methods->method_count; i++) {
46 Method_t internalMethod;
50 internalMethod = &(methods->method_list[i]);
51 sel = internalMethod->method_name;
52 selName = NSStringFromSelector(sel);
54 if ([selName length] == 0) {
55 NSLog(@"WARNING(%s): did not get selector for method 0x%08X",
56 __PRETTY_FUNCTION__, internalMethod);
60 [_sels addObject:selName];
64 struct objc_method_list *mlist;
65 void *iterator = NULL;
67 //NSLog(@"adding selectors of class: %@", NSStringFromClass(self));
69 while ((mlist = class_nextMethodList(self, &iterator)) != NULL) {
72 //NSLog(@" processing %i selectors ...", mlist->method_count);
74 for (mcount = mlist->method_count; mcount > 0; mcount--) {
78 if ((sel = mlist->method_list[mcount - 1].method_name) == NULL)
81 selName = NSStringFromSelector(sel);
82 if ([selName length] == 0) {
83 NSLog(@"WARNING(%s): did not get selector for method 0x%08X",
84 __PRETTY_FUNCTION__, mlist->method_list[mcount - 1]);
87 [_sels addObject:selName];
93 + (NSArray *)classImplementsSelectors {
96 a = [[[NSMutableSet alloc] initWithCapacity:32] autorelease];
97 [self _addSelectorsOfClassToArray:a];
98 return [a allObjects];
101 + (NSArray *)instancesRespondToSelectors {
105 a = [NSMutableSet setWithCapacity:128];
106 for (clazz = self; clazz; clazz = [clazz superclass])
107 [clazz _addSelectorsOfClassToArray:a];
108 return [a allObjects];
111 - (NSArray *)respondsToSelectors {
112 return [[self class] instancesRespondToSelectors];
115 @end /* NSObject(Reflection) */