Skip to content

Commit e2941fa

Browse files
committed
Annotate deprecated Objects.
1 parent 5181580 commit e2941fa

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

Tools/ServiceGenerator/SGGenerator.m

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
static NSString *kReturnsSchemaParameterKey = @"returnsSchema";
5353
static NSString *kAllMethodObjectParametersKey = @"allMethodObjectParameters";
5454
static NSString *kAllMethodObjectParameterRefsKey = @"allMethodObjectParameterRefs";
55+
static NSString *kHasDeprecatedSchemaKey = @"hasDeprecatedSchemaKey";
5556
static NSString *kCleanedRootURLStringKey = @"cleanedRootURLString";
5657
static NSString *kResumableUploadPathKey = @"resumableUploadPath";
5758
static NSString *kSimpleUploadPathKey = @"simpleUploadPath";
@@ -96,6 +97,7 @@ @interface GTLRDiscovery_RestDescription (SGGeneratorAdditions)
9697
@property(readonly) NSDictionary *sg_objectEnumsMap;
9798
@property(readonly) NSArray *sg_allSchemas;
9899
@property(readonly) NSArray *sg_topLevelObjectSchemas;
100+
@property(readonly) BOOL sg_hasDeprecatedSchema;
99101
@property(readonly) NSArray *sg_allMethodObjectParameterReferences;
100102
@property(readonly) NSString *sg_resumableUploadPath;
101103
@property(readonly) NSString *sg_simpleUploadPath;
@@ -1287,6 +1289,7 @@ - (NSString *)objectsHeader {
12871289
}
12881290

12891291
SGClangDirectives *clangDirectives = [SGClangDirectives disabledDocumentation];
1292+
clangDirectives.disableDeprecatedDeclarations = self.api.sg_hasDeprecatedSchema;
12901293
[parts addObject:clangDirectives.start];
12911294

12921295
[parts addObject:@"NS_ASSUME_NONNULL_BEGIN\n"];
@@ -1339,6 +1342,14 @@ - (NSString *)objectsSource {
13391342
[parts addObjectsFromArray:blocks];
13401343
}
13411344

1345+
SGClangDirectives *clangDirectives = [[SGClangDirectives alloc] init];
1346+
BOOL hasDeprecatedSchema = self.api.sg_hasDeprecatedSchema;
1347+
clangDirectives.disableDeprecatedImplementations = hasDeprecatedSchema;
1348+
clangDirectives.disableDeprecatedDeclarations = hasDeprecatedSchema;
1349+
if (clangDirectives.hasDirectives) {
1350+
[parts addObject:clangDirectives.start];
1351+
}
1352+
13421353
NSMutableArray *classParts = [NSMutableArray array];
13431354
for (GTLRDiscovery_JsonSchema *schema in self.api.sg_topLevelObjectSchemas) {
13441355
NSString *objectClassStr = [self generateObjectClassForSchema:schema
@@ -1354,6 +1365,10 @@ - (NSString *)objectsSource {
13541365
// Two blank lines between classes.
13551366
[parts addObject:[classParts componentsJoinedByString:@"\n\n"]];
13561367

1368+
if (clangDirectives.hasDirectives) {
1369+
[parts addObject:clangDirectives.end];
1370+
}
1371+
13571372
return [parts componentsJoinedByString:@"\n"];
13581373
}
13591374

@@ -2403,8 +2418,9 @@ - (NSString *)generateObjectClassForSchema:(GTLRDiscovery_JsonSchema *)schema
24032418
} else if (isTopLevelArrayResult) {
24042419
baseClass = kResultArrayClass;
24052420
}
2406-
atBlock = [NSString stringWithFormat:@"@interface %@ : %@\n",
2407-
schemaClassName, baseClass];
2421+
NSString *maybeDeprecated = schema.deprecated.boolValue ? kDeprecatedWithNewline : @"";
2422+
atBlock = [NSString stringWithFormat:@"%@@interface %@ : %@\n",
2423+
maybeDeprecated, schemaClassName, baseClass];
24082424
} else {
24092425
atBlock = [NSString stringWithFormat:@"@implementation %@\n",
24102426
schemaClassName];
@@ -3313,6 +3329,37 @@ - (NSArray *)sg_topLevelObjectSchemas {
33133329
return result;
33143330
}
33153331

3332+
- (BOOL)sg_hasDeprecatedSchema {
3333+
// This could be expanded to deal with if there are referenced as types
3334+
// on other schema vs. queries to only add the guards when needed, but
3335+
// for now just generally insert them when any schema was deprecated.
3336+
NSNumber *result = [self sg_propertyForKey:kHasDeprecatedSchemaKey];
3337+
if (result == nil) {
3338+
BOOL hasDeprecated = NO;
3339+
3340+
for (GTLRDiscovery_JsonSchema *schema in self.sg_topLevelObjectSchemas) {
3341+
if (schema.deprecated.boolValue) {
3342+
hasDeprecated = YES;
3343+
break;
3344+
}
3345+
3346+
for (GTLRDiscovery_JsonSchema *subSchema in schema.sg_childObjectSchemas) {
3347+
if (subSchema.deprecated.boolValue) {
3348+
hasDeprecated = YES;
3349+
break;
3350+
}
3351+
}
3352+
if (hasDeprecated) {
3353+
break;
3354+
}
3355+
}
3356+
3357+
result = [NSNumber numberWithBool:hasDeprecated];
3358+
[self sg_setProperty:result forKey:kHasDeprecatedSchemaKey];
3359+
}
3360+
return [result boolValue];
3361+
}
3362+
33163363
// These are resolved schema references in the method parameters (refs or
33173364
// inline).
33183365
- (NSArray *)sg_allMethodObjectParameterReferences {

Tools/ServiceGenerator/SGUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373

7474
// -Wdeprecated-implementations
7575
@property BOOL disableDeprecatedImplementations;
76+
// -Wdeprecated-declarations
77+
@property BOOL disableDeprecatedDeclarations;
7678
// -Wdocumentation
7779
@property BOOL disableDocumentation;
7880

Tools/ServiceGenerator/SGUtils.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ typedef NS_OPTIONS(NSInteger, SGCDFlags) {
681681
SGCDFlagsNone = 0,
682682
SGCDFlagsDocumentation = 1 << 0,
683683
SGCDFlagsDeprecatedImplementations = 1 << 1,
684+
SGCDFlagsDeprecatedDeclarations = 1 << 2,
684685
};
685686

686687
@implementation SGClangDirectives {
@@ -700,6 +701,14 @@ - (void)setDisableDeprecatedImplementations:(BOOL)value {
700701
SET_FLAG(SGCDFlagsDeprecatedImplementations, value);
701702
}
702703

704+
- (BOOL)disableDeprecatedDeclarations {
705+
return IS_FLAG_SET(SGCDFlagsDeprecatedDeclarations);
706+
}
707+
708+
- (void)setDisableDeprecatedDeclarations:(BOOL)value {
709+
SET_FLAG(SGCDFlagsDeprecatedDeclarations, value);
710+
}
711+
703712
- (BOOL)disableDocumentation {
704713
return IS_FLAG_SET(SGCDFlagsDocumentation);
705714
}
@@ -740,6 +749,11 @@ - (NSString *)start {
740749
[result appendString:@"#pragma clang diagnostic push\n"];
741750
}
742751

752+
if (self.disableDeprecatedDeclarations) {
753+
[result appendString:
754+
@"#pragma clang diagnostic ignored \"-Wdeprecated-declarations\"\n"];
755+
}
756+
743757
if (self.disableDeprecatedImplementations) {
744758
[result appendString:
745759
@"#pragma clang diagnostic ignored \"-Wdeprecated-implementations\"\n"];

0 commit comments

Comments
 (0)