|
58 | 58 | }
|
59 | 59 |
|
60 | 60 |
|
| 61 | +# Keywords used in the context of AWS CloudFormation Hooks, when |
| 62 | +# classes are generated, by this plugin, for target resource |
| 63 | +# types. For example, the `properties` item below is marked as a |
| 64 | +# keyword because if a target resource type has a property called |
| 65 | +# `Properties` (see the `AWS::ApiGateway::DocumentationPart` resource |
| 66 | +# type as one of the examples), the generated class code for the |
| 67 | +# target resource type will contain a getter, `getProperties()`, that |
| 68 | +# will collide with `getProperties()` that is already defined for |
| 69 | +# `ResourceHookTarget`. By marking `properties` as a keyword, the |
| 70 | +# generated code for the class will still have a relevant, private |
| 71 | +# variable for the resource type target's property, but whose name |
| 72 | +# will contain an underscore as a suffix: the Lombok-generated getter |
| 73 | +# (and setter) for that private variable will, in turn, contain an |
| 74 | +# underscore suffix as well; see `safe_reserved_hook_target()` below |
| 75 | +# for more information (`safe_reserved_hook_target()` is, in turn, |
| 76 | +# consumed by other parts of a hook's code generation logic in this |
| 77 | +# plugin). |
| 78 | +HOOK_TARGET_KEYWORDS = { |
| 79 | + "properties", |
| 80 | +} |
| 81 | + |
| 82 | + |
61 | 83 | def safe_reserved(token):
|
62 | 84 | if token in LANGUAGE_KEYWORDS:
|
63 | 85 | return token + "_"
|
64 | 86 | return token
|
65 | 87 |
|
66 | 88 |
|
| 89 | +# This is a specialized method for hooks only. In addition to using |
| 90 | +# LANGUAGE_KEYWORDS (used by safe_reserved()), this function uses |
| 91 | +# HOOK_TARGET_KEYWORDS: the reason for having such a specialized |
| 92 | +# method is that since excluding `properties` will alter an affected |
| 93 | +# target's getters and setters (see this specific case explained in |
| 94 | +# comments for `HOOK_TARGET_KEYWORDS`), we do not want to have the |
| 95 | +# same behavior for resource type extensions, that you also model with |
| 96 | +# this plugin of the CloudFormation CLI. |
| 97 | +def safe_reserved_hook_target(token): |
| 98 | + if token in LANGUAGE_KEYWORDS or token in HOOK_TARGET_KEYWORDS: |
| 99 | + return token + "_" |
| 100 | + return token |
| 101 | + |
| 102 | + |
67 | 103 | def validate_namespace(default):
|
68 | 104 | pattern = r"^[_a-z][_a-z0-9]+$"
|
69 | 105 |
|
|
0 commit comments