Skip to content

Commit

Permalink
Modernize code
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Apr 10, 2016
1 parent f5cfa99 commit 297d066
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
24 changes: 12 additions & 12 deletions Sources/XCDUndocumentedChecker.m
Expand Up @@ -43,8 +43,9 @@ static void XCDUndocumentedChecker_forwardInvocation(id self, SEL _cmd, NSInvoca
Class class = object_getClass([invocation target]);
while (!returnClassName && class)
{
NSDictionary *methodInfo = [classInfo objectForKey:NSStringFromClass(class)];
NSString *returnInfo = [methodInfo objectForKey:[class_isMetaClass(class) ? @"+" : @"-" stringByAppendingString:NSStringFromSelector([invocation selector])]];
NSDictionary *methodInfo = classInfo[NSStringFromClass(class)];
NSString *methodName = [class_isMetaClass(class) ? @"+" : @"-" stringByAppendingString:NSStringFromSelector([invocation selector])];
NSString *returnInfo = methodInfo[methodName];
NSArray *returnComponents = [returnInfo componentsSeparatedByString:@"."];
returnClassName = [returnComponents objectAtIndex:0];
if ([returnComponents count] == 2)
Expand Down Expand Up @@ -108,7 +109,7 @@ Class XCDClassFromProtocol(Protocol *protocol, NSError **error)
if (error)
*error = nil;

NSString *className = protocol ? [NSString stringWithCString:protocol_getName(protocol) encoding:NSUTF8StringEncoding] : @"nil";
NSString *className = protocol ? @(protocol_getName(protocol)) : @"nil";
Class class = NSClassFromString(className);
if (!class)
{
Expand Down Expand Up @@ -154,9 +155,8 @@ Class XCDClassFromProtocol(Protocol *protocol, NSError **error)
methods = class_copyMethodList(isInstanceMethod ? class : object_getClass(class), &methodCount);
for (unsigned int i = 0; i < methodCount; i++)
{
const char *methodName = sel_getName(method_getName(methods[i]));
const char *typeEncoding = method_getTypeEncoding(methods[i]);
[methodSignatures setObject:[NSString stringWithUTF8String:typeEncoding] forKey:[NSString stringWithFormat:@"%c%s", isInstanceMethod ? '-':'+', methodName]];
NSString *methodName = [NSString stringWithFormat:@"%c%s", isInstanceMethod ? '-':'+', sel_getName(method_getName(methods[i]))];
methodSignatures[methodName] = @(method_getTypeEncoding(methods[i]));
}
free(methods);
}
Expand Down Expand Up @@ -195,8 +195,8 @@ Class XCDClassFromProtocol(Protocol *protocol, NSError **error)
{
SEL selector = protocolMethods[i].name;
NSString *methodName = [isInstanceMethod ? @"-" : @"+" stringByAppendingFormat:@"%s", sel_getName(selector)];
NSString *methodSignature = [methodSignatures objectForKey:methodName];
NSString *expectedSignature = [NSString stringWithUTF8String:protocolMethods[i].types];
NSString *methodSignature = methodSignatures[methodName];
NSString *expectedSignature = @(protocolMethods[i].types);
BOOL signatureMatch = [expectedSignature isEqualToString:methodSignature];
if (!signatureMatch)
{
Expand Down Expand Up @@ -265,15 +265,15 @@ Class XCDClassFromProtocol(Protocol *protocol, NSError **error)
{
NSMutableDictionary *errorInfo = [NSMutableDictionary dictionary];
if ([methodsNotFound count] > 0)
[errorInfo setObject:methodsNotFound forKey:XCDUndocumentedCheckerMissingMethodsKey];
errorInfo[XCDUndocumentedCheckerMissingMethodsKey] = methodsNotFound;
if ([methodsMismatch count] > 0)
[errorInfo setObject:methodsMismatch forKey:XCDUndocumentedCheckerMismatchingMethodsKey];
errorInfo[XCDUndocumentedCheckerMismatchingMethodsKey] = methodsMismatch;
if ([hierarchyMismatch count] > 0)
[errorInfo setObject:hierarchyMismatch forKey:XCDUndocumentedCheckerMismatchingHierarchyKey];
errorInfo[XCDUndocumentedCheckerMismatchingHierarchyKey] = hierarchyMismatch;

if ([errorInfo count] > 0)
{
[errorInfo setObject:[NSString stringWithFormat:@"Methods of class %@ do not match %@ protocol", className, NSStringFromProtocol(protocol)] forKey:NSLocalizedDescriptionKey];
errorInfo[NSLocalizedDescriptionKey] = [NSString stringWithFormat:@"Methods of class %@ do not match %@ protocol", className, NSStringFromProtocol(protocol)];
*error = [NSError errorWithDomain:XCDUndocumentedCheckerErrorDomain code:XCDUndocumentedCheckerMethodMismatch userInfo:errorInfo];
}
}
Expand Down
18 changes: 12 additions & 6 deletions Sources/Xcproj.m
Expand Up @@ -202,7 +202,7 @@ + (void) initializeXcproj
NSError *classError = nil;
Class class = XCDClassFromProtocol(protocol, &classError);
if (class)
[self setValue:class forKey:[NSString stringWithCString:protocol_getName(protocol) encoding:NSUTF8StringEncoding]];
[self setValue:class forKey:@(protocol_getName(protocol))];
else
{
isSafe = NO;
Expand Down Expand Up @@ -348,7 +348,7 @@ - (int) application:(DDCliApplication *)app runWithArguments:(NSArray *)argument
if ([arguments count] >= 2)
actionArguments = [arguments subarrayWithRange:NSMakeRange(1, [arguments count] - 1)];
else
actionArguments = [NSArray array];
actionArguments = @[];

NSArray *actionParts = [[action componentsSeparatedByString:@"-"] valueForKeyPath:@"capitalizedString"];
NSMutableString *selectorString = [NSMutableString stringWithString:[actionParts componentsJoinedByString:@""]];
Expand All @@ -362,7 +362,13 @@ - (int) application:(DDCliApplication *)app runWithArguments:(NSArray *)argument

- (NSArray *) allowedActions
{
return [NSArray arrayWithObjects:@"list-targets", @"list-headers", @"read-build-setting", @"write-build-setting", @"add-xcconfig", @"add-resources-bundle", @"touch", nil];
return @[ @"list-targets",
@"list-headers",
@"read-build-setting",
@"write-build-setting",
@"add-xcconfig",
@"add-resources-bundle",
@"touch" ];
}

- (void) printUsage:(int)exitCode
Expand Down Expand Up @@ -412,7 +418,7 @@ - (NSNumber *) listHeaders:(NSArray *)arguments
if ([arguments count] == 1)
headerRole = [[arguments objectAtIndex:0] capitalizedString];

NSArray *allowedValues = [NSArray arrayWithObjects:@"All", @"Public", @"Project", @"Private", nil];
NSArray *allowedValues = @[ @"All", @"Public", @"Project", @"Private" ];
if (![allowedValues containsObject:headerRole])
@throw [DDCliParseException parseExceptionWithReason:[NSString stringWithFormat:@"list-headers argument must be one of {%@}.", [allowedValues componentsJoinedByString:@", "]] exitCode:EX_USAGE];

Expand Down Expand Up @@ -541,7 +547,7 @@ - (NSNumber *) touch:(NSArray *)arguments
/*
- (void) printBuildPhases
{
for (NSString *buildPhase in [NSArray arrayWithObjects:@"Frameworks", @"Link", @"SourceCode", @"Resource", @"Header", nil])
for (NSString *buildPhase in @[ @"Frameworks", @"Link", @"SourceCode", @"Resource", @"Header" ])
{
ddprintf(@"%@\n", buildPhase);
SEL buildPhaseSelector = NSSelectorFromString([NSString stringWithFormat:@"default%@BuildPhase", buildPhase]);
Expand Down Expand Up @@ -628,7 +634,7 @@ - (void) addGroupNamed:(NSString *)groupName inGroupNamed:(NSString *)otherGroup
id<PBXFileReference> fileReference = [_project fileReferenceForPath:filePath];
if (!fileReference)
{
NSArray *references = [[_project rootGroup] addFiles:[NSArray arrayWithObject:filePath] copy:NO createGroupsRecursively:NO];
NSArray *references = [[_project rootGroup] addFiles:@[ filePath ] copy:NO createGroupsRecursively:NO];
fileReference = [references lastObject];
}
return fileReference;
Expand Down

0 comments on commit 297d066

Please sign in to comment.