-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Rename TyphoonInitializer -> TyphoonMethod
- Refactor TyphoonMethod to be common (removed dependency on definition) - Refactor injections to use new method for method injections - Fixed bug in TypeDescriptor when it was primitive for unknown '@' object Related to #198
- Loading branch information
1 parent
9d7b1de
commit 7148e39
Showing
83 changed files
with
18,088 additions
and
5,139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
400fee1c8d720777a9053dc7cdba750d7b222d9c | ||
f6eb959f4f11023e9188e3d47e853550b22cd6a6 |
Large diffs are not rendered by default.
Oops, something went wrong.
135 changes: 0 additions & 135 deletions
135
Source/Definition/Initializer/Internal/TyphoonInitializer+InstanceBuilder.m
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
Source/Definition/Initializer/Internal/TyphoonMethod+InstanceBuilder.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TYPHOON FRAMEWORK | ||
// Copyright 2013, Jasper Blues & Contributors | ||
// All Rights Reserved. | ||
// | ||
// NOTICE: The authors permit you to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
|
||
#import "TyphoonLinkerCategoryBugFix.h" | ||
#import "TyphoonMethod+InstanceBuilder.h" | ||
#import "TyphoonDefinition.h" | ||
#import "TyphoonComponentFactory.h" | ||
#import "TyphoonIntrospectionUtils.h" | ||
#import "TyphoonInjectionByObjectFromString.h" | ||
#import "TyphoonInjectionByRuntimeArgument.h" | ||
#import "TyphoonTypeDescriptor.h" | ||
|
||
TYPHOON_LINK_CATEGORY(TyphoonInitializer_InstanceBuilder) | ||
|
||
|
||
@implementation TyphoonMethod (InstanceBuilder) | ||
|
||
/* ====================================================================================================================================== */ | ||
#pragma mark - Interface Methods | ||
|
||
- (NSArray *)injectedParameters | ||
{ | ||
return [_injectedParameters copy]; | ||
} | ||
|
||
- (NSArray *)parametersInjectedByValue | ||
{ | ||
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { | ||
return [evaluatedObject isKindOfClass:[TyphoonInjectionByObjectFromString class]]; | ||
}]; | ||
return [_injectedParameters filteredArrayUsingPredicate:predicate]; | ||
} | ||
|
||
- (NSArray *)parametersInjectedByRuntimeArgument | ||
{ | ||
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { | ||
return [evaluatedObject isKindOfClass:[TyphoonInjectionByRuntimeArgument class]]; | ||
}]; | ||
return [_injectedParameters filteredArrayUsingPredicate:predicate]; | ||
} | ||
|
||
- (NSInvocation *)newInvocationOnClass:(Class)clazz withFactory:(TyphoonComponentFactory *)factory args:(TyphoonRuntimeArguments *)args; | ||
{ | ||
BOOL isClassMethod = [self isClassMethodOnClass:clazz]; | ||
|
||
NSArray *typeCodes = [TyphoonIntrospectionUtils typeCodesForSelector:self.selector ofClass:clazz isClassMethod:isClassMethod]; | ||
|
||
NSMethodSignature *signature = [self methodSignatureWithTarget:clazz isClassMethod:isClassMethod]; | ||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; | ||
[invocation retainArguments]; | ||
[invocation setSelector:_selector]; | ||
|
||
[[self injectedParameters] enumerateObjectsUsingBlock:^(id <TyphoonParameterInjection> parameter, NSUInteger index, BOOL *stop) { | ||
TyphoonTypeDescriptor *type = [TyphoonTypeDescriptor descriptorWithTypeCode:typeCodes[index]]; | ||
[parameter setArgumentWithType:type onInvocation:invocation withFactory:factory args:args]; | ||
}]; | ||
|
||
return invocation; | ||
} | ||
|
||
/* ====================================================================================================================================== */ | ||
#pragma mark - Private Methods | ||
|
||
- (BOOL)isClassMethodOnClass:(Class)_class | ||
{ | ||
BOOL instanceRespondsToSelector = [_class instancesRespondToSelector:_selector]; | ||
BOOL classRespondsToSelector = [_class respondsToSelector:_selector]; | ||
|
||
if (!instanceRespondsToSelector && !classRespondsToSelector) { | ||
[NSException raise:NSInvalidArgumentException | ||
format:@"Method '%@' not found on '%@'. Did you include the required ':' characters to signify arguments?", | ||
NSStringFromSelector(_selector), NSStringFromClass(_class)]; | ||
} | ||
|
||
return classRespondsToSelector && !instanceRespondsToSelector; | ||
} | ||
|
||
- (NSMethodSignature *)methodSignatureWithTarget:(Class)clazz isClassMethod:(BOOL)isClassMethod | ||
{ | ||
return isClassMethod ? [clazz methodSignatureForSelector:_selector] : [clazz instanceMethodSignatureForSelector:_selector]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.