diff options
author | Aleksandr Mishchenko <AMishchenko@luxoft.com> | 2020-03-10 20:30:26 +0100 |
---|---|---|
committer | Aleksandr Mishchenko <AMishchenko@luxoft.com> | 2020-03-10 20:30:26 +0100 |
commit | abb19f31a42d7d41122109e8a4993b7a4fb266cb (patch) | |
tree | d528403f948c5aa74227cffa7230be9e04ee8e76 | |
parent | 50a2d3ea9e7bd7f95cc8f693856ef7451085f736 (diff) | |
download | sdl_ios-abb19f31a42d7d41122109e8a4993b7a4fb266cb.tar.gz |
changing according to review comments
-rw-r--r-- | generator/README.md | 97 | ||||
-rw-r--r-- | generator/generator.py | 8 | ||||
-rw-r--r-- | generator/templates/copyright.txt | 60 | ||||
-rw-r--r-- | generator/templates/functions/template.m | 5 |
4 files changed, 67 insertions, 103 deletions
diff --git a/generator/README.md b/generator/README.md index 877cdb023..815a89bdc 100644 --- a/generator/README.md +++ b/generator/README.md @@ -104,9 +104,9 @@ Where the **xxx** is the correspondent item name. All files should begin with the license information. -``` +```jinja2 /* - * Copyright (c) 2017 - [year], SmartDeviceLink Consortium, Inc. + * Copyright (c) {{year}}, SmartDeviceLink Consortium, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -141,11 +141,13 @@ All files should begin with the license information. Where `[year]` in the copyright line is the current (?) year. ### General rules for Objective-C classes -1. Default initializer in every class +1. Default initializer applies only to Functions(Request / Response / Notification) classes + ```objc - (instancetype)init { - if ((self = [super initWithName:SDLRPCFunctionNameRegisterAppInterface])) { - } + self = [super initWithName:SDLRPCFunctionNameRegisterAppInterface]; + if (!self) { return nil; } + return self; } ``` @@ -197,13 +199,8 @@ extern SDLTouchType const SDLTouchTypeBegin; If an item is deprecated then it will be declared as such: ```objc -extern SDLTouchType const SDLTouchTypeBegin __deprecated; -``` - -or even: - -```objc -extern SDLTouchType const SDLTouchTypeBegin __deprecated_msg(("this item is deprecated once and for all, please use SDLTouchTypeNewType instead")); +__deprecated +extern SDLTouchType const SDLTouchTypeBegin; ``` Take for an instance the enum class KeypressMode @@ -258,13 +255,10 @@ Structures in sdl_ios are implemented as classes derived from the parent class S </struct> ``` - *Please note that all params declared as mandatory="false" and there is one init method with all the params in the generated file. The method* ```+ (instancetype)currentDevice;``` *comes from the old manually made implementation* - *Note: the file begins with the `NS_ASSUME_NONNULL_BEGIN` macro, which makes all properties / parameters mandatory. If a parameter is not mandatory, then the modifier `nullable` must be used* ```objc // SDLDeviceInfo.h -// #import "SDLRPCStruct.h" @@ -277,18 +271,13 @@ NS_ASSUME_NONNULL_BEGIN */ @interface SDLDeviceInfo : SDLRPCStruct -/// Convenience init. Object will contain all information about the connected device automatically. -/// -/// @return An SDLDeviceInfo object -+ (instancetype)currentDevice; - /** - * @param hardware - * @param firmwareRev - * @param os - * @param osVersion - * @param carrier - * @param @(maxNumberRFCOMMPorts) + * @param hardware - hardware + * @param firmwareRev - firmwareRev + * @param os - os + * @param osVersion - osVersion + * @param carrier - carrier + * @param maxNumberRFCOMMPorts - @(maxNumberRFCOMMPorts) * @return A SDLDeviceInfo object */ - (instancetype)initWithHardware:(nullable NSString *)hardware firmwareRev:(nullable NSString *)firmwareRev os:(nullable NSString *)os osVersion:(nullable NSString *)osVersion carrier:(nullable NSString *)carrier maxNumberRFCOMMPorts:(UInt8)maxNumberRFCOMMPorts; @@ -296,48 +285,36 @@ NS_ASSUME_NONNULL_BEGIN /** * Device model * {"default_value": null, "max_length": 500, "min_length": 0} - * - * Optional, NSString * */ @property (nullable, strong, nonatomic) NSString *hardware; /** * Device firmware revision * {"default_value": null, "max_length": 500, "min_length": 0} - * - * Optional, NSString * */ @property (nullable, strong, nonatomic) NSString *firmwareRev; /** * Device OS * {"default_value": null, "max_length": 500, "min_length": 0} - * - * Optional, NSString * */ @property (nullable, strong, nonatomic) NSString *os; /** * Device OS version * {"default_value": null, "max_length": 500, "min_length": 0} - * - * Optional, NSString * */ @property (nullable, strong, nonatomic) NSString *osVersion; /** * Device mobile carrier (if applicable) * {"default_value": null, "max_length": 500, "min_length": 0} - * - * Optional, NSString * */ @property (nullable, strong, nonatomic) NSString *carrier; /** * Omitted if connected not via BT. * {"default_value": null, "max_value": 100, "min_value": 0} - * - * Optional, UInt8 */ @property (nullable, strong, nonatomic) NSNumber<SDLUInt> *maxNumberRFCOMMPorts; @@ -350,7 +327,6 @@ The implementation **SDLDeviceInfo.m** file: ```objc // SDLDeviceInfo.m -// #import "SDLDeviceInfo.h" #import "NSMutableDictionary+Store.h" @@ -360,22 +336,6 @@ NS_ASSUME_NONNULL_BEGIN @implementation SDLDeviceInfo - -+ (instancetype)currentDevice { - static SDLDeviceInfo *deviceInfo = nil; - if (deviceInfo == nil) { - deviceInfo = [[SDLDeviceInfo alloc] init]; - deviceInfo.hardware = [UIDevice currentDevice].model; - deviceInfo.os = [UIDevice currentDevice].systemName; - deviceInfo.osVersion = [UIDevice currentDevice].systemVersion; - CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init]; - CTCarrier *carrier = netinfo.subscriberCellularProvider; - NSString *carrierName = carrier.carrierName; - deviceInfo.carrier = carrierName; - } - return deviceInfo; -} - - (instancetype)initWithHardware:(nullable NSString *)hardware firmwareRev:(nullable NSString *)firmwareRev os:(nullable NSString *)os osVersion:(nullable NSString *)osVersion carrier:(nullable NSString *)carrier maxNumberRFCOMMPorts:(UInt8)maxNumberRFCOMMPorts { self = [super init]; if (!self) { @@ -399,27 +359,27 @@ NS_ASSUME_NONNULL_BEGIN } - (void)setFirmwareRev:(nullable NSString *)firmwareRev { - [self.store sdl_setObject:firmwareRev forName:SDLRPCParameterNameFirmwareRevision]; + [self.store sdl_setObject:firmwareRev forName:SDLRPCParameterNameFirmwareRev]; } - (nullable NSString *)firmwareRev { - return [self.store sdl_objectForName:SDLRPCParameterNameFirmwareRevision ofClass:NSString.class error:nil]; + return [self.store sdl_objectForName:SDLRPCParameterNameFirmwareRev ofClass:NSString.class error:nil]; } - (void)setOs:(nullable NSString *)os { - [self.store sdl_setObject:os forName:SDLRPCParameterNameOS]; + [self.store sdl_setObject:os forName:SDLRPCParameterNameOs]; } - (nullable NSString *)os { - return [self.store sdl_objectForName:SDLRPCParameterNameOS ofClass:NSString.class error:nil]; + return [self.store sdl_objectForName:SDLRPCParameterNameOs ofClass:NSString.class error:nil]; } - (void)setOsVersion:(nullable NSString *)osVersion { - [self.store sdl_setObject:osVersion forName:SDLRPCParameterNameOSVersion]; + [self.store sdl_setObject:osVersion forName:SDLRPCParameterNameOsVersion]; } - (nullable NSString *)osVersion { - return [self.store sdl_objectForName:SDLRPCParameterNameOSVersion ofClass:NSString.class error:nil]; + return [self.store sdl_objectForName:SDLRPCParameterNameOsVersion ofClass:NSString.class error:nil]; } - (void)setCarrier:(nullable NSString *)carrier { @@ -594,8 +554,9 @@ NS_ASSUME_NONNULL_BEGIN #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - (instancetype)init { - if ((self = [super initWithName:SDLRPCFunctionNameGetCloudAppProperties])) { - } + self = [super initWithName:SDLRPCFunctionNameGetCloudAppProperties]; + if (!self) { return nil; } + return self; } #pragma clang diagnostic pop @@ -708,8 +669,9 @@ NS_ASSUME_NONNULL_BEGIN #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - (instancetype)init { - if ((self = [super initWithName:SDLRPCFunctionNameAlert])) { - } + self = [super initWithName:SDLRPCFunctionNameShowAppMenu]; + if (!self) { return nil; } + return self; } #pragma clang diagnostic pop @@ -791,8 +753,9 @@ NS_ASSUME_NONNULL_BEGIN #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - (instancetype)init { - if ((self = [super initWithName:SDLRPCFunctionNameOnAppInterfaceUnregistered])) { - } + self = [super initWithName:SDLRPCFunctionNameOnAppInterfaceUnregistered]; + if (!self) { return nil; } + return self; } #pragma clang diagnostic pop diff --git a/generator/generator.py b/generator/generator.py index d9c91ac61..85a27342b 100644 --- a/generator/generator.py +++ b/generator/generator.py @@ -16,7 +16,7 @@ from re import findall from jinja2 import UndefinedError, TemplateNotFound, FileSystemLoader, Environment, ChoiceLoader, \ TemplateAssertionError, TemplateSyntaxError, TemplateRuntimeError -from pathlib2 import Path +from pathlib import Path ROOT = Path(__file__).absolute().parents[0] @@ -71,7 +71,7 @@ class Generator: if output_directory.startswith('/'): path = Path(output_directory).absolute().resolve() else: - path = ROOT.joinpath(output_directory).resolve() + path = Path('.').absolute().joinpath(output_directory).resolve() if not path.exists(): self.logger.warning('Directory not found: %s, trying to create it', path) try: @@ -202,7 +202,7 @@ class Generator: if not getattr(args, kind.name) and kind.path.exists(): while True: try: - confirm = input('Confirm default path {} for {} Y/Enter = yes, N = no' + confirm = input('Confirm default path {} for {} [Y/n]:\t' .format(kind.path, kind.name)) if confirm.lower() == 'y' or not confirm: print('{} set to {}'.format(kind.name, kind.path)) @@ -378,7 +378,7 @@ class Generator: else: while True: try: - confirm = input('File already exists {}. Overwrite? Y/Enter = yes, N = no\n' + confirm = input('File already exists {}. Overwrite? [Y/n]:\t' .format(file_with_suffix.name)) if confirm.lower() == 'y' or not confirm: self.logger.info('Overriding %s', file_with_suffix.name) diff --git a/generator/templates/copyright.txt b/generator/templates/copyright.txt index abb41f0da..a037d487d 100644 --- a/generator/templates/copyright.txt +++ b/generator/templates/copyright.txt @@ -1,31 +1,31 @@ /* -* Copyright (c) {{year}}, SmartDeviceLink Consortium, Inc. -* All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* Redistributions of source code must retain the above copyright notice, this -* list of conditions and the following disclaimer. -* -* Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following -* disclaimer in the documentation and/or other materials provided with the -* distribution. -* -* Neither the name of the SmartDeviceLink Consortium Inc. nor the names of -* its contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/
\ No newline at end of file + * Copyright (c) {{year}}, SmartDeviceLink Consortium, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the SmartDeviceLink Consortium Inc. nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */
\ No newline at end of file diff --git a/generator/templates/functions/template.m b/generator/templates/functions/template.m index 3e5e4bd1c..07fb962be 100644 --- a/generator/templates/functions/template.m +++ b/generator/templates/functions/template.m @@ -8,8 +8,9 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - (instancetype)init { - if ((self = [super initWithName:SDLRPCFunctionName{{origin}}])) { - } + self = [super initWithName:SDLRPCFunctionName{{origin}}]; + if (!self) { return nil; } + return self; } #pragma clang diagnostic pop |