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

Clean up warnings in KotlinJsonAdapter #899

Merged
merged 9 commits into from Sep 5, 2019

Conversation

ZacSweers
Copy link
Collaborator

Misc idiomatic cleanups, nothing functional changing

@@ -186,18 +189,18 @@ class KotlinJsonAdapterFactory : JsonAdapter.Factory {
// Fall back to a reflective adapter when the generated adapter is not found.
}

if (rawType.isLocalClass) {
throw IllegalArgumentException("Cannot serialize local class or object expression ${rawType.name}")
require(!rawType.isLocalClass) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this! Is this new in 1.3.50? I just discovered it the other day.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inspection is new, yes

@ZacSweers ZacSweers merged commit 711de52 into square:master Sep 5, 2019
@ZacSweers ZacSweers deleted the z/KotlinJsonAdapterTuneups branch September 5, 2019 01:39
if (binding == null && !parameter.isOptional) {
throw IllegalArgumentException("No property for required constructor ${parameter}")
}
require(!(binding == null && !parameter.isOptional)) { "No property for required constructor $parameter" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
require(!(binding == null && !parameter.isOptional)) { "No property for required constructor $parameter" }
require(binding != null || parameter.isOptional) { "No property for required constructor $parameter" }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix in a follow-up, didn't know you were doing a pass before merging 😬

@@ -210,13 +213,15 @@ class KotlinJsonAdapterFactory : JsonAdapter.Factory {
val parameter = parametersByName[property.name]

if (Modifier.isTransient(property.javaField?.modifiers ?: 0)) {
@Suppress("ReplaceGuardClauseWithFunctionCall") // More readable this way
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Down below you replaced a similar one

if (parameter != null && !parameter.isOptional) {
throw IllegalArgumentException(
"No default value for transient constructor $parameter")
}
continue
}

@Suppress("ReplaceGuardClauseWithFunctionCall") // More readable this way
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it just parameter == null || parameter.type == property.returnType? That's not bad...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite - the null smartcast no longer works when this is done too. On mobile but in one of these I think it was fine, but in the other it meant nullchecking it's mention in the message

ZacSweers added a commit that referenced this pull request Sep 8, 2019
Followup fixes from the previous PR
ZacSweers added a commit that referenced this pull request Sep 8, 2019
Followup fixes from the previous PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants