Skip to content
Browse files

working NS_ENUM

  • Loading branch information...
1 parent faa266a commit a25515681e38964ba737e8eda835521f38532b0b robvdveer committed Jul 26, 2013
View
4 Generating/GBDocSetOutputGenerator.m
@@ -406,14 +406,14 @@ - (NSString *)tokenIdentifierForObject:(GBModelBase *)object {
}
else if ([object isKindOfClass:[GBTypedefEnumData class]]){
NSString *objectName = [(GBTypedefEnumData *)object nameOfEnum];
- return [NSString stringWithFormat:@"//apple_ref/occ/tdef/%@", objectName];
+ return [NSString stringWithFormat:@"//apple_ref/c/tdef/%@", objectName];
}
} else if ([object isKindOfClass:[GBDocumentData class]]){
NSString *objectName = [(GBDocumentData *)object prettyNameOfDocument];
return [NSString stringWithFormat:@"//apple_ref/occ/doc/%@", objectName];
} else if ([object isKindOfClass:[GBEnumConstantData class]]){
NSString *objectName = [(GBEnumConstantData *)object name];
- return [NSString stringWithFormat:@"//apple_ref/occ/tag/%@", objectName];
+ return [NSString stringWithFormat:@"//apple_ref/c/econst/%@", objectName];
} else if (!object.isStaticDocument) {
// Members are slighly more complex - their identifier is different regarding to whether they are part of class or category/protocol. Then it depends on whether they are method or property. Finally their parent object (class/category/protocol) name (again class name for category) and selector should be added.
if (!object.parentObject) [NSException raise:@"Can't create token identifier for %@; object is not top level and has no parent assigned!", object];
View
3 Model/GBEnumConstantData.h
@@ -12,8 +12,11 @@
{
@private
NSString *_name;
+ NSString *_assignedValue;
}
+(id)constantWithName:(NSString *)name;
@property (readonly) NSString *name;
+@property (copy) NSString *assignedValue;
+@property (readonly) bool hasAssignedValue;
@end
View
14 Model/GBEnumConstantData.m
@@ -24,5 +24,19 @@ -(id)initWithName:(NSString *)name
return self;
}
+- (NSString *)description {
+ return self.name;
+}
+
+- (NSString *)debugDescription {
+ return [NSString stringWithFormat:@"%@: %@", [self className], self.name];
+}
+
+- (bool)hasAssignedValue
+{
+ return _assignedValue != nil;
+}
+
@synthesize name = _name;
+@synthesize assignedValue = _assignedValue;
@end
View
9 Model/GBTypedefEnumData.h
@@ -15,10 +15,19 @@
@private
NSString *_typedefName;
GBEnumConstantProvider *_constants;
+ NSString *_enumPrimitive;
+ bool _isOptions;
}
+(id)typedefEnumWithName:(NSString *)name;
@property (readonly) NSString *nameOfEnum;
@property (readonly) GBEnumConstantProvider *constants;
+
+/** The type of enum, e.g. NS_ENUM (NSInteger, name), this will be NSInteger */
+@property (copy) NSString *enumPrimitive;
+
+/** True when the enum is defined as NS_OPTIONS */
+@property (assign) bool isOptions;
+@property (readonly) NSString *enumStyle;
@end
View
7 Model/GBTypedefEnumData.m
@@ -37,6 +37,13 @@ - (BOOL)isTopLevelObject {
return YES;
}
+- (NSString *)enumStyle
+{
+ return _isOptions?@"NS_OPTIONS":@"NS_ENUM";
+}
+
@synthesize nameOfEnum = _typedefName;
@synthesize constants = _constants;
+@synthesize isOptions = _isOptions;
+@synthesize enumPrimitive = _enumPrimitive;
@end
View
93 Parsing/GBObjectiveCParser.m
@@ -421,57 +421,78 @@ - (BOOL)matchNextObject {
- (BOOL)matchTypedefEnumDefinition {
BOOL isTypeDef = [[self.tokenizer currentToken] matches:@"typedef"];
- BOOL isTypeDefEnum = [[self.tokenizer lookahead:1] matches:@"enum"];
+ BOOL isTypeDefEnum = [[self.tokenizer lookahead:1] matches:@"NS_ENUM"];
+ BOOL isTypeDefOptions = [[self.tokenizer lookahead:1] matches:@"NS_OPTIONS"];
+ BOOL hasOpenBracket = [[self.tokenizer lookahead:2] matches:@"("];
- if(isTypeDef && isTypeDefEnum)
+ //ONLY SUPPORTED ARE typedef enum { } name; because that is the only way to bind the name to the enum values.
+
+ if(isTypeDef && (isTypeDefEnum || isTypeDefOptions) && hasOpenBracket)
{
- NSMutableArray *constants = [[NSMutableArray alloc] init];
+ [self.tokenizer consume:3]; //consume 'typedef' 'NS_ENUM' and '('
- // remember the current comments, we need them later.
- __block GBSourceInfo *filedata = nil;
- GBSourceInfo *startInfo = [tokenizer sourceInfoForCurrentToken];
- GBComment *lastComment = [tokenizer lastComment];
+ //get the enum type
+ NSString *typedefType = [[self.tokenizer currentToken] stringValue];
+ [self.tokenizer consume:1];
- [self.tokenizer consume:2];
- [self.tokenizer consumeFrom:@"{" to:@"}" usingBlock:^(PKToken *token, BOOL *consume, BOOL *stop) {
-
- if([token matches:@","])
- {
- //skip
- }
- else
- {
- if(!filedata)
- {
- filedata = [tokenizer sourceInfoForToken:token];
- }
-
- GBEnumConstantData *newConstant = [GBEnumConstantData constantWithName:[token stringValue]];
- [newConstant registerSourceInfo:filedata];
- [constants addObject:newConstant];
-
- [self registerLastCommentToObject:newConstant];
- }
- }];
-
+ //consume ','
+ [self.tokenizer consume:1];
+
+ //get the typename
NSString *typedefName = [[self.tokenizer currentToken] stringValue];
- [self.tokenizer consume:1]; // consume typedef name;
+ [self.tokenizer consume:1];
+
+ //consume ')'
+ [self.tokenizer consume:1];
+ GBSourceInfo *startInfo = [tokenizer sourceInfoForCurrentToken];
+ GBComment *lastComment = [tokenizer lastComment];
GBLogVerbose(@"Matched %@ typedef enum definition at line %lu.", typedefName, startInfo.lineNumber);
GBTypedefEnumData *newEnum = [GBTypedefEnumData typedefEnumWithName:typedefName];
newEnum.includeInOutput = self.includeInOutput;
+ newEnum.enumPrimitive = typedefType;
+ newEnum.isOptions = isTypeDefOptions;
+
[newEnum registerSourceInfo:startInfo];
[self registerComment:lastComment toObject:newEnum];
-
- for(GBEnumConstantData *constant in constants)
- {
- [newEnum.constants registerConstant:constant];
- }
+
+ //[self.tokenizer consume:1];
+ [self.tokenizer consumeFrom:@"{" to:@"}" usingBlock:^(PKToken *token, BOOL *consume, BOOL *stop)
+ {
+ GBEnumConstantData *newConstant = [GBEnumConstantData constantWithName:[token stringValue]];
+ GBSourceInfo *filedata = [tokenizer sourceInfoForToken:token];
+ [newConstant registerSourceInfo:filedata];
+ [self registerLastCommentToObject:newConstant];
+ [self.tokenizer consume:1];
+
+ if([[self.tokenizer currentToken] matches:@"="])
+ {
+ [self.tokenizer consume:1];
+
+ //collect the stringvalues until a ',' is detected.
+ NSMutableString *value = [[NSMutableString alloc] init];
+ while(![[tokenizer currentToken] matches:@","] && ![[tokenizer currentToken] matches:@"}"])
+ {
+ [value appendString:[[tokenizer currentToken] stringValue]];
+ [tokenizer consume:1];
+ }
+
+ [newConstant setAssignedValue:value];
+ }
+
+ if([[self.tokenizer currentToken] matches:@","])
+ {
+ [tokenizer consume:1];
+ }
+
+ *consume = NO;
+
+ [newEnum.constants registerConstant:newConstant];
+ }];
//consume ;
[self.tokenizer consume:1];
-
[self.store registerTypedefEnum:newEnum];
return YES;
}
View
10 Processing/GBProcessor.m
@@ -447,6 +447,16 @@ - (void)validateCommentsForObjectAndMembers:(GBModelBase *)object {
}
}
}
+
+ if([object isKindOfClass:[GBTypedefEnumData class]])
+ {
+ for(GBEnumConstantData *constant in ((GBTypedefEnumData *)object).constants.constants)
+ {
+ if (![self isCommentValid:constant.comment] && self.settings.warnOnUndocumentedMember) {
+ GBLogXWarn(constant.prefferedSourceInfo, @"%@ is not documented!", constant);
+ }
+ }
+ }
}
- (BOOL)isCommentValid:(GBComment *)comment {
View
12 Templates/html/object-template.html
@@ -124,11 +124,10 @@ <h3 class="subsubtitle method-title">{{nameOfEnum}}</h3>
<h4 class="method-subtitle">Definition</h4>
<code>typedef enum {<br/>
{{#constants}}
- &nbsp;&nbsp; <a href="{{htmlLocalReference}}">{{name}}</a>,<br/>
+ &nbsp;&nbsp; <a href="{{htmlLocalReference}}">{{name}}</a>{{#hasAssignedValue}} = {{assignedValue}}{{/hasAssignedValue}},<br/>
{{/constants}}
- } {{nameOfEnum}};
- </code>
- {{/constants}}
+ } {{nameOfEnum}};</code>
+ {{/constants}}
</div>
{{#constants}}
<div class="section section-methods">
@@ -396,6 +395,11 @@ <h4 class="method-subtitle">{{strings/objectMethods/declaredInTitle}}</h4>
{{#hasShortDescription}}
{{#shortDescription}}{{>GBCommentComponent}}{{/shortDescription}}
{{/hasShortDescription}}
+
+{{#hasAvailability}}
+ <p>Available in {{#availability}}{{#components}}{{stringValue}}{{/components}}{{/availability}}</p>
+{{/hasAvailability}}
+
{{/comment}}
{{#prefferedSourceInfo}}
<p>

0 comments on commit a255156

Please sign in to comment.
Something went wrong with that request. Please try again.