Permalink
Browse files

Adding namespace prefix to Objection classes

  • Loading branch information...
1 parent 92b05fc commit b6ebb126ab8e1b46f0a0375ebb391497e57fce5c @thestoics thestoics committed Jul 26, 2011
Showing with 427 additions and 420 deletions.
  1. +141 −139 Objection.xcodeproj/project.pbxproj
  2. +15 −0 Source/JSObjection.h
  3. +15 −14 Source/{Objection.m → JSObjection.m}
  4. +2 −2 Source/{ObjectionBindingEntry.h → JSObjectionBindingEntry.h}
  5. +4 −4 Source/{ObjectionBindingEntry.m → JSObjectionBindingEntry.m}
  6. +24 −0 Source/JSObjectionEntry.h
  7. +21 −0 Source/JSObjectionEntry.m
  8. +16 −0 Source/JSObjectionFunctions.h
  9. +12 −12 Source/{ObjectionFunctions.m → JSObjectionFunctions.m}
  10. +3 −3 Source/{ObjectionInjector.h → JSObjectionInjector.h}
  11. +9 −9 Source/{ObjectionInjector.m → JSObjectionInjector.m}
  12. +14 −0 Source/JSObjectionInjectorEntry.h
  13. +17 −17 Source/{ObjectionInjectorEntry.m → JSObjectionInjectorEntry.m}
  14. +29 −0 Source/JSObjectionModule.h
  15. +18 −18 Source/{ObjectionModule.m → JSObjectionModule.m}
  16. +18 −0 Source/JSObjectionProviderEntry.h
  17. +4 −4 Source/{ObjectionProviderEntry.m → JSObjectionProviderEntry.m}
  18. +1 −1 Source/NSObject+Objection.h
  19. +1 −1 Source/NSObject+Objection.m
  20. +12 −23 Source/Objection.h
  21. +0 −24 Source/ObjectionEntry.h
  22. +0 −21 Source/ObjectionEntry.m
  23. +0 −16 Source/ObjectionFunctions.h
  24. +0 −14 Source/ObjectionInjectorEntry.h
  25. +0 −29 Source/ObjectionModule.h
  26. +0 −18 Source/ObjectionProviderEntry.h
  27. +17 −17 Specs/BasicUsageSpecs.m
  28. +4 −4 Specs/InheritanceSpecs.m
  29. +6 −6 Specs/InjectionErrorsSpecs.m
  30. +5 −5 Specs/ModuleFixtures.h
  31. +4 −4 Specs/ModuleFixtures.m
  32. +15 −15 Specs/ModuleUsageSpecs.m
Oops, something went wrong.
View
@@ -0,0 +1,15 @@
+#import <Foundation/Foundation.h>
+#import "JSObjectionInjector.h"
+#import "JSObjectionEntry.h"
+
+@interface JSObjection : NSObject {
+
+}
+
++ (JSObjectionInjector *)createInjector:(JSObjectionModule *)aModule;
++ (JSObjectionInjector *)createInjector;
++ (void)registerClass:(Class)theClass lifeCycle:(JSObjectionInstantiationRule)lifeCycle;
++ (void)setGlobalInjector:(JSObjectionInjector *)anInjector;
++ (JSObjectionInjector *)globalInjector;
++ (void)reset;
+@end
@@ -1,28 +1,29 @@
-#import "Objection.h"
+#import "JSObjection.h"
#import <pthread.h>
+#import "JSObjectionInjectorEntry.h"
static NSMutableDictionary *gObjectionContext;
static pthread_mutex_t gObjectionMutex;
-static ObjectionInjector *gGlobalInjector;
+static JSObjectionInjector *gGlobalInjector;
-@implementation Objection
+@implementation JSObjection
-+ (ObjectionInjector *) createInjector:(ObjectionModule *)aModule
++ (JSObjectionInjector *) createInjector:(JSObjectionModule *)aModule
{
pthread_mutex_lock(&gObjectionMutex);
@try {
- return [[[ObjectionInjector alloc] initWithContext:gObjectionContext andModule:aModule] autorelease];
+ return [[[JSObjectionInjector alloc] initWithContext:gObjectionContext andModule:aModule] autorelease];
}
@finally {
pthread_mutex_unlock(&gObjectionMutex);
}
}
-+ (ObjectionInjector *) createInjector
++ (JSObjectionInjector *) createInjector
{
pthread_mutex_lock(&gObjectionMutex);
@try {
- return [[[ObjectionInjector alloc] initWithContext:gObjectionContext] autorelease];
+ return [[[JSObjectionInjector alloc] initWithContext:gObjectionContext] autorelease];
}
@finally {
pthread_mutex_unlock(&gObjectionMutex);
@@ -31,7 +32,7 @@ + (ObjectionInjector *) createInjector
+ (void)initialize
{
- if (self == [Objection class]) {
+ if (self == [JSObjection class]) {
gObjectionContext = [[NSMutableDictionary alloc] init];
pthread_mutexattr_t mutexattr;
pthread_mutexattr_init(&mutexattr);
@@ -41,15 +42,15 @@ + (void)initialize
}
}
-+ (void) registerClass:(Class)theClass lifeCycle:(ObjectionInstantiationRule)lifeCycle
++ (void) registerClass:(Class)theClass lifeCycle:(JSObjectionInstantiationRule)lifeCycle
{
pthread_mutex_lock(&gObjectionMutex);
- if (lifeCycle != ObjectionInstantiationRuleSingleton && lifeCycle != ObjectionInstantiationRuleNormal) {
- @throw [NSException exceptionWithName:@"ObjectionInjectorException" reason:@"Invalid Instantiation Rule" userInfo:nil];
+ if (lifeCycle != JSObjectionInstantiationRuleSingleton && lifeCycle != JSObjectionInstantiationRuleNormal) {
+ @throw [NSException exceptionWithName:@"JSObjectionInjectorException" reason:@"Invalid Instantiation Rule" userInfo:nil];
}
if (theClass && [gObjectionContext objectForKey:NSStringFromClass(theClass)] == nil) {
- [gObjectionContext setObject:[ObjectionInjectorEntry entryWithClass:theClass lifeCycle:lifeCycle] forKey:NSStringFromClass(theClass)];
+ [gObjectionContext setObject:[JSObjectionInjectorEntry entryWithClass:theClass lifeCycle:lifeCycle] forKey:NSStringFromClass(theClass)];
}
pthread_mutex_unlock(&gObjectionMutex);
}
@@ -61,15 +62,15 @@ + (void) reset
pthread_mutex_unlock(&gObjectionMutex);
}
-+ (void)setGlobalInjector:(ObjectionInjector *)anInjector
++ (void)setGlobalInjector:(JSObjectionInjector *)anInjector
{
if (gGlobalInjector != anInjector) {
[gGlobalInjector release];
gGlobalInjector = [anInjector retain];
}
}
-+ (ObjectionInjector *) globalInjector
++ (JSObjectionInjector *) globalInjector
{
return [[gGlobalInjector retain] autorelease];
}
@@ -1,7 +1,7 @@
#import <Foundation/Foundation.h>
-#import "ObjectionEntry.h"
+#import "JSObjectionEntry.h"
-@interface ObjectionBindingEntry : ObjectionEntry {
+@interface JSObjectionBindingEntry : JSObjectionEntry {
id _instance;
}
@@ -1,7 +1,7 @@
-#import "ObjectionBindingEntry.h"
+#import "JSObjectionBindingEntry.h"
-@implementation ObjectionBindingEntry
+@implementation JSObjectionBindingEntry
- (id)initWithObject:(id)theObject
{
@@ -16,9 +16,9 @@ - (id)extractObject
return _instance;
}
-- (ObjectionInstantiationRule)lifeCycle
+- (JSObjectionInstantiationRule)lifeCycle
{
- return ObjectionInstantiationRuleSingleton;
+ return JSObjectionInstantiationRuleSingleton;
}
- (void)dealloc
View
@@ -0,0 +1,24 @@
+#import <Foundation/Foundation.h>
+
+typedef enum {
+ JSObjectionInstantiationRuleNone = -1,
+ JSObjectionInstantiationRuleNormal,
+ JSObjectionInstantiationRuleSingleton
+} JSObjectionInstantiationRule;
+
+
+@class JSObjectionInjector, JSObjectionEntry;
+
+@protocol JSObjectionEntry<NSObject>
+@property (nonatomic, readonly) JSObjectionInstantiationRule lifeCycle;
+@property (nonatomic, assign) JSObjectionInjector *injector;
+- (id)extractObject;
++ (id)entryWithEntry:(JSObjectionEntry *)entry;
+@end
+
+@interface JSObjectionEntry : NSObject<JSObjectionEntry>
+{
+ id _injector;
+}
+
+@end
View
@@ -0,0 +1,21 @@
+#import "JSObjectionEntry.h"
+
+@implementation JSObjectionEntry
+@synthesize injector = _injector;
+@dynamic lifeCycle;
+
+- (id)extractObject
+{
+ return nil;
+}
+
++ (id)entryWithEntry:(JSObjectionEntry *)entry
+{
+ return [[entry retain] autorelease];
+}
+
+- (JSObjectionInstantiationRule)lifeCycle
+{
+ return JSObjectionInstantiationRuleNone;
+}
+@end
@@ -0,0 +1,16 @@
+#import <Foundation/Foundation.h>
+#import <objc/runtime.h>
+
+typedef enum {
+ JSObjectionTypeClass,
+ JSObjectionTypeProtocol
+} JSObjectionType;
+
+typedef struct objection_property_info {
+ void *value;
+ JSObjectionType type;
+} JSObjectionPropertyInfo;
+
+JSObjectionPropertyInfo JSFindClassOrProtocolForProperty(objc_property_t property);
+objc_property_t JSGetProperty(Class klass, NSString *propertyName);
+NSSet* JSBuildDependenciesForClass(Class klass, NSSet *requirements);
@@ -1,48 +1,48 @@
#import <objc/runtime.h>
-#import "ObjectionFunctions.h"
+#import "JSObjectionFunctions.h"
-static NSString *const ObjectionException = @"ObjectionException";
+static NSString *const JSObjectionException = @"JSObjectionException";
-ObjectionPropertyInfo ObjectionFindClassOrProtocolForProperty(objc_property_t property)
+JSObjectionPropertyInfo JSFindClassOrProtocolForProperty(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];
+ @throw [NSException exceptionWithName:JSObjectionException 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];
+ @throw [NSException exceptionWithName:JSObjectionException reason:[NSString stringWithFormat:@"Unable to determine class type for property declaration: '%@'", propertyName] userInfo:nil];
}
NSString *classOrProtocolName = [startOfClassName substringToIndex:endRange.location];
id classOrProtocol = nil;
- ObjectionPropertyInfo propertyInfo;
+ JSObjectionPropertyInfo propertyInfo;
if ([classOrProtocolName hasPrefix:@"<"] && [classOrProtocolName hasSuffix:@">"]) {
classOrProtocolName = [classOrProtocolName stringByReplacingOccurrencesOfString:@"<" withString:@""];
classOrProtocolName = [classOrProtocolName stringByReplacingOccurrencesOfString:@">" withString:@""];
classOrProtocol = objc_getProtocol([classOrProtocolName UTF8String]);
- propertyInfo.type = ObjectionTypeProtocol;
+ propertyInfo.type = JSObjectionTypeProtocol;
} else {
classOrProtocol = NSClassFromString(classOrProtocolName);
- propertyInfo.type = ObjectionTypeClass;
+ propertyInfo.type = JSObjectionTypeClass;
}
if(!classOrProtocol) {
- @throw [NSException exceptionWithName:ObjectionException reason:[NSString stringWithFormat:@"Unable get class for name '%@' for property '%@'", classOrProtocolName, propertyName] userInfo:nil];
+ @throw [NSException exceptionWithName:JSObjectionException reason:[NSString stringWithFormat:@"Unable get class for name '%@' for property '%@'", classOrProtocolName, propertyName] userInfo:nil];
}
propertyInfo.value = classOrProtocol;
return propertyInfo;
}
-NSSet* ObjectionBuildDependenciesForClass(Class klass, NSSet *requirements)
+NSSet* JSBuildDependenciesForClass(Class klass, NSSet *requirements)
{
Class superClass = class_getSuperclass([klass class]);
if([superClass respondsToSelector:@selector(objectionRequires)]) {
@@ -54,11 +54,11 @@ ObjectionPropertyInfo ObjectionFindClassOrProtocolForProperty(objc_property_t pr
return requirements;
}
-objc_property_t ObjectionGetProperty(Class klass, NSString *propertyName)
+objc_property_t JSGetProperty(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];
+ @throw [NSException exceptionWithName:JSObjectionException reason:[NSString stringWithFormat:@"Unable to find property declaration: '%@'", propertyName] userInfo:nil];
}
return property;
}
@@ -1,13 +1,13 @@
#import <Foundation/Foundation.h>
-#import "ObjectionModule.h"
+#import "JSObjectionModule.h"
-@interface ObjectionInjector : NSObject {
+@interface JSObjectionInjector : NSObject {
NSDictionary *_globalContext;
NSMutableDictionary *_context;
NSSet *_eagerSingletons;
}
- (id)initWithContext:(NSDictionary *)theGlobalContext;
-- (id)initWithContext:(NSDictionary *)theGlobalContext andModule:(ObjectionModule *)theModule;
+- (id)initWithContext:(NSDictionary *)theGlobalContext andModule:(JSObjectionModule *)theModule;
- (id)getObject:(id)classOrProtocol;
@end
@@ -1,13 +1,13 @@
-#import "ObjectionInjector.h"
-#import "ObjectionEntry.h"
+#import "JSObjectionInjector.h"
+#import "JSObjectionEntry.h"
#import <pthread.h>
#import <objc/runtime.h>
-@interface ObjectionInjector(Private)
+@interface JSObjectionInjector(Private)
- (void)initializeEagerSingletons;
@end
-@implementation ObjectionInjector
+@implementation JSObjectionInjector
- (id)initWithContext:(NSDictionary *)theGlobalContext
{
@@ -20,7 +20,7 @@ - (id)initWithContext:(NSDictionary *)theGlobalContext
return self;
}
-- (id)initWithContext:(NSDictionary *)theGlobalContext andModule:(ObjectionModule *)theModule
+- (id)initWithContext:(NSDictionary *)theGlobalContext andModule:(JSObjectionModule *)theModule
{
if (self = [self initWithContext:theGlobalContext]) {
[theModule configure];
@@ -47,11 +47,11 @@ - (id)getObject:(id)classOrProtocol
}
- id<ObjectionEntry> injectorEntry = [_context objectForKey:key];
+ id<JSObjectionEntry> injectorEntry = [_context objectForKey:key];
injectorEntry.injector = self;
if (!injectorEntry) {
- id<ObjectionEntry> entry = [_globalContext objectForKey:key];
+ id<JSObjectionEntry> entry = [_globalContext objectForKey:key];
if (entry) {
injectorEntry = [[entry class] entryWithEntry:entry];
injectorEntry.injector = self;
@@ -71,10 +71,10 @@ - (void)initializeEagerSingletons
{
for (NSString *eagerSingletonKey in _eagerSingletons) {
id entry = [_globalContext objectForKey:eagerSingletonKey];
- if ([entry lifeCycle] == ObjectionInstantiationRuleSingleton) {
+ if ([entry lifeCycle] == JSObjectionInstantiationRuleSingleton) {
[self getObject:NSClassFromString(eagerSingletonKey)];
} else {
- @throw [NSException exceptionWithName:@"ObjectionException"
+ @throw [NSException exceptionWithName:@"JSObjectionException"
reason:[NSString stringWithFormat:@"Unable to initialize eager singleton for the class '%@' because it was never registered as a singleton", eagerSingletonKey]
userInfo:nil];
}
@@ -0,0 +1,14 @@
+#import <Foundation/Foundation.h>
+#import "JSObjectionEntry.h"
+
+@interface JSObjectionInjectorEntry : JSObjectionEntry {
+ Class _classEntry;
+ JSObjectionInstantiationRule _lifeCycle;
+ id _storageCache;
+}
+
+@property (nonatomic, readonly) Class classEntry;
+
+- (id)initWithClass:(Class)theClass lifeCycle:(JSObjectionInstantiationRule)theLifeCycle;
++ (id)entryWithClass:(Class)theClass lifeCycle:(JSObjectionInstantiationRule)theLifeCycle;
+@end
Oops, something went wrong.

0 comments on commit b6ebb12

Please sign in to comment.