Skip to content

Fix method name collisions for getProperties() #434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix method name collisions for getProperties()
  • Loading branch information
mrinaudo-aws committed Jan 10, 2024
commit 7685b419f2b85df575972db7d51d7887447c9f10
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ source env/bin/activate
pip3 install -e /path/to/cloudformation-cli-java-plugin
```

Install `pytest-cov`, used when running unit tests for this plugin:

```shell
pip3 install pytest-cov
```

You may also want to check out the [CloudFormation CLI](https://github.com/aws-cloudformation/cloudformation-cli) if you wish to make edits to that. In this case, installing them in one operation works well:

```shell
Expand Down
22 changes: 21 additions & 1 deletion python/rpdk/java/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,28 @@
}


# Keywords used in the context of AWS CloudFormation Hooks. For
# example, the `properties` item below is excluded because if a target
# resource type has a property called `properties` (see the
# `AWS::ApiGateway::DocumentationPart` resource type as one of the
# examples), the generated class code for the target resource type
# will contain a getter, `getProperties()`, that will collide with
# `getProperties()` that is already defined for
# `ResourceHookTarget`. By excluding `properties`, the generated code
# for the class will still have a private variable, but whose name
# will contain an underscore as a suffix: the Lombok-generated getter
# (and setter) for that private variable will, in turn, contain an
# underscore suffix as well; see `safe_reserved()` below for the
# implementation of this behavior (`safe_reserved()` is, in turn,
# consumed by other parts of the code generation logic in this
# plugin).
HOOKS_KEYWORDS = {
"properties",
}


def safe_reserved(token):
if token in LANGUAGE_KEYWORDS:
if token in LANGUAGE_KEYWORDS or token in HOOKS_KEYWORDS:
return token + "_"
return token

Expand Down