From 393811e02eeae6da3e239598739bb78e910d4ae4 Mon Sep 17 00:00:00 2001 From: Tomaz Kragelj Date: Thu, 19 Apr 2012 09:41:01 +0200 Subject: [PATCH] Added method arguments registration. --- AppledocTests/Store/MethodArgumentInfoTests.m | 98 +++++++++++++++++++ appledoc.xcodeproj/project.pbxproj | 4 + appledoc/Store/InterfaceInfoBase.m | 2 +- appledoc/Store/MethodArgumentInfo.h | 6 ++ appledoc/Store/MethodArgumentInfo.m | 38 +++++++ appledoc/Store/Store.m | 4 +- appledoc/Store/StoreConstants.m | 4 +- 7 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 AppledocTests/Store/MethodArgumentInfoTests.m diff --git a/AppledocTests/Store/MethodArgumentInfoTests.m b/AppledocTests/Store/MethodArgumentInfoTests.m new file mode 100644 index 00000000..ec91d7d2 --- /dev/null +++ b/AppledocTests/Store/MethodArgumentInfoTests.m @@ -0,0 +1,98 @@ +// +// MethodArgumentInfoTests.m +// appledoc +// +// Created by Tomaž Kragelj on 4/17/12. +// Copyright (c) 2012 Tomaz Kragelj. All rights reserved. +// + +#import "Store.h" +#import "TestCaseBase.h" + +@interface MethodArgumentInfoTests : TestCaseBase +@end + +@interface MethodArgumentInfoTests (CreationMethods) +- (void)runWithMethodArgumentInfo:(void(^)(MethodArgumentInfo *info))handler; +@end + +@implementation MethodArgumentInfoTests + +#pragma mark - Verify lazy initialization + +- (void)testLazyInitializersWork { + [self runWithMethodArgumentInfo:^(MethodArgumentInfo *info) { + // execute & verify + assertThat(info.argumentType, instanceOf([TypeInfo class])); + }]; +} + +#pragma mark - beginMethodArgumentTypes + +- (void)testBeginMethodArgumentTypesShouldCreateNewMethodArgument { + [self runWithMethodArgumentInfo:^(MethodArgumentInfo *info) { + // setup + id mock = [OCMockObject mockForClass:[Store class]]; + [[mock expect] pushRegistrationObject:OCMOCK_ANY]; + info.objectRegistrar = mock; + // execute + [info beginMethodArgumentTypes]; + // verify + STAssertNoThrow([mock verify], nil); + }]; +} + +#pragma mark - appendMethodArgumentSelector: + +- (void)testAppendMethodArgumentSelectorShouldAssignGivenString { + [self runWithMethodArgumentInfo:^(MethodArgumentInfo *info) { + // execute + [info appendMethodArgumentSelector:@"value"]; + // verify + assertThat(info.argumentSelector, equalTo(@"value")); + }]; +} + +- (void)testAppendMethodArgumentSelectorShouldUseLastValueIfSentMultipleTimes { + [self runWithMethodArgumentInfo:^(MethodArgumentInfo *info) { + // execute + [info appendMethodArgumentSelector:@"value1"]; + [info appendMethodArgumentSelector:@"value2"]; + // verify + assertThat(info.argumentSelector, equalTo(@"value2")); + }]; +} + +#pragma mark - appendMethodArgumentVariable: + +- (void)testAppendMethodArgumentVariableShouldAssignGivenString { + [self runWithMethodArgumentInfo:^(MethodArgumentInfo *info) { + // execute + [info appendMethodArgumentVariable:@"value"]; + // verify + assertThat(info.argumentVariable, equalTo(@"value")); + }]; +} + +- (void)testAppendMethodArgumentVariableShouldUseLastValueIfSentMultipleTimes { + [self runWithMethodArgumentInfo:^(MethodArgumentInfo *info) { + // execute + [info appendMethodArgumentVariable:@"value1"]; + [info appendMethodArgumentVariable:@"value2"]; + // verify + assertThat(info.argumentVariable, equalTo(@"value2")); + }]; +} + +@end + +#pragma mark - + +@implementation MethodArgumentInfoTests (CreationMethods) + +- (void)runWithMethodArgumentInfo:(void(^)(MethodArgumentInfo *info))handler { + MethodArgumentInfo *info = [MethodArgumentInfo new]; + handler(info); +} + +@end diff --git a/appledoc.xcodeproj/project.pbxproj b/appledoc.xcodeproj/project.pbxproj index f4a2edc4..55e7386e 100644 --- a/appledoc.xcodeproj/project.pbxproj +++ b/appledoc.xcodeproj/project.pbxproj @@ -90,6 +90,7 @@ 73D540281525A8BA00C57E1B /* StoreConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 73D540261525A8BA00C57E1B /* StoreConstants.m */; }; 73D5402A1525CBB700C57E1B /* ObjectiveCPragmaMarkStateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 73D540291525CBB700C57E1B /* ObjectiveCPragmaMarkStateTests.m */; }; 73D5402C1525D59600C57E1B /* ObjectiveCEnumStateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 73D5402B1525D59600C57E1B /* ObjectiveCEnumStateTests.m */; }; + 73D8651B153FEBD900BDAAFE /* MethodArgumentInfoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 73D8651A153FEBD900BDAAFE /* MethodArgumentInfoTests.m */; }; 73E289F21518E24D00D53484 /* ObjectiveCPropertyState.m in Sources */ = {isa = PBXBuildFile; fileRef = 73F989B71518C63D0068697C /* ObjectiveCPropertyState.m */; }; 73E289F31518E24D00D53484 /* ObjectiveCMethodState.m in Sources */ = {isa = PBXBuildFile; fileRef = 73F989BB1518C6530068697C /* ObjectiveCMethodState.m */; }; 73E289F41518E24D00D53484 /* ObjectiveCPragmaMarkState.m in Sources */ = {isa = PBXBuildFile; fileRef = 73F989BF1518C6AE0068697C /* ObjectiveCPragmaMarkState.m */; }; @@ -237,6 +238,7 @@ 73D540261525A8BA00C57E1B /* StoreConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StoreConstants.m; sourceTree = ""; }; 73D540291525CBB700C57E1B /* ObjectiveCPragmaMarkStateTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ObjectiveCPragmaMarkStateTests.m; sourceTree = ""; }; 73D5402B1525D59600C57E1B /* ObjectiveCEnumStateTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ObjectiveCEnumStateTests.m; sourceTree = ""; }; + 73D8651A153FEBD900BDAAFE /* MethodArgumentInfoTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MethodArgumentInfoTests.m; sourceTree = ""; }; 73ED9444150E9FEC0032FD07 /* Logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Logging.h; sourceTree = ""; }; 73ED9445150E9FEC0032FD07 /* Logging.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Logging.m; sourceTree = ""; }; 73ED944C150F3CF40032FD07 /* Objects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Objects.h; sourceTree = ""; }; @@ -434,6 +436,7 @@ 7349F657153ED21D004D7AC7 /* TypeInfoTests.m */, 735CD2C21538126400CADD4E /* InterfaceInfoBaseTests.m */, 733E445C153D516E0039010F /* MethodInfoTests.m */, + 73D8651A153FEBD900BDAAFE /* MethodArgumentInfoTests.m */, ); path = Store; sourceTree = ""; @@ -716,6 +719,7 @@ 731341FF153D5891002D5C54 /* TypeInfo.m in Sources */, 7349F658153ED21D004D7AC7 /* TypeInfoTests.m in Sources */, 7349F65D153EDA5C004D7AC7 /* MethodArgumentInfo.m in Sources */, + 73D8651B153FEBD900BDAAFE /* MethodArgumentInfoTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/appledoc/Store/InterfaceInfoBase.m b/appledoc/Store/InterfaceInfoBase.m index d9d2ef4b..414212a3 100644 --- a/appledoc/Store/InterfaceInfoBase.m +++ b/appledoc/Store/InterfaceInfoBase.m @@ -115,7 +115,7 @@ - (void)beginPropertyDefinition { #pragma mark - Methods - (void)beginMethodDefinitionWithType:(NSString *)type { - LogStoInfo(@"Starting %@ method definition...", type); + LogStoInfo(@"Starting %@ definition...", type); NSMutableArray *methodsArray = [self methodsArrayForType:type]; if (!methodsArray) LogWarn(@"Unsupported method type %@!", type); MethodInfo *info = [[MethodInfo alloc] initWithRegistrar:self.objectRegistrar]; diff --git a/appledoc/Store/MethodArgumentInfo.h b/appledoc/Store/MethodArgumentInfo.h index 975a3edb..9671afca 100644 --- a/appledoc/Store/MethodArgumentInfo.h +++ b/appledoc/Store/MethodArgumentInfo.h @@ -8,10 +8,16 @@ #import "ObjectInfoBase.h" +@class TypeInfo; + /** Holds data for a signle argument for a MethodInfo. An argument is composed of a selector, optional types and optional variable name. */ @interface MethodArgumentInfo : ObjectInfoBase +@property (nonatomic, strong) TypeInfo *argumentType; +@property (nonatomic, copy) NSString *argumentSelector; +@property (nonatomic, copy) NSString *argumentVariable; + @end diff --git a/appledoc/Store/MethodArgumentInfo.m b/appledoc/Store/MethodArgumentInfo.m index 41af1168..f0b0201e 100644 --- a/appledoc/Store/MethodArgumentInfo.m +++ b/appledoc/Store/MethodArgumentInfo.m @@ -6,8 +6,46 @@ // Copyright (c) 2012 Tomaz Kragelj. All rights reserved. // +#import "Objects.h" +#import "StoreRegistrations.h" +#import "TypeInfo.h" #import "MethodArgumentInfo.h" @implementation MethodArgumentInfo +@synthesize argumentType = _argumentType; +@synthesize argumentSelector = _argumentSelector; +@synthesize argumentVariable = _argumentVariable; + +#pragma mark - Properties + +- (TypeInfo *)argumentType { + if (_argumentType) return _argumentType; + LogStoDebug(@"Initializing method argument type due to first access..."); + _argumentType = [[TypeInfo alloc] init]; + return _argumentType; +} + @end + +#pragma mark - + +@implementation MethodArgumentInfo (Registrations) + +- (void)beginMethodArgumentTypes { + // Note that we don't have to respond to endCurrentObject or cancelCurrentObject to pop argumentType - Store will automatically pop it from its stack whenever either of these messages are sent to it. + LogStoVerbose(@"Starting method argument types..."); + [self pushRegistrationObject:self.argumentType]; +} + +- (void)appendMethodArgumentSelector:(NSString *)name { + LogStoInfo(@"Assigning method argument selector %@...", name); + self.argumentSelector = name; +} + +- (void)appendMethodArgumentVariable:(NSString *)name { + LogStoInfo(@"Assigning method argument variable %@...", name); + self.argumentVariable = name; +} + +@end \ No newline at end of file diff --git a/appledoc/Store/Store.m b/appledoc/Store/Store.m index 5122eb87..124a3fa7 100644 --- a/appledoc/Store/Store.m +++ b/appledoc/Store/Store.m @@ -240,7 +240,7 @@ - (void)endCurrentObject { LogStoDebug(@"Forwarding end current object to %@...", self.currentRegistrationObject); [self.currentRegistrationObject endCurrentObject]; } - LogStoInfo(@"Finalizing current object..."); + LogStoInfo(@"Finalizing %@...", self.currentRegistrationObject); [self popRegistrationObject]; } @@ -249,7 +249,7 @@ - (void)cancelCurrentObject { LogStoDebug(@"Forwarding cancel current object to %@...", self.currentRegistrationObject); [self.currentRegistrationObject cancelCurrentObject]; } - LogStoInfo(@"Cancelling current object..."); + LogStoInfo(@"Cancelling %@...", self.currentRegistrationObject); [self popRegistrationObject]; } diff --git a/appledoc/Store/StoreConstants.m b/appledoc/Store/StoreConstants.m index 9898c21e..b9a49990 100644 --- a/appledoc/Store/StoreConstants.m +++ b/appledoc/Store/StoreConstants.m @@ -9,6 +9,6 @@ #import "StoreConstants.h" const struct GBStoreTypes GBStoreTypes = { - .classMethod = @"class-method", - .instanceMethod = @"instance-method", + .classMethod = @"class method", + .instanceMethod = @"instance method", }; \ No newline at end of file