Skip to content

Commit

Permalink
Added method arguments registration.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaz committed Apr 19, 2012
1 parent a48f79f commit 393811e
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 5 deletions.
98 changes: 98 additions & 0 deletions 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
4 changes: 4 additions & 0 deletions appledoc.xcodeproj/project.pbxproj
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -237,6 +238,7 @@
73D540261525A8BA00C57E1B /* StoreConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StoreConstants.m; sourceTree = "<group>"; };
73D540291525CBB700C57E1B /* ObjectiveCPragmaMarkStateTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ObjectiveCPragmaMarkStateTests.m; sourceTree = "<group>"; };
73D5402B1525D59600C57E1B /* ObjectiveCEnumStateTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ObjectiveCEnumStateTests.m; sourceTree = "<group>"; };
73D8651A153FEBD900BDAAFE /* MethodArgumentInfoTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MethodArgumentInfoTests.m; sourceTree = "<group>"; };
73ED9444150E9FEC0032FD07 /* Logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Logging.h; sourceTree = "<group>"; };
73ED9445150E9FEC0032FD07 /* Logging.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Logging.m; sourceTree = "<group>"; };
73ED944C150F3CF40032FD07 /* Objects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Objects.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -434,6 +436,7 @@
7349F657153ED21D004D7AC7 /* TypeInfoTests.m */,
735CD2C21538126400CADD4E /* InterfaceInfoBaseTests.m */,
733E445C153D516E0039010F /* MethodInfoTests.m */,
73D8651A153FEBD900BDAAFE /* MethodArgumentInfoTests.m */,
);
path = Store;
sourceTree = "<group>";
Expand Down Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion appledoc/Store/InterfaceInfoBase.m
Expand Up @@ -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];
Expand Down
6 changes: 6 additions & 0 deletions appledoc/Store/MethodArgumentInfo.h
Expand Up @@ -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
38 changes: 38 additions & 0 deletions appledoc/Store/MethodArgumentInfo.m
Expand Up @@ -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
4 changes: 2 additions & 2 deletions appledoc/Store/Store.m
Expand Up @@ -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];
}

Expand All @@ -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];
}

Expand Down
4 changes: 2 additions & 2 deletions appledoc/Store/StoreConstants.m
Expand Up @@ -9,6 +9,6 @@
#import "StoreConstants.h"

const struct GBStoreTypes GBStoreTypes = {
.classMethod = @"class-method",
.instanceMethod = @"instance-method",
.classMethod = @"class method",
.instanceMethod = @"instance method",
};

0 comments on commit 393811e

Please sign in to comment.