/
Store.m
256 lines (205 loc) · 8.9 KB
/
Store.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//
// Store.m
// appledoc
//
// Created by Tomaž Kragelj on 3/19/12.
// Copyright (c) 2012 Tomaz Kragelj. All rights reserved.
//
#import "Objects.h"
#import "Store.h"
@interface Store ()
@property (nonatomic, strong) PKToken *currentSourceInfo;
@property (nonatomic, strong) NSMutableArray *registrationStack;
@end
#pragma mark -
@implementation Store
@synthesize currentSourceInfo = _currentSourceInfo;
@synthesize registrationStack = _registrationStack;
#pragma mark - StoreRegistrar and related stuff
- (BOOL)expectCurrentRegistrationObjectRespondTo:(SEL)selector {
if (self.registrationStack.count == 0) {
LogStoWarn(@"Expecting at least one object responding to %@ on registration stack!", NSStringFromSelector(selector));
return NO;
}
if (![self.currentRegistrationObject respondsToSelector:selector]) {
LogStoWarn(@"Current object %@ on registration stack doesn't respond to %@!", self.currentRegistrationObject, NSStringFromSelector(selector));
return NO;
}
return YES;
}
- (BOOL)doesCurrentRegistrationObjectRespondTo:(SEL)selector {
if (self.registrationStack.count == 0) return NO;
if (![self.currentRegistrationObject respondsToSelector:selector]) return NO;
return YES;
}
- (void)pushRegistrationObject:(id)object {
LogStoDebug(@"Pushing object %@ to registration stack...", object);
[self.registrationStack addObject:object];
}
- (id)popRegistrationObject {
id result = self.currentRegistrationObject;
[self.registrationStack removeLastObject];
return result;
}
- (id)currentRegistrationObject {
return [self.registrationStack lastObject];
}
- (NSMutableArray *)registrationStack {
if (_registrationStack) return _registrationStack;
LogStoDebug(@"Initializing registration stack due to first access...");
_registrationStack = [[NSMutableArray alloc] init];
return _registrationStack;
}
@end
#pragma mark -
@implementation Store (Registrations)
#pragma mark - Classes, categories and protocols handling
- (void)beginClassWithName:(NSString *)name derivedFromClassWithName:(NSString *)derived {
LogStoInfo(@"Starting class %@ derived from %@...", name, derived);
ClassInfo *info = [[ClassInfo alloc] initWithRegistrar:self];
info.nameOfClass = name;
info.nameOfSuperClass = derived;
[self pushRegistrationObject:info];
}
- (void)beginExtensionForClassWithName:(NSString *)name {
LogStoInfo(@"Starting class extenstion for class %@...", name);
CategoryInfo *info = [[CategoryInfo alloc] initWithRegistrar:self];
info.nameOfClass = name;
info.nameOfCategory = nil;
[self pushRegistrationObject:info];
}
- (void)beginCategoryWithName:(NSString *)category forClassWithName:(NSString *)name {
LogStoInfo(@"Starting category %@ for class %@...", category, name);
CategoryInfo *info = [[CategoryInfo alloc] initWithRegistrar:self];
info.nameOfClass = name;
info.nameOfCategory = category;
[self pushRegistrationObject:info];
}
- (void)beginProtocolWithName:(NSString *)name {
LogStoInfo(@"Starting protocol %@...", name);
ProtocolInfo *info = [[ProtocolInfo alloc] initWithRegistrar:self];
info.nameOfProtocol = name;
[self pushRegistrationObject:info];
}
- (void)appendAdoptedProtocolWithName:(NSString *)name {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding adopted protocol registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject appendAdoptedProtocolWithName:name];
}
#pragma mark - Method groups
- (void)appendMethodGroupWithDescription:(NSString *)description {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding method group description registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject appendMethodGroupWithDescription:description];
}
#pragma mark - Properties
- (void)beginPropertyDefinition {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding property definition registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject beginPropertyDefinition];
}
- (void)beginPropertyAttributes {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding property attributes registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject beginPropertyAttributes];
}
- (void)beginPropertyTypes {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding property types registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject beginPropertyTypes];
}
- (void)appendPropertyName:(NSString *)name {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding property name registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject appendPropertyName:name];
}
#pragma mark - Methods
- (void)beginMethodDefinitionWithType:(NSString *)type {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding method definition registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject beginMethodDefinitionWithType:type];
}
- (void)beginMethodResults {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding method results registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject beginMethodResults];
}
- (void)beginMethodArgument {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding method arguments registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject beginMethodArgument];
}
- (void)beginMethodArgumentTypes {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding method argument types registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject beginMethodArgumentTypes];
}
- (void)appendMethodArgumentSelector:(NSString *)name {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding method argument selector registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject appendMethodArgumentSelector:name];
}
- (void)appendMethodArgumentVariable:(NSString *)name {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding method argument variable registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject appendMethodArgumentVariable:name];
}
#pragma mark - Enumerations
- (void)beginEnumeration {
LogStoInfo(@"Starting enumeration...");
NSAssert(NO, @"Not implemented yet!");
}
- (void)appendEnumerationItem:(NSString *)name {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding enumeration item registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject appendEnumerationItem:name];
}
- (void)appendEnumerationValue:(NSString *)value {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding enumeration value registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject appendEnumerationValue:value];
}
#pragma mark - Structs
- (void)beginStruct {
LogStoInfo(@"Starting C struct...");
NSAssert(NO, @"Not implemented yet!");
}
#pragma mark - Constants
- (void)beginConstant {
LogStoInfo(@"Starting constant...");
NSAssert(NO, @"Not implemented yet!");
}
- (void)appendConstantType:(NSString *)type {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding constant type registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject appendConstantType:type];
}
- (void)appendConstantName:(NSString *)name {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding constant name registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject appendConstantName:name];
}
#pragma mark - General objects
- (void)appendType:(NSString *)type {
if (![self expectCurrentRegistrationObjectRespondTo:_cmd]) return;
LogStoDebug(@"Forwarding registration to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject appendType:type];
}
#pragma mark - Finalizing registration for current object
- (void)endCurrentObject {
if ([self doesCurrentRegistrationObjectRespondTo:_cmd]) {
LogStoDebug(@"Forwarding end current object to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject endCurrentObject];
}
LogStoInfo(@"Finalizing %@...", self.currentRegistrationObject);
[self popRegistrationObject];
}
- (void)cancelCurrentObject {
if ([self doesCurrentRegistrationObjectRespondTo:_cmd]) {
LogStoDebug(@"Forwarding cancel current object to %@...", self.currentRegistrationObject);
[self.currentRegistrationObject cancelCurrentObject];
}
LogStoInfo(@"Cancelling %@...", self.currentRegistrationObject);
[self popRegistrationObject];
}
@end