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

Fix adapter with question mark only #3314

Merged
merged 6 commits into from
Jun 16, 2022
Merged

Fix adapter with question mark only #3314

merged 6 commits into from
Jun 16, 2022

Conversation

hfhbd
Copy link
Collaborator

@hfhbd hfhbd commented Jun 15, 2022

Fixes #3233

Rather a hack, but works...

val argumentAdapters = PsiTreeUtil.findChildrenOfType(this, SqlBindExpr::class.java)
.mapNotNull { typeResolver.argumentType(it).parentAdapter() }
val binders = PsiTreeUtil.findChildrenOfType(this, SqlBindExpr::class.java)
val argumentAdapters = binders.singleQuestionMark() ?: binders.mapNotNull {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this only works if theres only a single question mark in the whole file

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, added a test with two insert statements

.mapNotNull { typeResolver.argumentType(it).parentAdapter() }
val binders = PsiTreeUtil.findChildrenOfType(this, SqlBindExpr::class.java)
val argumentAdapters = binders.singleQuestionMark() ?: binders.mapNotNull {
typeResolver.argumentType(it).parentAdapter()
Copy link
Collaborator

Choose a reason for hiding this comment

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

you'll want to have your logic live in this function and have it be invoked as a flatMap so that you can expand a single SqlBindExpr to multiple PropertySpec

Copy link
Collaborator

Choose a reason for hiding this comment

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

and the logic would be

.flatMap {
  it.parentOfType<SqlInsertStmt>()?.let {
    if (it.acceptsTableInterface()) return@flatMap listOf(table.adapterProperty())
  }
  return listOf(typeResolver.argumentType(it).parentAdapter())
}.filterNotNull()

Copy link
Collaborator Author

@hfhbd hfhbd Jun 16, 2022

Choose a reason for hiding this comment

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

Thanks, but don't you need if (it.acceptsTableInterface() && it.needsAdapter()) to prevent adding unused and unnecessary adapter property?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah right, because the table has only one adapter not multiple. Yes

@AlecKazakova AlecKazakova merged commit d047c56 into cashapp:master Jun 16, 2022
@hfhbd hfhbd deleted the insertQuestionMarkOnly branch June 16, 2022 13:57
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.

VALUES ? fails to make use of custom adapters
2 participants