Skip to content
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

Add instanceof argument checking methods to KiwiPreconditions #980

Closed
sleberknight opened this issue May 13, 2023 · 0 comments · Fixed by #982
Closed

Add instanceof argument checking methods to KiwiPreconditions #980

sleberknight opened this issue May 13, 2023 · 0 comments · Fixed by #982
Assignees
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

sleberknight commented May 13, 2023

In kiwi-beta I recently needed to check that an argument was not of a specific type:

checkArgument(!(simpleType instanceof ParameterizedType),
        "Do not call this method with a ParameterizedType. Use TypeInfo#ofType or TypeInfo#ofParameterizedType.");

This task is to add methods to KiwiPreconditions to check if an argument is an instance of a given type, or not of a given type.

Proposed base method signatures:

  • void checkArgumentInstanceOf(Object argument, Class<?> requiredType)
  • void checkArgumentNotInstanceOf(Object argument, Class<?> restrictedType)

Since you can't use instanceof with a variable, these will have to use Class#isAssignableFrom instead.

In addition, there should be the standard three variants of each of the above:

  1. base method
  2. base method + message
  3. base method + message template + template arguments
@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label May 13, 2023
@sleberknight sleberknight self-assigned this May 13, 2023
@sleberknight sleberknight added this to the 2.6.0 milestone May 20, 2023
sleberknight added a commit that referenced this issue May 20, 2023
* Add checkArgumentInstanceOf with three standard variants
* Add checkArgumentNotInstanceOf with three standard variants
* Suppress several "data flow" issues when IntelliJ can detect
  that a method "always fails according to its contracts" because
  that's what we're verifying here
* Minor grammar cleanup in javadocs

Closes #980
dsingley pushed a commit that referenced this issue May 22, 2023
* Add checkArgumentInstanceOf with three standard variants
* Add checkArgumentNotInstanceOf with three standard variants
* Suppress several "data flow" issues when IntelliJ can detect
  that a method "always fails according to its contracts" because
  that's what we're verifying here
* Minor grammar cleanup in javadocs

Closes #980
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant