From 1bece88f408838fbc852a894faeefae60fae9b19 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 2 Dec 2015 08:39:12 -0500 Subject: [PATCH] Modernize VariableNode for ObjC 2.0. --- Source/VariableNode.h | 30 +++++---------- Source/VariableNode.m | 89 +++++++++++++++++-------------------------- 2 files changed, 44 insertions(+), 75 deletions(-) diff --git a/Source/VariableNode.h b/Source/VariableNode.h index c9d7f4b..4a8c2bc 100644 --- a/Source/VariableNode.h +++ b/Source/VariableNode.h @@ -21,29 +21,19 @@ // information. The fields of this class are defined by the spec: // http://www.xdebug.org/docs-dbgp.php#properties-variables-and-values @interface VariableNode : NSObject -{ - NSString* name_; - NSString* fullName_; - NSString* className_; - NSString* type_; - NSString* value_; - NSMutableArray* children_; - NSInteger childCount_; - NSString* address_; -} - -@property (readonly, copy) NSString* name; -@property (readonly, copy) NSString* fullName; -@property (readonly, copy) NSString* className; -@property (readonly, copy) NSString* type; -@property (readonly, copy) NSString* value; -@property (readonly, retain) NSArray* children; -@property (readonly) NSInteger childCount; -@property (readonly, copy) NSString* address; + +@property(readonly, nonatomic) NSString* name; +@property(readonly, nonatomic) NSString* fullName; +@property(readonly, nonatomic) NSString* className; +@property(readonly, nonatomic) NSString* type; +@property(readonly, nonatomic) NSString* value; +@property(readonly, nonatomic) NSArray* children; +@property(readonly, nonatomic) NSInteger childCount; +@property(readonly, nonatomic) NSString* address; // Creates and initializes a new VariableNode from the XML response from the // debugger backend. -- (id)initWithXMLNode:(NSXMLElement*)node; +- (instancetype)initWithXMLNode:(NSXMLElement*)node; // When properties are asynchrnously loaded, this method can be used to set // the children on a node from the list of children from the XML response. diff --git a/Source/VariableNode.m b/Source/VariableNode.m index 6775747..80a62f4 100644 --- a/Source/VariableNode.m +++ b/Source/VariableNode.m @@ -18,68 +18,50 @@ #include "NSXMLElementAdditions.h" -// Private Properties ////////////////////////////////////////////////////////// - -@interface VariableNode () - -@property (copy) NSString* name; -@property (copy) NSString* fullName; -@property (copy) NSString* className; -@property (copy) NSString* type; -@property (copy) NSString* value; -@property (retain) NSArray* children; -@property (copy) NSString* address; - -@end - -//////////////////////////////////////////////////////////////////////////////// - -@implementation VariableNode +@implementation VariableNode { + NSMutableArray* _children; +} -@synthesize name = name_; -@synthesize fullName = fullName_; -@synthesize className = className_; -@synthesize type = type_; -@synthesize value = value_; -@synthesize children = children_; -@synthesize childCount = childCount_; -@synthesize address = address_; +@synthesize name = _name; +@synthesize fullName = _fullName; +@synthesize className = _className; +@synthesize type = _type; +@synthesize value = _value; +@synthesize childCount = _childCount; +@synthesize address = _address; -- (id)initWithXMLNode:(NSXMLElement*)node -{ +- (id)initWithXMLNode:(NSXMLElement*)node { if (self = [super init]) { - self.name = [[node attributeForName:@"name"] stringValue]; - self.fullName = [[node attributeForName:@"fullname"] stringValue]; - self.className = [[node attributeForName:@"classname"] stringValue]; - self.type = [[node attributeForName:@"type"] stringValue]; - self.value = [node base64DecodedValue]; - self.children = [NSMutableArray array]; + _name = [[[node attributeForName:@"name"] stringValue] copy]; + _fullName = [[[node attributeForName:@"fullname"] stringValue] copy]; + _className = [[[node attributeForName:@"classname"] stringValue] copy]; + _type = [[[node attributeForName:@"type"] stringValue] copy]; + _value = [[node base64DecodedValue] copy]; + _children = [[NSMutableArray alloc] init]; if ([node children]) { [self setChildrenFromXMLChildren:[node children]]; } - childCount_ = [[[node attributeForName:@"numchildren"] stringValue] integerValue]; - self.address = [[node attributeForName:@"address"] stringValue]; + _childCount = [[[node attributeForName:@"numchildren"] stringValue] integerValue]; + _address = [[[node attributeForName:@"address"] stringValue] copy]; } return self; } -- (void)dealloc -{ - self.name = nil; - self.fullName = nil; - self.className = nil; - self.type = nil; - self.value = nil; - self.children = nil; - self.address = nil; +- (void)dealloc { + [_name release]; + [_fullName release]; + [_className release]; + [_type release]; + [_value release]; + [_children release]; + [_address release]; [super dealloc]; } -- (void)setChildrenFromXMLChildren:(NSArray*)children -{ +- (void)setChildrenFromXMLChildren:(NSArray*)children { [self willChangeValueForKey:@"children"]; - [children_ removeAllObjects]; + [_children removeAllObjects]; for (NSXMLNode* child in children) { // Other child nodes may be the string value. @@ -88,7 +70,7 @@ // Don't include the CLASSNAME property as that information is retreeived // elsewhere. if (![node.name isEqualToString:@"CLASSNAME"]) - [children_ addObject:node]; + [_children addObject:node]; [node release]; } } @@ -96,21 +78,18 @@ [self didChangeValueForKey:@"children"]; } -- (BOOL)isLeaf -{ - return (self.childCount == 0); +- (BOOL)isLeaf { + return self.childCount == 0; } -- (NSString*)displayType -{ +- (NSString*)displayType { if (self.className != nil) { return [NSString stringWithFormat:@"%@ (%@)", self.className, self.type]; } return self.type; } -- (NSString*)description -{ +- (NSString*)description { return [NSString stringWithFormat:@"", self, self.fullName]; } -- 2.22.5