Permalink
Browse files

Merge pull request #1 from tomohisa/master

It looks more useful. Thank you so much.
  • Loading branch information...
2 parents 90f2f77 + 0715e82 commit 990778b471517e5b29e21395534ce16ef20e2b09 @kishikawakatsumi committed Feb 26, 2012
Showing with 23 additions and 1 deletion.
  1. +2 −0 Classes/DescriptionBuilder.h
  2. +21 −1 Classes/DescriptionBuilder.m
@@ -20,5 +20,7 @@ typedef enum DescriptionStyle {
+ (NSString *)reflectDescription:(id)obj;
+ (NSString *)reflectDescription:(id)obj style:(DescriptionStyle)style;
++ (NSString *)reflectDescriptionWithSuperClass:(id)obj;
++ (NSString *)reflectDescriptionWithSuperClass:(id)obj style:(DescriptionStyle)style;
@end
@@ -9,12 +9,25 @@
#import "DescriptionBuilder.h"
#import <objc/runtime.h>
+@interface DescriptionBuilder()
++ (NSString *)reflectDescription:(id)obj style:(DescriptionStyle)style targetClass:(Class)cls withSuperClass:(BOOL) superClassFlag;
+@end
+
@implementation DescriptionBuilder
+ (NSString *)reflectDescription:(id)obj {
return [DescriptionBuilder reflectDescription:obj style:DescriptionStyleDefault];
}
++ (NSString *)reflectDescriptionWithSuperClass:(id)obj {
+ return [DescriptionBuilder reflectDescription:obj style:DescriptionStyleDefault targetClass:[obj class] withSuperClass:YES];
+}
+
++ (NSString *)reflectDescriptionWithSuperClass:(id)obj style:(DescriptionStyle)style {
+ return [DescriptionBuilder reflectDescription:obj style:style targetClass:[obj class] withSuperClass:YES];
+}
+
+
/**
c char
C unsigned char
@@ -37,6 +50,9 @@ + (NSString *)reflectDescription:(id)obj {
{ 構造体
*/
+ (NSString *)reflectDescription:(id)obj style:(DescriptionStyle)style {
+ return [DescriptionBuilder reflectDescription:obj style:style targetClass:[obj class] withSuperClass:NO];
+}
++ (NSString *)reflectDescription:(id)obj style:(DescriptionStyle)style targetClass:(Class)cls withSuperClass:(BOOL) superClassFlag{
id objValue;
Class classValue;
SEL selValue;
@@ -57,7 +73,7 @@ + (NSString *)reflectDescription:(id)obj style:(DescriptionStyle)style {
NSMutableString *description = [[[NSMutableString alloc] init] autorelease];
- Class clazz = [obj class];
+ Class clazz = cls;
unsigned int outCount = 0;
Ivar *ivars = class_copyIvarList(clazz, &outCount);
@@ -230,6 +246,10 @@ + (NSString *)reflectDescription:(id)obj style:(DescriptionStyle)style {
break;
}
}
+ if (superClassFlag && class_getSuperclass(cls)) {
+ [description appendString:@"\n"];
+ [description appendString:[DescriptionBuilder reflectDescription:obj style:style targetClass:class_getSuperclass(cls) withSuperClass:superClassFlag]];
+ }
[description appendString:@">"];
if (outCount > 0) { free(ivars); }
return description;

0 comments on commit 990778b

Please sign in to comment.