summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2019-04-13 00:32:04 -0400
committerJulian Rex <julian.rex@mapbox.com>2019-04-17 16:21:41 -0400
commit2767e618a88cbe1bf7819c89132927ca3e79d167 (patch)
treecc46bb785a5ddc8136fe3e64fda668876c959353
parent7d61b28b7bcf914c26055d71efb4d2b2cb7933e5 (diff)
downloadqtlocation-mapboxgl-2767e618a88cbe1bf7819c89132927ca3e79d167.tar.gz
[ios] Tweaks for analyzer warnings
-rw-r--r--platform/darwin/src/MGLStyleValue_Private.h2
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm44
-rw-r--r--platform/darwin/src/NSExpression+MGLPrivateAdditions.h4
-rw-r--r--platform/darwin/src/NSPredicate+MGLPrivateAdditions.h6
-rw-r--r--platform/ios/src/MGLMapView.h8
-rw-r--r--platform/ios/src/MGLMapView.mm2
-rw-r--r--platform/ios/src/UIView+MGLAdditions.h2
-rwxr-xr-xplatform/ios/vendor/SMCalloutView/SMCalloutView.m9
8 files changed, 47 insertions, 30 deletions
diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h
index fee34b4b71..376bf5e73b 100644
--- a/platform/darwin/src/MGLStyleValue_Private.h
+++ b/platform/darwin/src/MGLStyleValue_Private.h
@@ -291,7 +291,7 @@ private: // Private utilities for converting from mbgl to mgl values
}
// Array
- static ObjCType toMGLRawStyleValue(const std::vector<MBGLElement> &mbglStopValue) {
+ static NSArray<NSExpression*> *toMGLRawStyleValue(const std::vector<MBGLElement> &mbglStopValue) {
NSMutableArray *array = [NSMutableArray arrayWithCapacity:mbglStopValue.size()];
for (const auto &mbglElement: mbglStopValue) {
[array addObject:[NSExpression expressionForConstantValue:toMGLRawStyleValue(mbglElement)]];
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index 9dad00e56e..fe2e5a0a31 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -792,19 +792,24 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
} else if ([curveType isEqualToString:@"cubic-bezier"]) {
curveParameters = @[@"literal", [interpolationOptions subarrayWithRange:NSMakeRange(1, 4)]];
}
- NSExpression *curveParameterExpression = [NSExpression expressionWithMGLJSONObject:curveParameters];
- argumentObjects = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)];
- NSExpression *inputExpression = [NSExpression expressionWithMGLJSONObject:argumentObjects.firstObject];
- NSArray *stopExpressions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)];
- NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:stopExpressions.count / 2];
- NSEnumerator *stopEnumerator = stopExpressions.objectEnumerator;
- while (NSNumber *key = stopEnumerator.nextObject) {
- NSExpression *valueExpression = stopEnumerator.nextObject;
- stops[key] = [NSExpression expressionWithMGLJSONObject:valueExpression];
+
+ NSAssert(curveParameters, @"curveParameters should be non-nil");
+ if (curveParameters) {
+ NSExpression *curveParameterExpression = [NSExpression expressionWithMGLJSONObject:curveParameters];
+ argumentObjects = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)];
+ NSExpression *inputExpression = [NSExpression expressionWithMGLJSONObject:argumentObjects.firstObject];
+ NSArray *stopExpressions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)];
+ NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:stopExpressions.count / 2];
+ NSEnumerator *stopEnumerator = stopExpressions.objectEnumerator;
+ while (NSNumber *key = stopEnumerator.nextObject) {
+ NSExpression *valueExpression = stopEnumerator.nextObject;
+ stops[key] = [NSExpression expressionWithMGLJSONObject:valueExpression];
+ }
+ NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops];
+ return [NSExpression expressionForFunction:@"mgl_interpolate:withCurveType:parameters:stops:"
+ arguments:@[inputExpression, curveTypeExpression, curveParameterExpression, stopExpression]];
}
- NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops];
- return [NSExpression expressionForFunction:@"mgl_interpolate:withCurveType:parameters:stops:"
- arguments:@[inputExpression, curveTypeExpression, curveParameterExpression, stopExpression]];
+
} else if ([op isEqualToString:@"step"]) {
NSExpression *inputExpression = [NSExpression expressionWithMGLJSONObject:argumentObjects[0]];
NSArray *stopExpressions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)];
@@ -823,9 +828,14 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
minimum = [NSExpression expressionWithMGLJSONObject:valueExpression];
}
}
- NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops];
- return [NSExpression expressionForFunction:@"mgl_step:from:stops:"
- arguments:@[inputExpression, minimum, stopExpression]];
+
+ NSAssert(minimum, @"minimum should be non-nil");
+ if (minimum) {
+ NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops];
+ return [NSExpression expressionForFunction:@"mgl_step:from:stops:"
+ arguments:@[inputExpression, minimum, stopExpression]];
+ }
+
} else if ([op isEqualToString:@"zoom"]) {
return NSExpression.zoomLevelVariableExpression;
} else if ([op isEqualToString:@"heatmap-density"]) {
@@ -1021,7 +1031,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
}
case NSKeyPathExpressionType: {
- NSArray *expressionObject;
+ NSArray *expressionObject = @[];
NSArray *keyPath = [self.keyPath componentsSeparatedByString:@"."];
for (NSString *pathComponent in keyPath) {
if (expressionObject) {
@@ -1030,6 +1040,8 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
expressionObject = @[@"get", pathComponent];
}
}
+
+ NSAssert(expressionObject.count > 0, @"expressionObject should be non-empty");
return expressionObject;
}
diff --git a/platform/darwin/src/NSExpression+MGLPrivateAdditions.h b/platform/darwin/src/NSExpression+MGLPrivateAdditions.h
index 4ef49a2d15..54bc9068f4 100644
--- a/platform/darwin/src/NSExpression+MGLPrivateAdditions.h
+++ b/platform/darwin/src/NSExpression+MGLPrivateAdditions.h
@@ -13,8 +13,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface NSObject (MGLExpressionAdditions)
-- (NSNumber *)mgl_number;
-- (NSNumber *)mgl_numberWithFallbackValues:(id)fallbackValue, ... NS_REQUIRES_NIL_TERMINATION;
+- (nullable NSNumber *)mgl_number;
+- (nullable NSNumber *)mgl_numberWithFallbackValues:(id)fallbackValue, ... NS_REQUIRES_NIL_TERMINATION;
@end
diff --git a/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h b/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h
index 1828009678..051a2775a1 100644
--- a/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h
+++ b/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h
@@ -10,15 +10,15 @@ NS_ASSUME_NONNULL_BEGIN
- (mbgl::style::Filter)mgl_filter;
-+ (instancetype)mgl_predicateWithFilter:(mbgl::style::Filter)filter;
++ (nullable instancetype)mgl_predicateWithFilter:(mbgl::style::Filter)filter;
@end
@interface NSPredicate (MGLExpressionAdditions)
-- (id)mgl_if:(id)firstValue, ...;
+- (nullable id)mgl_if:(id)firstValue, ...;
-- (id)mgl_match:(NSExpression *)firstCase, ...;
+- (nullable id)mgl_match:(NSExpression *)firstCase, ...;
@end
diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h
index 607a197840..2423d62ee1 100644
--- a/platform/ios/src/MGLMapView.h
+++ b/platform/ios/src/MGLMapView.h
@@ -1130,7 +1130,7 @@ MGL_EXPORT
`UIApplicationWillTerminateNotification`; you may receive a `nil` return value
depending on the order of notification delivery.
*/
-- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets;
+- (nullable MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets;
/**
Returns the camera that best fits the given coordinate bounds, with the specified camera,
@@ -1150,7 +1150,7 @@ MGL_EXPORT
`UIApplicationWillTerminateNotification`; you may receive a `nil` return value
depending on the order of notification delivery.
*/
-- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets;
+- (nullable MGLMapCamera *)camera:(MGLMapCamera *)camera fittingCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets;
/**
Returns the camera that best fits the given shape, with the specified camera,
@@ -1169,7 +1169,7 @@ MGL_EXPORT
`UIApplicationWillTerminateNotification`; you may receive a `nil` return value
depending on the order of notification delivery.
*/
-- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape edgePadding:(UIEdgeInsets)insets;
+- (nullable MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape edgePadding:(UIEdgeInsets)insets;
/**
Returns the camera that best fits the given shape, with the specified direction,
@@ -1187,7 +1187,7 @@ MGL_EXPORT
`UIApplicationWillTerminateNotification`; you may receive a `nil` return value
depending on the order of notification delivery.
*/
-- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets;
+- (nullable MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets;
/**
Returns the point in this view’s coordinate system on which to "anchor" in
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index cadf5be3fd..7365c02c29 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -2478,7 +2478,7 @@ public:
}];
[attributionController addAction:telemetryAction];
- NSString *cancelTitle = NSLocalizedStringWithDefaultValue(@"CANCEL", nil, nil, @"Cancel", @"");
+ NSString *cancelTitle = NSLocalizedStringWithDefaultValue(@"CANCEL", nil, nil, @"Cancel", @"Cancel");
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle
style:UIAlertActionStyleCancel
handler:NULL];
diff --git a/platform/ios/src/UIView+MGLAdditions.h b/platform/ios/src/UIView+MGLAdditions.h
index 85fea31ad2..ef074215b3 100644
--- a/platform/ios/src/UIView+MGLAdditions.h
+++ b/platform/ios/src/UIView+MGLAdditions.h
@@ -4,7 +4,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface UIView (MGLAdditions)
-- (UIViewController *)mgl_viewControllerForLayoutGuides;
+- (nullable UIViewController *)mgl_viewControllerForLayoutGuides;
- (NSLayoutYAxisAnchor *)mgl_safeTopAnchor;
diff --git a/platform/ios/vendor/SMCalloutView/SMCalloutView.m b/platform/ios/vendor/SMCalloutView/SMCalloutView.m
index 66a7b5a7a7..0520ba08a5 100755
--- a/platform/ios/vendor/SMCalloutView/SMCalloutView.m
+++ b/platform/ios/vendor/SMCalloutView/SMCalloutView.m
@@ -554,13 +554,18 @@ NSTimeInterval const kMGLSMCalloutViewRepositionDelayForUIScrollView = 1.0/3.0;
stretch.toValue = presenting ? @1.0 : @0.0;
animation = stretch;
}
-
+
+ NSAssert(animation, @"There should be an animation");
+
// CAAnimation is KVC compliant, so we can store whether we're presenting for lookup in our delegate methods
[animation setValue:@(presenting) forKey:@"presenting"];
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
- return animation;
+
+ // Cast as non-null to mute static analysis warning as documented at
+ // https://clang-analyzer.llvm.org/faq.html#decide_nullability
+ return (CAAnimation * _Nonnull)animation;
}
- (void)layoutSubviews {