Permalink
Browse files

Added support for proxy objects (still experimental)

  • Loading branch information...
1 parent 64a803b commit c7ea63ff6d00e203173e088d094a4c637d842b59 Adrian Kosmaczewski committed Nov 7, 2011
@@ -21,6 +21,7 @@
3A13EA0E14683C4C0099DE03 /* GLKViewControllerProcessor.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A13EA0D14683C4B0099DE03 /* GLKViewControllerProcessor.m */; };
3A13EA1114683F500099DE03 /* UITapGestureRecognizerProcessor.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A13EA1014683F4E0099DE03 /* UITapGestureRecognizerProcessor.m */; };
3A13EA14146840460099DE03 /* GLKViewProcessor.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A13EA13146840450099DE03 /* GLKViewProcessor.m */; };
+ 3A13EA171468437D0099DE03 /* ProxyObjectProcessor.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A13EA161468437B0099DE03 /* ProxyObjectProcessor.m */; };
3A527B4C12006FAD00F0986C /* MGSFragaria.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3ACD6E2A120067A2006C9D8E /* MGSFragaria.framework */; };
3A92DE6311F308C300E0EF30 /* nib2objc.icns in Resources */ = {isa = PBXBuildFile; fileRef = 3A92DE6211F308C300E0EF30 /* nib2objc.icns */; };
3A92E20211F3153000E0EF30 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A92E20111F3153000E0EF30 /* AppDelegate.m */; };
@@ -146,6 +147,8 @@
3A13EA1014683F4E0099DE03 /* UITapGestureRecognizerProcessor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UITapGestureRecognizerProcessor.m; sourceTree = "<group>"; };
3A13EA12146840430099DE03 /* GLKViewProcessor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLKViewProcessor.h; sourceTree = "<group>"; };
3A13EA13146840450099DE03 /* GLKViewProcessor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLKViewProcessor.m; sourceTree = "<group>"; };
+ 3A13EA15146843790099DE03 /* ProxyObjectProcessor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProxyObjectProcessor.h; sourceTree = "<group>"; };
+ 3A13EA161468437B0099DE03 /* ProxyObjectProcessor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProxyObjectProcessor.m; sourceTree = "<group>"; };
3A92DE6211F308C300E0EF30 /* nib2objc.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = nib2objc.icns; sourceTree = "<group>"; };
3A92E20011F3153000E0EF30 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
3A92E20111F3153000E0EF30 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
@@ -443,6 +446,8 @@
3A13EA1014683F4E0099DE03 /* UITapGestureRecognizerProcessor.m */,
3A13EA12146840430099DE03 /* GLKViewProcessor.h */,
3A13EA13146840450099DE03 /* GLKViewProcessor.m */,
+ 3A13EA15146843790099DE03 /* ProxyObjectProcessor.h */,
+ 3A13EA161468437B0099DE03 /* ProxyObjectProcessor.m */,
);
path = Processors;
sourceTree = "<group>";
@@ -592,6 +597,7 @@
3A13EA0E14683C4C0099DE03 /* GLKViewControllerProcessor.m in Sources */,
3A13EA1114683F500099DE03 /* UITapGestureRecognizerProcessor.m in Sources */,
3A13EA14146840460099DE03 /* GLKViewProcessor.m in Sources */,
+ 3A13EA171468437D0099DE03 /* ProxyObjectProcessor.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -125,13 +125,13 @@ - (void)process
if (processor == nil)
{
-//#ifdef CONFIGURATION_Debug
+#ifdef CONFIGURATION_Debug
// Get notified about classes not yet handled by this utility
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:klass forKey:@"// unknown object (yet)"];
[objects setObject:dict forKey:key];
[dict release];
-//#endif
+#endif
}
else
{
@@ -143,9 +143,10 @@ - (void)process
// Let's print everything as source code
[_output release];
_output = [[NSMutableString alloc] init];
- for (NSDictionary *identifier in objects)
+ for (NSString *identifier in objects)
{
id object = [objects objectForKey:identifier];
+ NSString *identifierKey = [[identifier stringByReplacingOccurrencesOfString:@"-" withString:@""] lowercaseString];
// First, output any helper functions, ordered alphabetically
NSArray *orderedKeys = [object keysSortedByValueUsingSelector:@selector(caseInsensitiveCompare:)];
@@ -163,7 +164,7 @@ - (void)process
id klass = [object objectForKey:@"class"];
id constructor = [object objectForKey:@"constructor"];
NSString *instanceName = [self instanceNameForObject:object];
- [_output appendFormat:@"%@ *%@%@ = %@;\n", klass, instanceName, identifier, constructor];
+ [_output appendFormat:@"%@ *%@%@ = %@;\n", klass, instanceName, identifierKey, constructor];
// Then, output the properties only, ordered alphabetically
orderedKeys = [[object allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
@@ -177,11 +178,11 @@ - (void)process
switch (self.codeStyle)
{
case NibProcessorCodeStyleProperties:
- [_output appendFormat:@"%@%@.%@ = %@;\n", instanceName, identifier, key, value];
+ [_output appendFormat:@"%@%@.%@ = %@;\n", instanceName, identifierKey, key, value];
break;
case NibProcessorCodeStyleSetter:
- [_output appendFormat:@"[%@%@ set%@:%@];\n", instanceName, identifier, [key capitalize], value];
+ [_output appendFormat:@"[%@%@ set%@:%@];\n", instanceName, identifierKey, [key capitalize], value];
break;
default:
@@ -197,7 +198,7 @@ - (void)process
id value = [object objectForKey:key];
if ([key hasPrefix:@"__method__"])
{
- [_output appendFormat:@"[%@%@ %@];\n", instanceName, identifier, value];
+ [_output appendFormat:@"[%@%@ %@];\n", instanceName, identifierKey, value];
}
}
[_output appendString:@"\n"];
@@ -48,6 +48,7 @@
#import "GLKViewControllerProcessor.h"
#import "UITapGestureRecognizerProcessor.h"
#import "GLKViewProcessor.h"
+#import "ProxyObjectProcessor.h"
@interface Processor (Protected)
@@ -101,6 +102,7 @@ + (Processor *)processorForClass:(NSString *)klass
else if ([klass isEqualToString:@"IBGLKViewController"]) processor = [[GLKViewControllerProcessor alloc] init];
else if ([klass isEqualToString:@"IBUITapGestureRecognizer"]) processor = [[UITapGestureRecognizerProcessor alloc] init];
else if ([klass isEqualToString:@"IBGLKView"]) processor = [[GLKViewProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBProxyObject"]) processor = [[ProxyObjectProcessor alloc] init];
return [processor autorelease];
}
@@ -142,7 +144,9 @@ - (id)init
@"edgeInsetsContent",
@"edgeInsetsImage",
@"edgeInsetsTitle",
- @"highlightedColor", nil];
+ @"highlightedColor",
+ @"proxiedObjectIdentifier",
+ @"ibExternalCustomClassName", nil];
}
return self;
}
@@ -163,30 +167,33 @@ - (NSDictionary *)processObject:(NSDictionary *)object
input = [object retain];
[output release];
output = [[NSMutableDictionary alloc] init];
- [output setObject:[self constructorString] forKey:@"constructor"];
-
- NSString *frameString = [self frameString];
- if (nil != frameString)
- {
- [output setObject:frameString forKey:@"frame"];
- }
for (id item in input)
{
id value = [input objectForKey:item];
[self processKey:item value:value];
-//#ifdef CONFIGURATION_Debug
+#ifdef CONFIGURATION_Debug
// This will show properties not yet known by nib2objc
if ([output objectForKey:item] == nil &&
![ignoredProperties containsObject:item])
{
id object = [NSString stringWithFormat:@"// unknown property: %@", value];
[output setObject:object forKey:item];
}
-//#endif
+#endif
}
+
+ // Because of proxy objects, this call should be done at the end
+ // when all the properties of the object have been parsed
+ [output setObject:[self constructorString] forKey:@"constructor"];
+ NSString *frameString = [self frameString];
+ if (nil != frameString)
+ {
+ [output setObject:frameString forKey:@"frame"];
+ }
+
return output;
}
@@ -197,15 +204,14 @@ - (void)processKey:(id)item value:(id)value
- (NSString *)frameString
{
- NSString *rect = [NSString rectStringFromPoint:[self.input objectForKey:@"frameOrigin"] size:[self.input objectForKey:@"frameSize"]];
- return rect;
+ return nil;
}
- (NSString *)constructorString
{
// Some subclasses have different constructors than the classic
// "initWithFrame:", and as such they should override this method.
- return [NSString stringWithFormat:@"[[%@ alloc] initWithFrame:%@]", [self getProcessedClassName], [self frameString]];
+ return [NSString stringWithFormat:@"[[%@ alloc] init]", [self getProcessedClassName]];
}
@end
@@ -0,0 +1,13 @@
+//
+// ProxyObjectProcessor.h
+// nib2objc
+//
+// Created by Adrian Kosmaczewski on 11/7/11.
+// Copyright (c) 2011 akosma software. All rights reserved.
+//
+
+#import "Processor.h"
+
+@interface ProxyObjectProcessor : Processor
+
+@end
@@ -0,0 +1,43 @@
+//
+// ProxyObjectProcessor.m
+// nib2objc
+//
+// Created by Adrian Kosmaczewski on 11/7/11.
+// Copyright (c) 2011 akosma software. All rights reserved.
+//
+
+#import "ProxyObjectProcessor.h"
+#import "NSNumber+Nib2ObjcExtensions.h"
+
+@implementation ProxyObjectProcessor
+
+- (void)dealloc
+{
+ [super dealloc];
+}
+
+#pragma mark - Private methods
+
+- (NSString *)getProcessedClassName
+{
+ return @"NSProxy";
+}
+
+- (void)processKey:(id)item value:(id)value
+{
+ // Subclasses can override this method for their own properties.
+ // In those cases, call [super processUnknownProperty:item value:value];
+ // to be sure that mother classes do their work too.
+
+ id object = nil;
+ if ([item isEqualToString:@"custom-class"])
+ {
+ [output setObject:value forKey:@"class"];
+ }
+ if (object != nil)
+ {
+ [output setObject:object forKey:item];
+ }
+}
+
+@end
@@ -22,11 +22,6 @@ - (NSString *)getProcessedClassName
return @"UIBarItem";
}
-- (NSString *)frameString
-{
- return nil;
-}
-
- (void)processKey:(id)item value:(id)value
{
id object = nil;
@@ -22,16 +22,6 @@ - (NSString *)getProcessedClassName
return @"UIGestureRecognizer";
}
-- (NSString *)constructorString
-{
- return [NSString stringWithFormat:@"[[%@ alloc] init]", [self getProcessedClassName]];
-}
-
-- (NSString *)frameString
-{
- return nil;
-}
-
- (void)processKey:(id)item value:(id)value
{
id object = nil;
@@ -21,16 +21,6 @@ - (NSString *)getProcessedClassName
return @"UIViewController";
}
-- (NSString *)constructorString
-{
- return [NSString stringWithFormat:@"[[%@ alloc] init]", [self getProcessedClassName]];
-}
-
-- (NSString *)frameString
-{
- return nil;
-}
-
- (void)processKey:(id)item value:(id)value
{
id object = nil;
@@ -25,6 +25,17 @@ - (NSString *)getProcessedClassName
return @"UIView";
}
+- (NSString *)frameString
+{
+ NSString *rect = [NSString rectStringFromPoint:[self.input objectForKey:@"frameOrigin"] size:[self.input objectForKey:@"frameSize"]];
+ return rect;
+}
+
+- (NSString *)constructorString
+{
+ return [NSString stringWithFormat:@"[[%@ alloc] initWithFrame:%@]", [self getProcessedClassName], [self frameString]];
+}
+
- (void)processKey:(id)item value:(id)value
{
// Subclasses can override this method for their own properties.

0 comments on commit c7ea63f

Please sign in to comment.