-
Notifications
You must be signed in to change notification settings - Fork 496
/
StatementValidatorMixin.kt
46 lines (41 loc) · 1.96 KB
/
StatementValidatorMixin.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package app.cash.sqldelight.dialects.sqlite_3_18.grammar.mixins
import com.alecstrong.sql.psi.core.SqlAnnotationHolder
import com.alecstrong.sql.psi.core.psi.SqlBindExpr
import com.alecstrong.sql.psi.core.psi.SqlCompositeElement
import com.alecstrong.sql.psi.core.psi.SqlTypes
import com.alecstrong.sql.psi.core.psi.impl.SqlStmtImpl
import com.intellij.lang.ASTNode
import com.intellij.psi.tree.TokenSet
open class StatementValidatorMixin(node: ASTNode) : SqlStmtImpl(node) {
private fun SqlCompositeElement.annotateReservedKeywords(annotationHolder: SqlAnnotationHolder) {
if (this is SqlBindExpr) return
children.filterIsInstance<SqlCompositeElement>().forEach {
it.annotateReservedKeywords(annotationHolder)
}
node.getChildren(TokenSet.create(SqlTypes.ID)).forEach {
if (it.text.uppercase() in invalidIds) {
annotationHolder.createErrorAnnotation(this, "Reserved keyword in sqlite")
}
}
}
override fun annotate(annotationHolder: SqlAnnotationHolder) {
if (createVirtualTableStmt != null) {
// Virtual tables do their own text parsing/validation.
return
}
annotateReservedKeywords(annotationHolder)
super.annotate(annotationHolder)
}
companion object {
// If this list needs to be updated see https://github.com/cashapp/sqldelight/issues/1471#issuecomment-565771116
// for details on how to update it.
private val invalidIds = setOf(
"ADD", "ALL", "ALTER", "AND", "AS", "AUTOINCREMENT", "BETWEEN", "CASE", "CHECK", "COLLATE",
"COMMIT", "CONSTRAINT", "CREATE", "DEFAULT", "DEFERRABLE", "DELETE", "DISTINCT", "DROP",
"ELSE", "ESCAPE", "EXCEPT", "EXISTS", "FOREIGN", "FROM", "GROUP", "HAVING", "IN", "INDEX",
"INSERT", "INTERSECT", "INTO", "IS", "ISNULL", "JOIN", "LIMIT", "NOT", "NOTNULL", "NULL",
"OR", "ORDER", "PRIMARY", "REFERENCES", "SELECT", "SET", "TABLE", "THEN", "TO",
"TRANSACTION", "UNION", "UNIQUE", "UPDATE", "USING", "VALUES", "WHEN", "WHERE",
)
}
}