Skip to content

Commit

Permalink
- Rename TyphoonInitializer -> TyphoonMethod
Browse files Browse the repository at this point in the history
- 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
alexgarbarev committed Mar 19, 2014
1 parent 9d7b1de commit 7148e39
Show file tree
Hide file tree
Showing 83 changed files with 18,088 additions and 5,139 deletions.
2 changes: 1 addition & 1 deletion .scripts/pod-update-checksum.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
400fee1c8d720777a9053dc7cdba750d7b222d9c
f6eb959f4f11023e9188e3d47e853550b22cd6a6
48 changes: 24 additions & 24 deletions A-Typhoon.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@


#import <Foundation/Foundation.h>
#import "TyphoonInitializer.h"
#import "TyphoonMethod.h"

@class TyphoonComponentFactory;
@class TyphoonRuntimeArguments;

@interface TyphoonInitializer (InstanceBuilder)
@interface TyphoonMethod (InstanceBuilder)

@property(nonatomic, readonly) BOOL isClassMethod;
- (NSArray *)injectedParameters;

- (NSArray *)parametersInjectedByValue;

- (NSArray *)parametersInjectedByRuntimeArgument;

- (NSInvocation *)newInvocationInFactory:(TyphoonComponentFactory *)factory args:(TyphoonRuntimeArguments *)args;
- (NSInvocation *)newInvocationOnClass:(Class)clazz withFactory:(TyphoonComponentFactory *)factory args:(TyphoonRuntimeArguments *)args;

- (void)setDefinition:(TyphoonDefinition *)definition;

- (NSString *)typeCodeForParameterAtIndex:(NSUInteger)index;
- (BOOL)isClassMethodOnClass:(Class)clazz;

@end
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@

#import <Foundation/Foundation.h>

@class TyphoonDefinition;
@class TyphoonParameterInjectedAsCollection;

typedef enum
{
TyphoonComponentInitializerIsClassMethodGuess,
TyphoonComponentInitializerIsClassMethodYes,
TyphoonComponentInitializerIsClassMethodNo
} TyphoonComponentInitializerIsClassMethod;

/**
* @ingroup Definition
*
Expand All @@ -41,12 +31,10 @@ typedef enum
* Its generally recommended to use initializer-style injection, unless the above drawbacks will manifest.
*
*/
@interface TyphoonInitializer : NSObject <NSCopying>
@interface TyphoonMethod : NSObject <NSCopying>
{
NSMutableArray *_injectedParameters;
NSArray *_parameterNames;
__unsafe_unretained TyphoonDefinition *_definition;
TyphoonComponentInitializerIsClassMethod _isClassMethodStrategy;
SEL _selector;
}

Expand All @@ -57,24 +45,11 @@ typedef enum

@property(nonatomic, readonly) NSArray *parameterNames;

/**
* Returns true if this is a default initializer generated by Typhoon. A manually specified initializer will return false, even if the
* selector is @selector(init)
*/
@property(nonatomic) BOOL generated;

- (id)initWithSelector:(SEL)initializer;

- (id)initWithSelector:(SEL)initializer isClassMethodStrategy:(TyphoonComponentInitializerIsClassMethod)isClassMethod;

- (TyphoonDefinition *)definition;

- (NSArray *)injectedParameters;

/* ====================================================================================================================================== */
#pragma mark - inject


- (void)injectParameterWith:(id)injection;

- (void)injectParameter:(NSString *)parameterName with:(id)injection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,35 @@


#import "TyphoonCollaboratingAssemblyProxy.h"
#import "TyphoonInitializer.h"
#import "TyphoonMethod.h"
#import "NSObject+TyphoonIntrospectionUtils.h"
#import "TyphoonDefinition.h"

#import "TyphoonParameterInjection.h"

#import "TyphoonInjections.h"

@implementation TyphoonInitializer
#import <objc/runtime.h>

@implementation TyphoonMethod


/* ====================================================================================================================================== */
#pragma mark - Initialization & Destruction

- (id)initWithSelector:(SEL)initializer
{
return [self initWithSelector:initializer isClassMethodStrategy:TyphoonComponentInitializerIsClassMethodGuess];
}

- (id)initWithSelector:(SEL)initializer isClassMethodStrategy:(TyphoonComponentInitializerIsClassMethod)isClassMethod;
- (id)initWithSelector:(SEL)selector
{
self = [super init];
if (self) {
_injectedParameters = [[NSMutableArray alloc] init];
_isClassMethodStrategy = isClassMethod;
self.selector = initializer;
self.selector = selector;
}
return self;
}

- (id)init
{
return [self initWithSelector:@selector(init) isClassMethodStrategy:TyphoonComponentInitializerIsClassMethodGuess];
}

/* ====================================================================================================================================== */
#pragma mark - Interface Methods

- (TyphoonDefinition *)definition
{
return _definition;
}

- (NSArray *)injectedParameters
{
return [_injectedParameters copy];
return [self initWithSelector:nil];
}

#pragma mark - manipulations with _injectedParameters
Expand Down Expand Up @@ -171,7 +154,7 @@ - (void)setSelector:(SEL)selector

- (id)copyWithZone:(NSZone *)zone
{
TyphoonInitializer *copy = [[TyphoonInitializer alloc] initWithSelector:_selector isClassMethodStrategy:_isClassMethodStrategy];
TyphoonMethod *copy = [[TyphoonMethod alloc] initWithSelector:_selector];
for (id <TyphoonParameterInjection> parameter in _injectedParameters) {
[copy addParameterInjection:[parameter copyWithZone:NSDefaultMallocZone()]];
}
Expand Down
Loading

0 comments on commit 7148e39

Please sign in to comment.