Skip to content

Commit

Permalink
Categories and extensions are now linked with the class they extend.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaz committed Dec 10, 2012
1 parent 07dd791 commit 61dfc5f
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 18 deletions.
76 changes: 64 additions & 12 deletions AppledocTests/Processing/LinkKnownObjectsTaskTests.mm
Expand Up @@ -39,6 +39,12 @@ static id createClass(NSString *name) {
return result;
}

static id createCategory(void(^handler)(CategoryInfo *info)) {
CategoryInfo *result = [[CategoryInfo alloc] init];
handler(result);
return result;
}

static id createProtocol(void(^handler)(ProtocolInfo *info)) {
ProtocolInfo *result = [[ProtocolInfo alloc] init];
handler(result);
Expand All @@ -51,11 +57,15 @@ static id createProtocol(NSString *name) {
return result;
}

static void derive(ClassInfo *object, NSString *name) {
static void deriveClass(ClassInfo *object, NSString *name) {
object.classSuperClass.nameOfObject = name;
}

static void adopt(InterfaceInfoBase *interface, NSString *first, ...) {
static void extendClass(CategoryInfo *object, NSString *name) {
object.categoryClass.nameOfObject = name;
}

static void adoptProtocols(InterfaceInfoBase *interface, NSString *first, ...) {
va_list args;
va_start(args, first);
for (NSString *arg=first; arg!=nil; arg=va_arg(args, NSString *)) {
Expand All @@ -76,7 +86,7 @@ static void adopt(InterfaceInfoBase *interface, NSString *first, ...) {
runWithTask(^(LinkKnownObjectsTask *task, id store) {
// setup
InterfaceInfoBase *class1 = createInterface(^(InterfaceInfoBase *interface) {
adopt(interface, @"MyProtocol1", @"MyProtocol2", @"UnknownProtocol", nil);
adoptProtocols(interface, @"MyProtocol1", @"MyProtocol2", @"UnknownProtocol", nil);
});
id protocol1 = createProtocol(@"MyProtocol1");
id protocol2 = createProtocol(@"MyProtocol2");
Expand All @@ -95,8 +105,8 @@ static void adopt(InterfaceInfoBase *interface, NSString *first, ...) {
it(@"should link extensions to known protocols", ^{
runWithTask(^(LinkKnownObjectsTask *task, id store) {
// setup
InterfaceInfoBase *extension1 = createInterface(^(InterfaceInfoBase *interface) {
adopt(interface, @"MyProtocol1", @"MyProtocol2", @"UnknownProtocol", nil);
InterfaceInfoBase *extension1 = createCategory(^(CategoryInfo *interface) {
adoptProtocols(interface, @"MyProtocol1", @"MyProtocol2", @"UnknownProtocol", nil);
});
id protocol1 = createProtocol(@"MyProtocol1");
id protocol2 = createProtocol(@"MyProtocol2");
Expand All @@ -114,8 +124,8 @@ static void adopt(InterfaceInfoBase *interface, NSString *first, ...) {
it(@"should link categories to known protocols", ^{
runWithTask(^(LinkKnownObjectsTask *task, id store) {
// setup
InterfaceInfoBase *category1 = createInterface(^(InterfaceInfoBase *interface) {
adopt(interface, @"MyProtocol1", @"MyProtocol2", @"UnknownProtocol", nil);
InterfaceInfoBase *category1 = createCategory(^(CategoryInfo *interface) {
adoptProtocols(interface, @"MyProtocol1", @"MyProtocol2", @"UnknownProtocol", nil);
});
id protocol1 = createProtocol(@"MyProtocol1");
id protocol2 = createProtocol(@"MyProtocol2");
Expand All @@ -134,7 +144,7 @@ static void adopt(InterfaceInfoBase *interface, NSString *first, ...) {
runWithTask(^(LinkKnownObjectsTask *task, id store) {
// setup
ProtocolInfo *protocol1 = createProtocol(^(ProtocolInfo *info) {
adopt(info, @"MyProtocol1", @"MyProtocol2", @"UnknownProtocol", nil);
adoptProtocols(info, @"MyProtocol1", @"MyProtocol2", @"UnknownProtocol", nil);
});
id protocol2 = createProtocol(@"MyProtocol1");
id protocol3 = createProtocol(@"MyProtocol2");
Expand All @@ -154,7 +164,7 @@ static void adopt(InterfaceInfoBase *interface, NSString *first, ...) {
runWithTask(^(LinkKnownObjectsTask *task, id store) {
// setup
ClassInfo *class1 = createClass(^(ClassInfo *info) {
derive(info, @"MyBaseClass");
deriveClass(info, @"MyBaseClass");
});
id class2 = createClass(@"MyBaseClass");
[given([store storeClasses]) willReturn:@[ class1, class2 ]];
Expand All @@ -170,15 +180,15 @@ static void adopt(InterfaceInfoBase *interface, NSString *first, ...) {
// setup
ClassInfo *class1 = createClass(^(ClassInfo *info) {
info.nameOfClass = @"Class1";
derive(info, @"Class2");
deriveClass(info, @"Class2");
});
ClassInfo *class2 = createClass(^(ClassInfo *info) {
info.nameOfClass = @"Class2";
derive(info, @"Class3");
deriveClass(info, @"Class3");
});
ClassInfo *class3 = createClass(^(ClassInfo *info) {
info.nameOfClass = @"Class3";
derive(info, @"Unknown");
deriveClass(info, @"Unknown");
});
[given([store storeClasses]) willReturn:@[ class1, class2, class3 ]];
// execute
Expand All @@ -191,4 +201,46 @@ static void adopt(InterfaceInfoBase *interface, NSString *first, ...) {
});
});

describe(@"category classes:", ^{
it(@"should link extensions to known classes", ^{
runWithTask(^(LinkKnownObjectsTask *task, id store) {
// setup
CategoryInfo *extension1 = createCategory(^(CategoryInfo *info) {
extendClass(info, @"Class1");
});
CategoryInfo *extension2 = createCategory(^(CategoryInfo *info) {
extendClass(info, @"UnknownClass");
});
ClassInfo *class1 = createClass(@"Class1");
[given([store storeExtensions]) willReturn:@[ extension1, extension2 ]];
[given([store storeClasses]) willReturn:@[ class1 ]];
// execute
[task runTask];
// verify
extension1.categoryClass.linkToObject should equal(class1);
extension2.categoryClass.linkToObject should be_nil();
});
});

it(@"should link categories to known classes", ^{
runWithTask(^(LinkKnownObjectsTask *task, id store) {
// setup
CategoryInfo *category1 = createCategory(^(CategoryInfo *info) {
extendClass(info, @"Class1");
});
CategoryInfo *category2 = createCategory(^(CategoryInfo *info) {
extendClass(info, @"UnknownClass");
});
ClassInfo *class1 = createClass(@"Class1");
[given([store storeCategories]) willReturn:@[ category1, category2 ]];
[given([store storeClasses]) willReturn:@[ class1 ]];
// execute
[task runTask];
// verify
category1.categoryClass.linkToObject should equal(class1);
category2.categoryClass.linkToObject should be_nil();
});
});
});

TEST_END
24 changes: 18 additions & 6 deletions appledoc/Processing/LinkKnownObjectsTask.m
Expand Up @@ -36,18 +36,20 @@ - (void)handleClassesFromStore:(Store *)store {
- (void)handleExtensionsFromStore:(Store *)store {
LogDebug(@"Preparing links for classes...");
__weak LinkKnownObjectsTask *bself = self;
[store.storeExtensions enumerateObjectsUsingBlock:^(CategoryInfo *class, NSUInteger idx, BOOL *stop) {
LogDebug(@"Handling %@...", class);
[bself handleAdoptedProtocolsForInterface:class store:store];
[store.storeExtensions enumerateObjectsUsingBlock:^(CategoryInfo *extension, NSUInteger idx, BOOL *stop) {
LogDebug(@"Handling %@...", extension);
[bself handleExtendedClassesForCategory:extension store:store];
[bself handleAdoptedProtocolsForInterface:extension store:store];
}];
}

- (void)handleCategoriesFromStore:(Store *)store {
LogDebug(@"Preparing links for classes...");
__weak LinkKnownObjectsTask *bself = self;
[store.storeCategories enumerateObjectsUsingBlock:^(CategoryInfo *class, NSUInteger idx, BOOL *stop) {
LogDebug(@"Handling %@...", class);
[bself handleAdoptedProtocolsForInterface:class store:store];
[store.storeCategories enumerateObjectsUsingBlock:^(CategoryInfo *category, NSUInteger idx, BOOL *stop) {
LogDebug(@"Handling %@...", category);
[bself handleExtendedClassesForCategory:category store:store];
[bself handleAdoptedProtocolsForInterface:category store:store];
}];
}

Expand All @@ -73,6 +75,16 @@ - (void)handleSuperClassesForClass:(ClassInfo *)class store:(Store *)store {
}];
}

- (void)handleExtendedClassesForCategory:(CategoryInfo *)category store:(Store *)store {
if (category.categoryClass.nameOfObject.length == 0) return;
[store.storeClasses enumerateObjectsUsingBlock:^(ClassInfo *testedClass, NSUInteger idx, BOOL *stop) {
if (![testedClass.nameOfClass isEqualToString:category.nameOfClass]) return;
LogDebug(@"Found link to extended class %@.", testedClass);
category.categoryClass.linkToObject = testedClass;
*stop = YES;
}];
}

- (void)handleAdoptedProtocolsForInterface:(InterfaceInfoBase *)interface store:(Store *)store {
LogDebug(@"Handling adopted protocols...");
[interface.interfaceAdoptedProtocols enumerateObjectsUsingBlock:^(ObjectLinkInfo *link, NSUInteger idx, BOOL *stop) {
Expand Down

0 comments on commit 61dfc5f

Please sign in to comment.