summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-06-20 08:39:31 +0300
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-08-13 13:32:56 +0300
commit603c02ccc21543473074787aaad7c89d282dddc9 (patch)
treea14685995821275c8fe258b794fa783aa31f6c61
parent0ff218d688084146fee178ce52c17f346fa67198 (diff)
downloadqtlocation-mapboxgl-603c02ccc21543473074787aaad7c89d282dddc9.tar.gz
[darwin] Generate plural version of property name, yet, keep singular version of an enum
-rwxr-xr-xplatform/darwin/scripts/generate-style-code.js53
-rw-r--r--platform/darwin/scripts/style-spec-cocoa-conventions-v8.json2
-rw-r--r--platform/darwin/src/MGLStyleLayer.h.ejs26
-rw-r--r--platform/darwin/src/MGLStyleLayer.mm.ejs16
-rw-r--r--platform/darwin/src/MGLSymbolStyleLayer.h40
-rw-r--r--platform/darwin/src/MGLSymbolStyleLayer.mm18
-rw-r--r--platform/darwin/test/MGLStyleLayerTests.mm.ejs2
-rw-r--r--platform/darwin/test/MGLSymbolStyleLayerTests.mm4
8 files changed, 94 insertions, 67 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js
index 78eb796eb7..18afa561e5 100755
--- a/platform/darwin/scripts/generate-style-code.js
+++ b/platform/darwin/scripts/generate-style-code.js
@@ -5,6 +5,7 @@ const fs = require('fs');
const ejs = require('ejs');
const _ = require('lodash');
const colorParser = require('csscolorparser');
+const assert = require('assert');
require('../../../scripts/style-code');
@@ -19,34 +20,56 @@ delete spec.layout_circle["circle-sort-key"]
delete spec.layout_line["line-sort-key"]
delete spec.layout_fill["fill-sort-key"]
+class ConventionOverride {
+ constructor(val) {
+ if (typeof val === 'string') {
+ this.name_ = val;
+ this.enumName_ = null;
+ } else if (val instanceof Object) {
+ this.name_ = val.name;
+ this.enumName_ = val.enumName;
+ } else {
+ assert(false);
+ }
+ }
+
+ set name(name_) { this.name_ = name_; }
+ get name() { return this.name_; }
+ get enumName() { return this.enumName_ || this.name_; }
+}
+
// Rename properties and keep `original` for use with setters and getters
_.forOwn(cocoaConventions, function (properties, kind) {
- _.forOwn(properties, function (newName, oldName) {
+ _.forOwn(properties, function (newConvention, oldName) {
+ let conventionOverride = new ConventionOverride(newConvention);
let property = spec[kind][oldName];
- if (newName.startsWith('is-')) {
- property.getter = newName;
- newName = newName.substr(3);
+ if (conventionOverride.name.startsWith('is-')) {
+ property.getter = conventionOverride.name;
+ conventionOverride.name = conventionOverride.name.substr(3);
}
- if (newName !== oldName) {
+
+ // Override enum name based on style-spec-cocoa-conventions-v8.json
+ property.enumName = conventionOverride.enumName;
+
+ if (conventionOverride.name !== oldName) {
property.original = oldName;
+ delete spec[kind][oldName];
+ spec[kind][conventionOverride.name] = property;
}
- delete spec[kind][oldName];
- spec[kind][newName] = property;
// Update cross-references to this property in other properties'
// documentation and requirements.
let renameCrossReferences = function (property, name) {
- property.doc = property.doc.replace(new RegExp('`' + oldName + '`', 'g'), '`' + newName + '`');
+ property.doc = property.doc.replace(new RegExp('`' + oldName + '`', 'g'), '`' + conventionOverride.name + '`');
let requires = property.requires || [];
for (let i = 0; i < requires.length; i++) {
if (requires[i] === oldName) {
- property.requires[i] = newName;
+ property.requires[i] = conventionOverride.name;
}
if (typeof requires[i] !== 'string') {
- let prop = name;
_.forOwn(requires[i], function (values, name, require) {
if (name === oldName) {
- require[newName] = values;
+ require[conventionOverride.name] = values;
delete require[name];
}
});
@@ -468,7 +491,7 @@ global.describeType = function (property) {
case 'anchor':
return '`MGLTextAnchor` array';
case 'mode':
- return '`MGLTextWritingModes` array';
+ return '`MGLTextWritingMode` array';
default:
return 'array';
}
@@ -573,6 +596,10 @@ global.originalPropertyName = function (property) {
return property.original || property.name;
};
+global.enumName = function (property) {
+ return property.enumName || property.name;
+};
+
global.propertyType = function (property) {
switch (property.type) {
case 'boolean':
@@ -647,7 +674,7 @@ global.valueTransformerArguments = function (property) {
case 'anchor':
return ['std::vector<mbgl::style::SymbolAnchorType>', objCType, 'mbgl::style::SymbolAnchorType', 'MGLTextAnchor'];
case 'mode':
- return ['std::vector<mbgl::style::TextWritingModeType>', objCType, 'mbgl::style::TextWritingModeType', 'MGLTextWritingModes'];
+ return ['std::vector<mbgl::style::TextWritingModeType>', objCType, 'mbgl::style::TextWritingModeType', 'MGLTextWritingMode'];
default:
throw new Error(`unknown array type for ${property.name}`);
}
diff --git a/platform/darwin/scripts/style-spec-cocoa-conventions-v8.json b/platform/darwin/scripts/style-spec-cocoa-conventions-v8.json
index 9564479179..c781879bc5 100644
--- a/platform/darwin/scripts/style-spec-cocoa-conventions-v8.json
+++ b/platform/darwin/scripts/style-spec-cocoa-conventions-v8.json
@@ -19,7 +19,7 @@
"text-optional": "is-text-optional",
"text-rotate": "text-rotation",
"text-size": "text-font-size",
- "text-writing-mode": "text-writing-modes"
+ "text-writing-mode": {"name": "text-writing-modes", "enumName": "text-writing-mode"}
},
"paint_circle": {
"circle-pitch-scale": "circle-scale-alignment",
diff --git a/platform/darwin/src/MGLStyleLayer.h.ejs b/platform/darwin/src/MGLStyleLayer.h.ejs
index 4bbb9e9f0d..91ba813b17 100644
--- a/platform/darwin/src/MGLStyleLayer.h.ejs
+++ b/platform/darwin/src/MGLStyleLayer.h.ejs
@@ -21,17 +21,17 @@ NS_ASSUME_NONNULL_BEGIN
<% for (const property of layoutProperties) { -%>
<% if (definesEnum(property, layoutProperties)) { -%>
/**
-<%- propertyDoc(property.name, property, type, 'enum').wrap(80, 1) %>
+<%- propertyDoc(enumName(property), property, type, 'enum').wrap(80, 1) %>
Values of this type are used in the `MGL<%- camelize(type) %>StyleLayer.<%- camelizeWithLeadingLowercase(property.name) %>`
property.
*/
-typedef NS_ENUM(NSUInteger, MGL<%- camelize(property.name) %>) {
+typedef NS_ENUM(NSUInteger, MGL<%- camelize(enumName(property)) %>) {
<% for (const value in property.values) { -%>
/**
-<%- propertyDoc(property.name, property.values[value], type, 'enum').wrap(80, 4+1) %>
+<%- propertyDoc(enumName(property), property.values[value], type, 'enum').wrap(80, 4+1) %>
*/
- MGL<%- camelize(property.name) %><%- camelize(value) %>,
+ MGL<%- camelize(enumName(property)) %><%- camelize(value) %>,
<% } -%>
};
@@ -40,17 +40,17 @@ typedef NS_ENUM(NSUInteger, MGL<%- camelize(property.name) %>) {
<% for (const property of paintProperties) { -%>
<% if (definesEnum(property, paintProperties)) { -%>
/**
-<%- propertyDoc(property.name, property, type, 'enum').wrap(80, 1) %>
+<%- propertyDoc(enumName(property), property, type, 'enum').wrap(80, 1) %>
- Values of this type are used in the `MGL<%- camelize(type) %>StyleLayer.<%- camelizeWithLeadingLowercase(property.name) %>`
+ Values of this type are used in the `MGL<%- camelize(type) %>StyleLayer.<%- camelizeWithLeadingLowercase(enumName(property)) %>`
property.
*/
-typedef NS_ENUM(NSUInteger, MGL<%- camelize(property.name) %>) {
+typedef NS_ENUM(NSUInteger, MGL<%- camelize(enumName(property)) %>) {
<% for (const value in property.values) { -%>
/**
-<%- propertyDoc(property.name, property.values[value], type, 'enum').wrap(80, 4+1) %>
+<%- propertyDoc(enumName(property), property.values[value], type, 'enum').wrap(80, 4+1) %>
*/
- MGL<%- camelize(property.name) %><%- camelize(value) %>,
+ MGL<%- camelize(enumName(property)) %><%- camelize(value) %>,
<% } -%>
};
@@ -180,17 +180,17 @@ which it is added.
<% for (let property of enumProperties) { -%>
/**
- Creates a new value object containing the given `MGL<%- camelize(property.name) %>` enumeration.
+ Creates a new value object containing the given `MGL<%- camelize(enumName(property)) %>` enumeration.
@param <%- objCName(property) %> The value for the new object.
@return A new value object that contains the enumeration value.
*/
-+ (instancetype)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %>;
++ (instancetype)valueWithMGL<%- camelize(enumName(property)) %>:(MGL<%- camelize(enumName(property)) %>)<%- objCName(property) %>;
/**
- The `MGL<%- camelize(property.name) %>` enumeration representation of the value.
+ The `MGL<%- camelize(enumName(property)) %>` enumeration representation of the value.
*/
-@property (readonly) MGL<%- camelize(property.name) %> MGL<%- camelize(property.name) %>Value;
+@property (readonly) MGL<%- camelize(enumName(property)) %> MGL<%- camelize(enumName(property)) %>Value;
<% } -%>
@end
diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs
index e8c8d8cfd9..5d9f546cd7 100644
--- a/platform/darwin/src/MGLStyleLayer.mm.ejs
+++ b/platform/darwin/src/MGLStyleLayer.mm.ejs
@@ -26,9 +26,9 @@ namespace mbgl {
<% if (layoutProperties.length) { -%>
<% for (const property of layoutProperties) { -%>
<% if (definesEnum(property, layoutProperties)) { -%>
- MBGL_DEFINE_ENUM(MGL<%- camelize(property.name) %>, {
+ MBGL_DEFINE_ENUM(MGL<%- camelize(enumName(property)) %>, {
<% for (const value in property.values) { -%>
- { MGL<%- camelize(property.name) %><%- camelize(value) %>, "<%-value%>" },
+ { MGL<%- camelize(enumName(property)) %><%- camelize(value) %>, "<%-value%>" },
<% } -%>
});
@@ -38,9 +38,9 @@ namespace mbgl {
<% if (paintProperties.length) { -%>
<% for (const property of paintProperties) { -%>
<% if (definesEnum(property, paintProperties)) { -%>
- MBGL_DEFINE_ENUM(MGL<%- camelize(property.name) %>, {
+ MBGL_DEFINE_ENUM(MGL<%- camelize(enumName(property)) %>, {
<% for (const value in property.values) { -%>
- { MGL<%- camelize(property.name) %><%- camelize(value) %>, "<%-value%>" },
+ { MGL<%- camelize(enumName(property)) %><%- camelize(value) %>, "<%-value%>" },
<% } -%>
});
@@ -239,12 +239,12 @@ namespace mbgl {
@implementation NSValue (MGL<%- camelize(type) %>StyleLayerAdditions)
<% for (let property of enumProperties) { -%>
-+ (NSValue *)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %> {
- return [NSValue value:&<%- objCName(property) %> withObjCType:@encode(MGL<%- camelize(property.name) %>)];
++ (NSValue *)valueWithMGL<%- camelize(enumName(property)) %>:(MGL<%- camelize(enumName(property)) %>)<%- objCName(property) %> {
+ return [NSValue value:&<%- objCName(property) %> withObjCType:@encode(MGL<%- camelize(enumName(property)) %>)];
}
-- (MGL<%- camelize(property.name) %>)MGL<%- camelize(property.name) %>Value {
- MGL<%- camelize(property.name) %> <%- objCName(property) %>;
+- (MGL<%- camelize(enumName(property)) %>)MGL<%- camelize(enumName(property)) %>Value {
+ MGL<%- camelize(enumName(property)) %> <%- objCName(property) %>;
[self getValue:&<%- objCName(property) %>];
return <%- objCName(property) %>;
}
diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h
index cbbd4577d0..93c9e38477 100644
--- a/platform/darwin/src/MGLSymbolStyleLayer.h
+++ b/platform/darwin/src/MGLSymbolStyleLayer.h
@@ -317,27 +317,27 @@ typedef NS_ENUM(NSUInteger, MGLTextTransform) {
};
/**
- The property allows to control an orientation of a symbol. Note, that the
- property values act as a hint, so that Symbols whose language doesn't support
- provided orientation, will be laid out in their natural orientation. Example:
- English point symbol will be rendered horizontally even if `"textWritingMode":
- ["vertical"]` is set. The order of elements in an array define priority order
- for the placement of an orientation variant.
+ The property allows to control an orientation of a symbol. Note that the
+ property values act as a hint, so that a symbol whose language doesn’t support
+ the provided orientation will be laid out in its natural orientation. Example:
+ English point symbol will be rendered horizontally even if array value contains
+ single 'vertical' enum value. The order of elements in an array define priority
+ order for the placement of an orientation variant.
Values of this type are used in the `MGLSymbolStyleLayer.textWritingModes`
property.
*/
-typedef NS_ENUM(NSUInteger, MGLTextWritingModes) {
+typedef NS_ENUM(NSUInteger, MGLTextWritingMode) {
/**
If a text's language supports horizontal writing mode, symbols with point
placement would be laid out horizontally.
*/
- MGLTextWritingModesHorizontal,
+ MGLTextWritingModeHorizontal,
/**
If a text's language supports vertical writing mode, symbols with point
placement would be laid out vertically.
*/
- MGLTextWritingModesVertical,
+ MGLTextWritingModeVertical,
};
/**
@@ -1671,12 +1671,12 @@ MGL_EXPORT
@property (nonatomic, null_resettable) NSExpression *textVariableAnchor;
/**
- The property allows to control an orientation of a symbol. Note, that the
- property values act as a hint, so that Symbols whose language doesn't support
- provided orientation, will be laid out in their natural orientation. Example:
- English point symbol will be rendered horizontally even if `"textWritingMode":
- ["vertical"]` is set. The order of elements in an array define priority order
- for the placement of an orientation variant.
+ The property allows to control an orientation of a symbol. Note that the
+ property values act as a hint, so that a symbol whose language doesn’t support
+ the provided orientation will be laid out in its natural orientation. Example:
+ English point symbol will be rendered horizontally even if array value contains
+ single 'vertical' enum value. The order of elements in an array define priority
+ order for the placement of an orientation variant.
This property is only applied to the style if `text` is non-`nil`, and
`symbolPlacement` is set to an expression that evaluates to or
@@ -1688,7 +1688,7 @@ MGL_EXPORT
You can set this property to an expression containing any of the following:
- * Constant `MGLTextWritingModes` array values
+ * Constant `MGLTextWritingMode` array values
* Constant array, whose each element is any of the following constant string
values:
* `horizontal`: If a text's language supports horizontal writing mode,
@@ -2446,17 +2446,17 @@ MGL_EXPORT
@property (readonly) MGLTextTransform MGLTextTransformValue;
/**
- Creates a new value object containing the given `MGLTextWritingModes` enumeration.
+ Creates a new value object containing the given `MGLTextWritingMode` enumeration.
@param textWritingModes The value for the new object.
@return A new value object that contains the enumeration value.
*/
-+ (instancetype)valueWithMGLTextWritingModes:(MGLTextWritingModes)textWritingModes;
++ (instancetype)valueWithMGLTextWritingMode:(MGLTextWritingMode)textWritingModes;
/**
- The `MGLTextWritingModes` enumeration representation of the value.
+ The `MGLTextWritingMode` enumeration representation of the value.
*/
-@property (readonly) MGLTextWritingModes MGLTextWritingModesValue;
+@property (readonly) MGLTextWritingMode MGLTextWritingModeValue;
/**
Creates a new value object containing the given `MGLIconTranslationAnchor` enumeration.
diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm
index e60da45a38..e89b9c3e88 100644
--- a/platform/darwin/src/MGLSymbolStyleLayer.mm
+++ b/platform/darwin/src/MGLSymbolStyleLayer.mm
@@ -96,9 +96,9 @@ namespace mbgl {
{ MGLTextTransformLowercase, "lowercase" },
});
- MBGL_DEFINE_ENUM(MGLTextWritingModes, {
- { MGLTextWritingModesHorizontal, "horizontal" },
- { MGLTextWritingModesVertical, "vertical" },
+ MBGL_DEFINE_ENUM(MGLTextWritingMode, {
+ { MGLTextWritingModeHorizontal, "horizontal" },
+ { MGLTextWritingModeVertical, "vertical" },
});
MBGL_DEFINE_ENUM(MGLIconTranslationAnchor, {
@@ -1032,7 +1032,7 @@ namespace mbgl {
MGLAssertStyleLayerIsValid();
MGLLogDebug(@"Setting textWritingModes: %@", textWritingModes);
- auto mbglValue = MGLStyleValueTransformer<std::vector<mbgl::style::TextWritingModeType>, NSArray<NSValue *> *, mbgl::style::TextWritingModeType, MGLTextWritingModes>().toPropertyValue<mbgl::style::PropertyValue<std::vector<mbgl::style::TextWritingModeType>>>(textWritingModes, false);
+ auto mbglValue = MGLStyleValueTransformer<std::vector<mbgl::style::TextWritingModeType>, NSArray<NSValue *> *, mbgl::style::TextWritingModeType, MGLTextWritingMode>().toPropertyValue<mbgl::style::PropertyValue<std::vector<mbgl::style::TextWritingModeType>>>(textWritingModes, false);
self.rawLayer->setTextWritingMode(mbglValue);
}
@@ -1043,7 +1043,7 @@ namespace mbgl {
if (propertyValue.isUndefined()) {
propertyValue = self.rawLayer->getDefaultTextWritingMode();
}
- return MGLStyleValueTransformer<std::vector<mbgl::style::TextWritingModeType>, NSArray<NSValue *> *, mbgl::style::TextWritingModeType, MGLTextWritingModes>().toExpression(propertyValue);
+ return MGLStyleValueTransformer<std::vector<mbgl::style::TextWritingModeType>, NSArray<NSValue *> *, mbgl::style::TextWritingModeType, MGLTextWritingMode>().toExpression(propertyValue);
}
- (void)setTextWritingMode:(NSExpression *)textWritingMode {
@@ -1629,12 +1629,12 @@ namespace mbgl {
return textTransform;
}
-+ (NSValue *)valueWithMGLTextWritingModes:(MGLTextWritingModes)textWritingModes {
- return [NSValue value:&textWritingModes withObjCType:@encode(MGLTextWritingModes)];
++ (NSValue *)valueWithMGLTextWritingMode:(MGLTextWritingMode)textWritingModes {
+ return [NSValue value:&textWritingModes withObjCType:@encode(MGLTextWritingMode)];
}
-- (MGLTextWritingModes)MGLTextWritingModesValue {
- MGLTextWritingModes textWritingModes;
+- (MGLTextWritingMode)MGLTextWritingModeValue {
+ MGLTextWritingMode textWritingModes;
[self getValue:&textWritingModes];
return textWritingModes;
}
diff --git a/platform/darwin/test/MGLStyleLayerTests.mm.ejs b/platform/darwin/test/MGLStyleLayerTests.mm.ejs
index 4a38070007..14c7c397d3 100644
--- a/platform/darwin/test/MGLStyleLayerTests.mm.ejs
+++ b/platform/darwin/test/MGLStyleLayerTests.mm.ejs
@@ -214,7 +214,7 @@
<% for (let property of enumProperties) { -%>
<% for (let value in property.values) { -%>
<% if (property.values.hasOwnProperty(value)) { -%>
- XCTAssertEqual([NSValue valueWithMGL<%- camelize(property.name) %>:MGL<%- camelize(property.name) %><%- camelize(value) %>].MGL<%- camelize(property.name) %>Value, MGL<%- camelize(property.name) %><%- camelize(value) %>);
+ XCTAssertEqual([NSValue valueWithMGL<%- camelize(enumName(property)) %>:MGL<%- camelize(enumName(property)) %><%- camelize(value) %>].MGL<%- camelize(enumName(property)) %>Value, MGL<%- camelize(enumName(property)) %><%- camelize(value) %>);
<% } -%>
<% } -%>
<% } -%>
diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm
index af7feed39c..5cc9c3c332 100644
--- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm
+++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm
@@ -3193,8 +3193,8 @@
XCTAssertEqual([NSValue valueWithMGLTextTransform:MGLTextTransformNone].MGLTextTransformValue, MGLTextTransformNone);
XCTAssertEqual([NSValue valueWithMGLTextTransform:MGLTextTransformUppercase].MGLTextTransformValue, MGLTextTransformUppercase);
XCTAssertEqual([NSValue valueWithMGLTextTransform:MGLTextTransformLowercase].MGLTextTransformValue, MGLTextTransformLowercase);
- XCTAssertEqual([NSValue valueWithMGLTextWritingModes:MGLTextWritingModesHorizontal].MGLTextWritingModesValue, MGLTextWritingModesHorizontal);
- XCTAssertEqual([NSValue valueWithMGLTextWritingModes:MGLTextWritingModesVertical].MGLTextWritingModesValue, MGLTextWritingModesVertical);
+ XCTAssertEqual([NSValue valueWithMGLTextWritingMode:MGLTextWritingModeHorizontal].MGLTextWritingModeValue, MGLTextWritingModeHorizontal);
+ XCTAssertEqual([NSValue valueWithMGLTextWritingMode:MGLTextWritingModeVertical].MGLTextWritingModeValue, MGLTextWritingModeVertical);
XCTAssertEqual([NSValue valueWithMGLIconTranslationAnchor:MGLIconTranslationAnchorMap].MGLIconTranslationAnchorValue, MGLIconTranslationAnchorMap);
XCTAssertEqual([NSValue valueWithMGLIconTranslationAnchor:MGLIconTranslationAnchorViewport].MGLIconTranslationAnchorValue, MGLIconTranslationAnchorViewport);
XCTAssertEqual([NSValue valueWithMGLTextTranslationAnchor:MGLTextTranslationAnchorMap].MGLTextTranslationAnchorValue, MGLTextTranslationAnchorMap);