main
 1//
 2// Licensed under the terms in License.txt
 3//
 4// Copyright 2010 Allen Ding. All rights reserved.
 5//
 6
 7#import "KWPendingNode.h"
 8#import "KWExampleNodeVisitor.h"
 9#import "KWContextNode.h"
10
11@implementation KWPendingNode
12
13@synthesize context = _context;
14
15#pragma mark -
16#pragma mark Initializing
17
18- (id)initWithCallSite:(KWCallSite *)aCallSite context:(KWContextNode *)context description:(NSString *)aDescription {
19    if ((self = [super init])) {
20        callSite = [aCallSite retain];
21        description = [aDescription copy];
22        _context = [context retain];
23    }
24
25    return self;
26}
27
28+ (id)pendingNodeWithCallSite:(KWCallSite *)aCallSite context:(KWContextNode *)context description:(NSString *)aDescription {
29    return [[[self alloc] initWithCallSite:aCallSite context:context description:aDescription] autorelease];
30}
31
32- (void)dealloc {
33    [_context release];
34    [callSite release];
35    [description release];
36    [super dealloc];
37}
38
39#pragma mark -
40#pragma mark Getting Call Sites
41
42@synthesize callSite;
43
44#pragma mark -
45#pragma mark Getting Descriptions
46
47@synthesize description;
48
49#pragma mark -
50#pragma mark Accepting Visitors
51
52- (void)acceptExampleNodeVisitor:(id<KWExampleNodeVisitor>)aVisitor {
53    [aVisitor visitPendingNode:self];
54}
55
56#pragma mark -
57#pragma mark - Accessing the context stack
58
59- (NSArray *)contextStack
60{
61    NSMutableArray *contextStack = [NSMutableArray array];
62    
63    KWContextNode *currentContext = _context;
64    
65    while (currentContext) {
66        [contextStack addObject:currentContext];
67        currentContext = currentContext.parentContext;
68    }
69    return contextStack;
70}
71
72@end