Permalink
Browse files

cleaning up codebase

  • Loading branch information...
1 parent 1dbb54f commit a825cd3ba9516fea9f46436039d755d94a40804c @thestoics thestoics committed Dec 9, 2010
View
@@ -6,9 +6,18 @@ typedef enum {
} ObjectionInstantiationRule;
+@protocol ObjectionEntry<NSObject>
+
+@property(nonatomic, readonly) ObjectionInstantiationRule lifeCycle;
+
+- (id) extractObject;
+
+@end
+
+
@class ObjectionInjector;
-@interface ObjectionEntry : NSObject<NSCopying> {
+@interface ObjectionEntry : NSObject {
Class _classEntry;
ObjectionInstantiationRule _lifeCycle;
id _injector;
@@ -22,5 +31,6 @@ typedef enum {
- (id) initWithClass:(Class)theClass lifeCycle:(ObjectionInstantiationRule)theLifeCycle;
- (id) extractObject;
-+ (id)withClass:(Class)theClass lifeCycle:(ObjectionInstantiationRule)theLifeCycle;
++ (id)entryWithEntry:(ObjectionEntry *)entry;
++ (id)entryWithClass:(Class)theClass lifeCycle:(ObjectionInstantiationRule)theLifeCycle;
@end
@@ -0,0 +1,35 @@
+static NSString *const ObjectionException = @"ObjectionException";
+
+extern Class ObjectionFindClassForProperty(objc_property_t property) {
+ NSString *attributes = [NSString stringWithCString: property_getAttributes(property) encoding: NSASCIIStringEncoding];
+ NSString *propertyName = [NSString stringWithCString:property_getName(property) encoding:NSASCIIStringEncoding];
+
+ NSRange startRange = [attributes rangeOfString:@"T@\""];
+ if (startRange.location == NSNotFound) {
+ @throw [NSException exceptionWithName:ObjectionException reason:[NSString stringWithFormat:@"Unable to determine class type for property declaration: '%@'", propertyName] userInfo:nil];
+ }
+
+ NSString *startOfClassName = [attributes substringFromIndex:startRange.length];
+ NSRange endRange = [startOfClassName rangeOfString:@"\""];
+
+ if (endRange.location == NSNotFound) {
+ @throw [NSException exceptionWithName:ObjectionException reason:[NSString stringWithFormat:@"Unable to determine class type for property declaration: '%@'", propertyName] userInfo:nil];
+ }
+
+ NSString *className = [startOfClassName substringToIndex:endRange.location];
+ Class theClass = NSClassFromString(className);
+
+ if(!theClass) {
+ @throw [NSException exceptionWithName:ObjectionException reason:[NSString stringWithFormat:@"Unable get class for name '%@' for property '%@'", className, propertyName] userInfo:nil];
+ }
+
+ return theClass;
+}
+
+extern objc_property_t ObjectionGetProperty(Class klass, NSString *propertyName) {
+ objc_property_t property = class_getProperty(klass, (const char *)[propertyName UTF8String]);
+ if (property == NULL) {
+ @throw [NSException exceptionWithName:ObjectionException reason:[NSString stringWithFormat:@"Unable to find property declaration: '%@'", propertyName] userInfo:nil];
+ }
+ return property;
+}
@@ -1,6 +1,7 @@
#import <Foundation/Foundation.h>
+#import "ObjectionEntry.h"
-@interface ObjectionInstanceEntry : NSObject {
+@interface ObjectionInstanceEntry : NSObject<ObjectionEntry> {
id instance;
}
@@ -34,6 +34,12 @@
4B15F24F12AA896900C3CD8E /* OCHamcrest.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 4BA9CFF412AA86E600674F0E /* OCHamcrest.framework */; };
4B25BCE61291B81F00821DC1 /* InjectionErrorsSpecs.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BF451E21291AD28006EB2D5 /* InjectionErrorsSpecs.m */; };
4B25BD4B1291BBE700821DC1 /* InjectionErrorFixtures.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B25BD4A1291BBE700821DC1 /* InjectionErrorFixtures.m */; };
+ 4B496DB812B0F0340053F2A3 /* ObjectionFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B496DB512B0F0340053F2A3 /* ObjectionFunctions.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 4B496DBA12B0F0340053F2A3 /* ObjectionFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B496DB512B0F0340053F2A3 /* ObjectionFunctions.h */; };
+ 4B496E6B12B0F3E50053F2A3 /* ObjectionFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B496E6A12B0F3E50053F2A3 /* ObjectionFunctions.m */; };
+ 4B496E6C12B0F3E50053F2A3 /* ObjectionFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B496E6A12B0F3E50053F2A3 /* ObjectionFunctions.m */; };
+ 4B496E6D12B0F3E50053F2A3 /* ObjectionFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B496E6A12B0F3E50053F2A3 /* ObjectionFunctions.m */; };
+ 4B496E6E12B0F3E50053F2A3 /* ObjectionFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B496E6A12B0F3E50053F2A3 /* ObjectionFunctions.m */; };
4B7300D812AA8F3400903427 /* InheritanceSpecs.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B7300D712AA8F3400903427 /* InheritanceSpecs.m */; };
4B7300D912AA8F3400903427 /* InheritanceSpecs.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B7300D712AA8F3400903427 /* InheritanceSpecs.m */; };
4B957EC312ADDFC500CBF1EB /* ObjectionModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B957EC212ADDFC500CBF1EB /* ObjectionModule.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -57,6 +63,7 @@
4BA9CFB212AA868400674F0E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BA9CFB112AA868400674F0E /* main.m */; };
4BA9CFEA12AA86D300674F0E /* Cedar-iPhone.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BA9CFE912AA86D300674F0E /* Cedar-iPhone.framework */; };
4BA9CFEC12AA86D300674F0E /* OCHamcrest-iPhone.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BA9CFEB12AA86D300674F0E /* OCHamcrest-iPhone.framework */; };
+ 4BAEB37B12B0F7A200CD97E5 /* ObjectionFunctions.h in Copy Header Files */ = {isa = PBXBuildFile; fileRef = 4B496DB512B0F0340053F2A3 /* ObjectionFunctions.h */; };
4BED512112AA8BCC00CA6B36 /* ObjectionEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BED511E12AA8BCC00CA6B36 /* ObjectionEntry.m */; };
4BED512212AA8BCC00CA6B36 /* ObjectionInjector.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BED511F12AA8BCC00CA6B36 /* ObjectionInjector.m */; };
4BED512312AA8BCC00CA6B36 /* ObjectionInstanceEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BED512012AA8BCC00CA6B36 /* ObjectionInstanceEntry.m */; };
@@ -101,6 +108,7 @@
4BA6DD1F12AAB3CD00CFFD70 /* ObjectionEntry.h in Copy Header Files */,
4BA6DD2012AAB3CD00CFFD70 /* ObjectionInjector.h in Copy Header Files */,
4BA6DD2112AAB3CD00CFFD70 /* ObjectionInstanceEntry.h in Copy Header Files */,
+ 4BAEB37B12B0F7A200CD97E5 /* ObjectionFunctions.h in Copy Header Files */,
);
name = "Copy Header Files";
runOnlyForDeploymentPostprocessing = 0;
@@ -110,6 +118,8 @@
/* Begin PBXFileReference section */
4B25BD491291BBE700821DC1 /* InjectionErrorFixtures.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectionErrorFixtures.h; sourceTree = "<group>"; };
4B25BD4A1291BBE700821DC1 /* InjectionErrorFixtures.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InjectionErrorFixtures.m; sourceTree = "<group>"; };
+ 4B496DB512B0F0340053F2A3 /* ObjectionFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectionFunctions.h; sourceTree = "<group>"; };
+ 4B496E6A12B0F3E50053F2A3 /* ObjectionFunctions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ObjectionFunctions.m; sourceTree = "<group>"; };
4B7300D712AA8F3400903427 /* InheritanceSpecs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InheritanceSpecs.m; sourceTree = "<group>"; };
4B957EC212ADDFC500CBF1EB /* ObjectionModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectionModule.h; sourceTree = "<group>"; };
4B957EC512ADE03900CBF1EB /* ObjectionModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ObjectionModule.m; sourceTree = "<group>"; };
@@ -217,6 +227,7 @@
08FB77AEFE84172EC02AAC07 /* Source */ = {
isa = PBXGroup;
children = (
+ 4B496E6A12B0F3E50053F2A3 /* ObjectionFunctions.m */,
4BED511E12AA8BCC00CA6B36 /* ObjectionEntry.m */,
4BED511F12AA8BCC00CA6B36 /* ObjectionInjector.m */,
4BED512012AA8BCC00CA6B36 /* ObjectionInstanceEntry.m */,
@@ -250,6 +261,7 @@
4BED513012AA8BF300CA6B36 /* ObjectionInjector.h */,
4BED513112AA8BF300CA6B36 /* ObjectionInstanceEntry.h */,
4B957EC212ADDFC500CBF1EB /* ObjectionModule.h */,
+ 4B496DB512B0F0340053F2A3 /* ObjectionFunctions.h */,
);
path = Headers;
sourceTree = "<group>";
@@ -292,13 +304,15 @@
4BED513412AA8BF300CA6B36 /* ObjectionInstanceEntry.h in Headers */,
4B957EC312ADDFC500CBF1EB /* ObjectionModule.h in Headers */,
4B957EE712ADE26500CBF1EB /* Objection.h in Headers */,
+ 4B496DB812B0F0340053F2A3 /* ObjectionFunctions.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
D2AAC07A0554694100DB518D /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
+ 4B496DBA12B0F0340053F2A3 /* ObjectionFunctions.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -467,6 +481,7 @@
4B957EC912ADE06600CBF1EB /* ObjectionModule.m in Sources */,
4B957ECF12ADE0B900CBF1EB /* Objection.m in Sources */,
4B95819A12AE593F00CBF1EB /* ModuleUsageSpecs.m in Sources */,
+ 4B496E6E12B0F3E50053F2A3 /* ObjectionFunctions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -480,6 +495,7 @@
4B957EC712ADE03900CBF1EB /* ObjectionModule.m in Sources */,
4B957ECE12ADE0B900CBF1EB /* Objection.m in Sources */,
4B95819712AE593F00CBF1EB /* ModuleUsageSpecs.m in Sources */,
+ 4B496E6C12B0F3E50053F2A3 /* ObjectionFunctions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -499,6 +515,7 @@
4B957EC612ADE03900CBF1EB /* ObjectionModule.m in Sources */,
4B957ECC12ADE0B900CBF1EB /* Objection.m in Sources */,
4B95819912AE593F00CBF1EB /* ModuleUsageSpecs.m in Sources */,
+ 4B496E6B12B0F3E50053F2A3 /* ObjectionFunctions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -511,6 +528,7 @@
4BED512C12AA8BCC00CA6B36 /* ObjectionInstanceEntry.m in Sources */,
4B957EC812ADE05D00CBF1EB /* ObjectionModule.m in Sources */,
4B957ED112ADE0B900CBF1EB /* Objection.m in Sources */,
+ 4B496E6D12B0F3E50053F2A3 /* ObjectionFunctions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -103,8 +103,9 @@ Installation
1. git clone git://github.com/atomicobject/objection.git
2. Open Objection.xcodeproj
3. Select Objection-iPhone target
-4. Select Release Configuration.
+4. Select Release Configuration
5. Build
+6. Add -ObjC and -all_load to Other Link Flags in your project
#### Include framework
#import <Objection-iPhone/Objection.h>
@@ -123,6 +124,6 @@ Installation
Requirements
============
-* MacOS X 10.6 >
-* iOS 3.0 >
+* MacOS X 10.6 +
+* iOS 3.0 +
View
@@ -47,7 +47,7 @@ + (void) registerClass:(Class)theClass lifeCycle:(ObjectionInstantiationRule)lif
}
if (theClass && [gObjectionContext objectForKey:NSStringFromClass(theClass)] == nil) {
- [gObjectionContext setObject:[ObjectionEntry withClass:theClass lifeCycle:lifeCycle] forKey:NSStringFromClass(theClass)];
+ [gObjectionContext setObject:[ObjectionEntry entryWithClass:theClass lifeCycle:lifeCycle] forKey:NSStringFromClass(theClass)];
}
[pool drain];
pthread_mutex_unlock(&gObjectionMutex);
View
@@ -1,7 +1,6 @@
#import "ObjectionEntry.h"
#import "Objection.h"
-
-#import <objc/runtime.h>
+#import "ObjectionFunctions.h"
@interface ObjectionEntry (Private)
- (void) notifyObjectThatItIsReady: (id)object;
@@ -43,13 +42,6 @@ - (void)dealloc {
[super dealloc];
}
-#pragma mark NSCopying
-#pragma mark -
-
-- (id)copyWithZone:(NSZone *)zone {
- return [[ObjectionEntry alloc] initWithClass:self.classEntry lifeCycle:self.lifeCycle];
-}
-
#pragma mark Private Methods
#pragma mark -
@@ -66,12 +58,8 @@ - (id)buildObject {
id objectUnderConstruction = [[self.classEntry alloc] init];
for (NSString *propertyName in properties) {
- objc_property_t property = class_getProperty(self.classEntry, (const char *)[propertyName UTF8String]);
- if (property == NULL) {
- @throw [NSException exceptionWithName:@"ObjectionInjectionException" reason:[NSString stringWithFormat:@"Unable to find property declaration: '%@'", propertyName] userInfo:nil];
- }
-
- Class desiredClass = [self parseClassFromProperty:property];
+ objc_property_t property = ObjectionGetProperty(self.classEntry, propertyName);
+ Class desiredClass = ObjectionFindClassForProperty(property);
// Ensure that the class is initialized before attempting to retrieve it.
// Using +load would force all registered classes to be initialized so are
// lazily initializing them.
@@ -103,35 +91,11 @@ - (id)buildObject {
#pragma mark Class Methods
#pragma mark -
-+ (id)withClass:(Class)theClass lifeCycle:(ObjectionInstantiationRule)theLifeCycle {
++ (id)entryWithClass:(Class)theClass lifeCycle:(ObjectionInstantiationRule)theLifeCycle {
return [[[ObjectionEntry alloc] initWithClass:theClass lifeCycle:theLifeCycle] autorelease];
}
-#pragma mark Private Methods
-
-- (Class)parseClassFromProperty:(objc_property_t)property {
- NSString *attributes = [NSString stringWithCString: property_getAttributes(property) encoding: NSASCIIStringEncoding];
- NSString *propertyName = [NSString stringWithCString:property_getName(property) encoding:NSASCIIStringEncoding];
-
- NSRange startRange = [attributes rangeOfString:@"T@\""];
- if (startRange.location == NSNotFound) {
- @throw [NSException exceptionWithName:@"ObjectionInjectionException" reason:[NSString stringWithFormat:@"Unable to determine class type for property declaration: '%@'", propertyName] userInfo:nil];
- }
-
- NSString *startOfClassName = [attributes substringFromIndex:startRange.length];
- NSRange endRange = [startOfClassName rangeOfString:@"\""];
-
- if (endRange.location == NSNotFound) {
- @throw [NSException exceptionWithName:@"ObjectionInjectionException" reason:[NSString stringWithFormat:@"Unable to determine class type for property declaration: '%@'", propertyName] userInfo:nil];
- }
-
- NSString *className = [startOfClassName substringToIndex:endRange.location];
- Class theClass = NSClassFromString(className);
-
- if(!theClass) {
- @throw [NSException exceptionWithName:@"ObjectionInjectionException" reason:[NSString stringWithFormat:@"Unable get class for name '%@' for property '%@'", className, propertyName] userInfo:nil];
- }
-
- return theClass;
++ (id)entryWithEntry:(ObjectionEntry *)entry {
+ return [[[ObjectionEntry alloc] initWithClass:entry.classEntry lifeCycle:entry.lifeCycle] autorelease];
}
@end
@@ -0,0 +1,5 @@
+#import <Foundation/Foundation.h>
+#import <objc/runtime.h>
+
+extern Class ObjectionFindClassForProperty(objc_property_t property);
+extern objc_property_t ObjectionGetProperty(Class klass, NSString *propertyName);
View
@@ -28,16 +28,16 @@ - (id)initWithContext:(NSDictionary *)theGlobalContext andModule:(ObjectionModul
- (id)getObject:(Class)theClass {
@synchronized(self) {
+
NSString *key = NSStringFromClass(theClass);
- ObjectionEntry *injectorEntry = [_context objectForKey:key];
+ id<ObjectionEntry> injectorEntry = [_context objectForKey:key];
if (!injectorEntry) {
- ObjectionEntry *entry = [_globalContext objectForKey:key];
- if (entry) {
- injectorEntry = [entry copy];
- injectorEntry.injector = self;
+ id<ObjectionEntry> entry = [_globalContext objectForKey:key];
+ if ([entry isKindOfClass:[ObjectionEntry class]]) {
+ injectorEntry = [ObjectionEntry entryWithEntry:entry];
+ ((ObjectionEntry *)injectorEntry).injector = self;
[_context setObject:injectorEntry forKey:key];
- [injectorEntry release];
}
}
@@ -13,6 +13,10 @@ - (id) extractObject {
return instance;
}
+- (ObjectionInstantiationRule) lifeCycle {
+ return ObjectionInstantiationRule_Singleton;
+}
+
- (void)dealloc {
[instance release]; instance = nil;
[super dealloc];

0 comments on commit a825cd3

Please sign in to comment.