Changeset 166

Show
Ignore:
Timestamp:
11/10/06 23:06:11 (2 years ago)
Author:
rentzsch
Message:

mogenerator 1.0.4:

[FIX] Add -[NSEntityDescription(customBaseClass) noninheritedAttributes] and update the machine templates to use it instead of plain old -[NSEntityDescription attributesByName], which returns all attributes: even those inherited.

Best case, this resulted in duplicate code generation in sub-entities.

Worst case, it would override human-generated methods with machine-generated methods in sub-entities. For example, consider an entity model was something like this: Human -> Employee. Human has a "firstName" attribute. Our business logic overrides the firstName accessor to prefix it with "Mr. ". This is what would happen:

_HumanMO firstName: primitiveValueForKey: wrapper

HumanMO firstName: return [@"Mr. " stringAppendingString:[super firstName]];

_EmployeeMO firstName: primitiveValueForKey: wrapper (duplicate code, overrides and blows away HumanMO's behavior.)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cocoa/mogenerator/machine.h.motemplate

    r164 r166  
    1010 
    1111@interface _<$managedObjectClassName$> : <$customSuperentity$> {} 
    12 <$foreach Attribute attributesByName do$> 
     12<$foreach Attribute noninheritedAttributes do$> 
    1313<$if Attribute.hasDefinedAttributeType$> 
    1414- (<$Attribute.attributeValueClassName$>*)<$Attribute.name$>; 
  • trunk/cocoa/mogenerator/machine.m.motemplate

    r162 r166  
    55 
    66@implementation _<$managedObjectClassName$> 
    7 <$foreach Attribute attributesByName do$> 
     7<$foreach Attribute noninheritedAttributes do$> 
    88<$if Attribute.hasDefinedAttributeType$> 
    99 
  • trunk/cocoa/mogenerator/mogenerator.m

    r164 r166  
    3232        } else { 
    3333                return gCustomBaseClass ? gCustomBaseClass : @"NSManagedObject"; 
     34        } 
     35} 
     36/** @TypeInfo NSAttributeDescription */ 
     37- (NSArray*)noninheritedAttributes { 
     38        NSEntityDescription *superentity = [self superentity]; 
     39        if (superentity) { 
     40                NSMutableArray *result = [[[self attributesByName] allValues] mutableCopy]; 
     41                [result removeObjectsInArray:[[superentity attributesByName] allValues]]; 
     42                return result; 
     43        } else { 
     44                return [[self attributesByName] allValues]; 
    3445        } 
    3546} 
     
    162173                                break; 
    163174                        case opt_version: 
    164                                 printf("mogenerator 1.0.3. By Jonathan 'Wolf' Rentzsch.\n"); 
     175                                printf("mogenerator 1.0.4. By Jonathan 'Wolf' Rentzsch.\n"); 
    165176                                break; 
    166177                        case opt_help: 
  • trunk/cocoa/mogenerator/mogenerator.xcodeproj/wolf.mode1

    r164 r166  
    219219                        <array> 
    220220                                <dict> 
     221                                        <key>BecomeActive</key> 
     222                                        <true/> 
    221223                                        <key>ContentConfiguration</key> 
    222224                                        <dict> 
     
    334336                                                </dict> 
    335337                                                <dict> 
    336                                                         <key>BecomeActive</key> 
    337                                                         <true/> 
    338338                                                        <key>ContentConfiguration</key> 
    339339                                                        <dict> 
     
    372372                        <key>TableOfContents</key> 
    373373                        <array> 
    374                                 <string>790C55640B05772800BF93B7</string> 
     374                                <string>790C55D90B058BD900BF93B7</string> 
    375375                                <string>1CE0B1FE06471DED0097A5F4</string> 
    376                                 <string>790C55650B05772800BF93B7</string> 
     376                                <string>790C55DA0B058BD900BF93B7</string> 
    377377                                <string>1CE0B20306471E060097A5F4</string> 
    378378                                <string>1CE0B20506471E060097A5F4</string> 
     
    591591                        <array> 
    592592                                <string>79D2BF1B0ACFAF4A00F3F141</string> 
    593                                 <string>790C556B0B05783C00BF93B7</string> 
     593                                <string>790C55E00B058DBF00BF93B7</string> 
    594594                                <string>1CD0528F0623707200166675</string> 
    595595                                <string>XCMainBuildResultsModuleGUID</string> 
  • trunk/cocoa/mogenerator/mogenerator.xcodeproj/wolf.pbxuser

    r164 r166  
    7373                                ); 
    7474                        }; 
    75                         PBXPerProjectTemplateStateSaveDate = 184907544; 
    76                         PBXWorkspaceStateSaveDate = 184907544; 
     75                        PBXPerProjectTemplateStateSaveDate = 184912844; 
     76                        PBXWorkspaceStateSaveDate = 184912844; 
    7777                }; 
    7878                sourceControlManager = 79D2BF0B0ACFAE0700F3F141 /* Source Control */; 
     
    8282        08FB7796FE84155DC02AAC07 /* mogenerator.m */ = { 
    8383                uiCtxt = { 
    84                         sepNavIntBoundsRect = "{{0, 0}, {1057, 3388}}"; 
    85                         sepNavSelRange = "{0, 0}"; 
    86                         sepNavVisRect = "{{0, 567}, {1057, 777}}"; 
     84                        sepNavIntBoundsRect = "{{0, 0}, {1057, 3542}}"; 
     85                        sepNavSelRange = "{955, 0}"; 
     86                        sepNavVisRect = "{{0, 0}, {1057, 777}}"; 
    8787                        sepNavWindowFrame = "{{339, 43}, {1096, 835}}"; 
    8888                }; 
  • trunk/cocoa/mogenerator/mogeneratorTestMule/MOs/_ChildMO.h

    r165 r166  
    1212 
    1313 
    14  
    15  
    16 - (NSString*)humanName; 
    17 - (void)setHumanName:(NSString*)value_; 
    18  
    19 //- (BOOL)validateHumanName:(id*)value_ error:(NSError**)error_; 
    20  
    21  
    22  
    2314- (NSString*)childName; 
    2415- (void)setChildName:(NSString*)value_; 
    2516 
    2617//- (BOOL)validateChildName:(id*)value_ error:(NSError**)error_; 
    27  
    28  
    29  
    30 - (NSData*)hairColorStorage; 
    31 - (void)setHairColorStorage:(NSData*)value_; 
    32  
    33 //- (BOOL)validateHairColorStorage:(id*)value_ error:(NSError**)error_; 
    3418 
    3519 
  • trunk/cocoa/mogenerator/mogeneratorTestMule/MOs/_ChildMO.m

    r165 r166  
    55 
    66@implementation _ChildMO 
    7  
    8  
    9  
    10  
    11  
    12 - (NSString*)humanName { 
    13         [self willAccessValueForKey:@"humanName"]; 
    14         NSString *result = [self primitiveValueForKey:@"humanName"]; 
    15         [self didAccessValueForKey:@"humanName"]; 
    16         return result; 
    17 } 
    18  
    19 - (void)setHumanName:(NSString*)value_ { 
    20     [self willChangeValueForKey:@"humanName"]; 
    21     [self setPrimitiveValue:value_ forKey:@"humanName"]; 
    22     [self didChangeValueForKey:@"humanName"]; 
    23 } 
    24  
    25  
    26  
    277 
    288 
     
    3919    [self setPrimitiveValue:value_ forKey:@"childName"]; 
    4020    [self didChangeValueForKey:@"childName"]; 
    41 } 
    42  
    43  
    44  
    45  
    46  
    47  
    48 - (NSData*)hairColorStorage { 
    49         [self willAccessValueForKey:@"hairColorStorage"]; 
    50         NSData *result = [self primitiveValueForKey:@"hairColorStorage"]; 
    51         [self didAccessValueForKey:@"hairColorStorage"]; 
    52         return result; 
    53 } 
    54  
    55 - (void)setHairColorStorage:(NSData*)value_ { 
    56     [self willChangeValueForKey:@"hairColorStorage"]; 
    57     [self setPrimitiveValue:value_ forKey:@"hairColorStorage"]; 
    58     [self didChangeValueForKey:@"hairColorStorage"]; 
    5921} 
    6022 
  • trunk/cocoa/mogenerator/mogeneratorTestMule/MOs/_ParentMO.h

    r162 r166  
    2929 
    3030 
    31 - (NSString*)humanName; 
    32 - (void)setHumanName:(NSString*)value_; 
    33  
    34 //- (BOOL)validateHumanName:(id*)value_ error:(NSError**)error_; 
    35  
    36  
    37  
    3831- (NSDecimalNumber*)myDecimal; 
    3932- (void)setMyDecimal:(NSDecimalNumber*)value_; 
     
    4740 
    4841//- (BOOL)validateMyDate:(id*)value_ error:(NSError**)error_; 
    49  
    50  
    5142 
    5243 
     
    116107 
    117108 
    118 - (NSData*)hairColorStorage; 
    119 - (void)setHairColorStorage:(NSData*)value_; 
    120  
    121 //- (BOOL)validateHairColorStorage:(id*)value_ error:(NSError**)error_; 
    122  
    123  
    124  
    125109- (NSNumber*)myInt32; 
    126110- (void)setMyInt32:(NSNumber*)value_; 
  • trunk/cocoa/mogenerator/mogeneratorTestMule/MOs/_ParentMO.m

    r162 r166  
    5454 
    5555 
    56 - (NSString*)humanName { 
    57         [self willAccessValueForKey:@"humanName"]; 
    58         NSString *result = [self primitiveValueForKey:@"humanName"]; 
    59         [self didAccessValueForKey:@"humanName"]; 
    60         return result; 
    61 } 
    62  
    63 - (void)setHumanName:(NSString*)value_ { 
    64     [self willChangeValueForKey:@"humanName"]; 
    65     [self setPrimitiveValue:value_ forKey:@"humanName"]; 
    66     [self didChangeValueForKey:@"humanName"]; 
    67 } 
    68  
    69  
    70  
    71  
    72  
    73  
    7456- (NSDecimalNumber*)myDecimal { 
    7557        [self willAccessValueForKey:@"myDecimal"]; 
     
    10890 
    10991 
    110  
    111  
    11292- (NSNumber*)myBoolean { 
    11393        [self willAccessValueForKey:@"myBoolean"]; 
     
    279259    [self setPrimitiveValue:value_ forKey:@"myString"]; 
    280260    [self didChangeValueForKey:@"myString"]; 
    281 } 
    282  
    283  
    284  
    285  
    286  
    287  
    288 - (NSData*)hairColorStorage { 
    289         [self willAccessValueForKey:@"hairColorStorage"]; 
    290         NSData *result = [self primitiveValueForKey:@"hairColorStorage"]; 
    291         [self didAccessValueForKey:@"hairColorStorage"]; 
    292         return result; 
    293 } 
    294  
    295 - (void)setHairColorStorage:(NSData*)value_ { 
    296     [self willChangeValueForKey:@"hairColorStorage"]; 
    297     [self setPrimitiveValue:value_ forKey:@"hairColorStorage"]; 
    298     [self didChangeValueForKey:@"hairColorStorage"]; 
    299261} 
    300262 
  • trunk/cocoa/mogenerator/mogeneratorTestMule/mogeneratorTestMule.xcodeproj/wolf.mode1

    r165 r166  
    370370                        <key>TableOfContents</key> 
    371371                        <array> 
    372                                 <string>790C55C00B058A9A00BF93B7</string> 
     372                                <string>790C560B0B05919400BF93B7</string> 
    373373                                <string>1CE0B1FE06471DED0097A5F4</string> 
    374                                 <string>790C55C10B058A9A00BF93B7</string> 
     374                                <string>790C560C0B05919400BF93B7</string> 
    375375                                <string>1CE0B20306471E060097A5F4</string> 
    376376                                <string>1CE0B20506471E060097A5F4</string> 
     
    506506        <key>WindowOrderList</key> 
    507507        <array> 
     508                <string>1C0AD2B3069F1EA900FABCE6</string> 
     509                <string>79812D6F0B05091300DF4429</string> 
    508510                <string>/Volumes/Island/wolf/code/sf/redshed/cocoa/mogenerator/mogeneratorTestMule/mogeneratorTestMule.xcodeproj</string> 
    509511        </array> 
     
    525527                                        <array> 
    526528                                                <dict> 
    527                                                         <key>BecomeActive</key> 
    528                                                         <true/> 
    529529                                                        <key>ContentConfiguration</key> 
    530530                                                        <dict> 
     
    532532                                                                <string>1CD0528F0623707200166675</string> 
    533533                                                                <key>PBXProjectModuleLabel</key> 
    534                                                                 <string>_ParentMO.h</string> 
     534                                                                <string></string> 
    535535                                                                <key>StatusBarVisibility</key> 
    536536                                                                <true/> 
     
    588588                        <array> 
    589589                                <string>79812D6F0B05091300DF4429</string> 
    590                                 <string>79812E2A0B050B6F00DF4429</string> 
     590                                <string>790C560D0B05919400BF93B7</string> 
    591591                                <string>1CD0528F0623707200166675</string> 
    592592                                <string>XCMainBuildResultsModuleGUID</string> 
     
    943943                        <array> 
    944944                                <string>1C0AD2B3069F1EA900FABCE6</string> 
    945                                 <string>79812E360B050B9300DF4429</string> 
     945                                <string>790C560E0B05919400BF93B7</string> 
    946946                                <string>1CD0528B0623707200166675</string> 
    947                                 <string>79812E370B050B9300DF4429</string> 
     947                                <string>790C560F0B05919400BF93B7</string> 
    948948                        </array> 
    949949                        <key>ToolbarConfiguration</key> 
  • trunk/cocoa/mogenerator/mogeneratorTestMule/mogeneratorTestMule.xcodeproj/wolf.pbxuser

    r165 r166  
    3535                                ); 
    3636                        }; 
    37                         PBXPerProjectTemplateStateSaveDate = 184912509
    38                         PBXWorkspaceStateSaveDate = 184912509
     37                        PBXPerProjectTemplateStateSaveDate = 184914308
     38                        PBXWorkspaceStateSaveDate = 184914308
    3939                }; 
    4040                sourceControlManager = 79812C860B04F47200DF4429 /* Source Control */;