Skip to content

Commit

Permalink
Remove some warnings (#3555)
Browse files Browse the repository at this point in the history
* Fix deprecated String lowercase/uppercase functions

* Fix deprecated String capitalize functions

* Fix other warnings

* Fix imports

Co-authored-by: hfhbd <hfhbd@users.noreply.github.com>
  • Loading branch information
hfhbd and hfhbd committed Oct 3, 2022
1 parent 4c0f582 commit 494d5a6
Show file tree
Hide file tree
Showing 23 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class HsqlTypeResolver(private val parentResolver: TypeResolver) : TypeResolver
return functionExpr.hsqlFunctionType() ?: parentResolver.functionType(functionExpr)
}

private fun SqlFunctionExpr.hsqlFunctionType() = when (functionName.text.toLowerCase()) {
private fun SqlFunctionExpr.hsqlFunctionType() = when (functionName.text.lowercase()) {
"coalesce", "ifnull" -> encapsulatingType(exprList, TINY_INT, SMALL_INT, HsqlType.INTEGER, INTEGER, BIG_INT, REAL, TEXT, BLOB)
"max" -> encapsulatingType(exprList, TINY_INT, SMALL_INT, HsqlType.INTEGER, INTEGER, BIG_INT, REAL, TEXT, BLOB).asNullable()
"min" -> encapsulatingType(exprList, BLOB, TEXT, TINY_INT, SMALL_INT, INTEGER, HsqlType.INTEGER, BIG_INT, REAL).asNullable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MySqlTypeResolver(
return functionExpr.mySqlFunctionType() ?: parentResolver.functionType(functionExpr)
}

private fun SqlFunctionExpr.mySqlFunctionType() = when (functionName.text.toLowerCase()) {
private fun SqlFunctionExpr.mySqlFunctionType() = when (functionName.text.lowercase()) {
"greatest" -> encapsulatingType(exprList, INTEGER, REAL, TEXT, BLOB)
"concat" -> encapsulatingType(exprList, TEXT)
"last_insert_id" -> IntermediateType(INTEGER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class PostgreSqlTypeResolver(private val parentResolver: TypeResolver) : TypeRes
return functionExpr.postgreSqlFunctionType() ?: parentResolver.functionType(functionExpr)
}

private fun SqlFunctionExpr.postgreSqlFunctionType() = when (functionName.text.toLowerCase()) {
private fun SqlFunctionExpr.postgreSqlFunctionType() = when (functionName.text.lowercase()) {
"greatest" -> encapsulatingType(exprList, PrimitiveType.INTEGER, REAL, TEXT, BLOB)
"concat" -> encapsulatingType(exprList, TEXT)
"substring" -> IntermediateType(TEXT).nullableIf(resolvedType(exprList[0]).javaType.isNullable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open class SqliteTypeResolver(private val parentResolver: TypeResolver) : TypeRe
}
}

private fun SqlFunctionExpr.sqliteFunctionType() = when (functionName.text.toLowerCase()) {
private fun SqlFunctionExpr.sqliteFunctionType() = when (functionName.text.lowercase()) {
"printf" -> IntermediateType(TEXT).nullableIf(resolvedType(exprList[0]).javaType.isNullable)
"datetime", "julianday", "strftime", "sqlite_compileoption_get", "sqlite_source_id", "sqlite_version" -> {
IntermediateType(TEXT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ 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
import java.util.Locale

open class StatementValidatorMixin(node: ASTNode) : SqlStmtImpl(node) {
private fun SqlCompositeElement.annotateReservedKeywords(annotationHolder: SqlAnnotationHolder) {
Expand All @@ -16,7 +15,7 @@ open class StatementValidatorMixin(node: ASTNode) : SqlStmtImpl(node) {
it.annotateReservedKeywords(annotationHolder)
}
node.getChildren(TokenSet.create(SqlTypes.ID)).forEach {
if (it.text.toUpperCase(Locale.ROOT) in invalidIds) {
if (it.text.uppercase() in invalidIds) {
annotationHolder.createErrorAnnotation(this, "Reserved keyword in sqlite")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.withContext
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmName
import kotlin.jvm.JvmOverloads

/** Turns this [Query] into a [Flow] which emits whenever the underlying result set changes. */
@JvmName("toFlow")
Expand All @@ -55,7 +54,6 @@ fun <T : Any> Query<T>.asFlow(): Flow<Query<T>> = flow {
}
}

@JvmOverloads
fun <T : Any> Flow<Query<T>>.mapToOne(
context: CoroutineContext,
): Flow<T> = map {
Expand All @@ -64,7 +62,6 @@ fun <T : Any> Flow<Query<T>>.mapToOne(
}
}

@JvmOverloads
fun <T : Any> Flow<Query<T>>.mapToOneOrDefault(
defaultValue: T,
context: CoroutineContext,
Expand All @@ -74,7 +71,6 @@ fun <T : Any> Flow<Query<T>>.mapToOneOrDefault(
}
}

@JvmOverloads
fun <T : Any> Flow<Query<T>>.mapToOneOrNull(
context: CoroutineContext,
): Flow<T?> = map {
Expand All @@ -83,7 +79,6 @@ fun <T : Any> Flow<Query<T>>.mapToOneOrNull(
}
}

@JvmOverloads
fun <T : Any> Flow<Query<T>>.mapToOneNotNull(
context: CoroutineContext,
): Flow<T> = mapNotNull {
Expand All @@ -92,7 +87,6 @@ fun <T : Any> Flow<Query<T>>.mapToOneNotNull(
}
}

@JvmOverloads
fun <T : Any> Flow<Query<T>>.mapToList(
context: CoroutineContext,
): Flow<List<T>> = map {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package app.cash.sqldelight.core

fun String.capitalize() = replaceFirstChar { if (it.isLowerCase()) it.titlecaseChar() else it }

fun String.decapitalize() = replaceFirstChar { if (it.isLowerCase()) it else it.lowercaseChar() }
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.cash.sqldelight.core.compiler

import app.cash.sqldelight.core.capitalize
import app.cash.sqldelight.core.compiler.model.NamedExecute
import app.cash.sqldelight.core.compiler.model.NamedMutator
import app.cash.sqldelight.core.lang.argumentType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package app.cash.sqldelight.core.compiler

import app.cash.sqldelight.core.capitalize
import app.cash.sqldelight.core.compiler.model.NamedQuery
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier.DATA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package app.cash.sqldelight.core.compiler

import app.cash.sqldelight.core.SqlDelightFileIndex
import app.cash.sqldelight.core.capitalize
import app.cash.sqldelight.core.compiler.model.NamedQuery
import app.cash.sqldelight.core.compiler.model.SelectQueryable
import app.cash.sqldelight.core.lang.MigrationFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package app.cash.sqldelight.core.compiler

import app.cash.sqldelight.core.capitalize
import app.cash.sqldelight.core.compiler.SqlDelightCompiler.allocateName
import app.cash.sqldelight.core.compiler.integration.javadocText
import app.cash.sqldelight.core.lang.ADAPTER_NAME
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.cash.sqldelight.core.compiler.integration

import app.cash.sqldelight.core.capitalize
import app.cash.sqldelight.core.compiler.SqlDelightCompiler
import app.cash.sqldelight.core.lang.ADAPTER_NAME
import app.cash.sqldelight.core.lang.SqlDelightFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package app.cash.sqldelight.core.compiler.model

import app.cash.sqldelight.core.capitalize
import app.cash.sqldelight.core.compiler.SqlDelightCompiler.allocateName
import app.cash.sqldelight.core.lang.acceptsTableInterface
import app.cash.sqldelight.core.lang.psi.ColumnTypeMixin.ValueTypeDialectType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package app.cash.sqldelight.core.compiler.model

import app.cash.sqldelight.core.capitalize
import app.cash.sqldelight.core.compiler.SqlDelightCompiler.allocateName
import app.cash.sqldelight.core.decapitalize
import app.cash.sqldelight.core.lang.SqlDelightQueriesFile
import app.cash.sqldelight.core.lang.cursorGetter
import app.cash.sqldelight.core.lang.parentAdapter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package app.cash.sqldelight.core.lang

import app.cash.sqldelight.core.capitalize
import app.cash.sqldelight.core.decapitalize
import com.intellij.openapi.vfs.VirtualFile
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package app.cash.sqldelight.core.lang.psi

import app.cash.sqldelight.core.capitalize
import app.cash.sqldelight.core.compiler.SqlDelightCompiler.allocateName
import app.cash.sqldelight.core.lang.types.typeResolver
import app.cash.sqldelight.core.lang.util.parentOfType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ internal fun SqlExpr.argumentType(argument: SqlExpr): IntermediateType {
}

is SqlFunctionExpr -> {
fun argumentType(expr: SqlExpr) = when (functionName.text.toLowerCase()) {
fun argumentType(expr: SqlExpr) = when (functionName.text.lowercase()) {
"instr" -> when (expr) {
exprList.getOrNull(1) -> IntermediateType(TEXT)
else -> typeResolver.functionType(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal object AnsiSqlTypeResolver : TypeResolver {
}
}

private fun SqlFunctionExpr.typeReturned() = when (functionName.text.toLowerCase()) {
private fun SqlFunctionExpr.typeReturned() = when (functionName.text.lowercase()) {
"round" -> {
// Single arg round function returns an int. Otherwise real.
if (exprList.size == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private fun PsiElement.rangesToReplace(): List<Pair<IntRange, String>> {
second = "",
),
)
} else if (this is SqlModuleArgument && moduleArgumentDef?.columnDef != null && (parent as SqlCreateVirtualTableStmt).moduleName?.text?.toLowerCase() == "fts5") {
} else if (this is SqlModuleArgument && moduleArgumentDef?.columnDef != null && (parent as SqlCreateVirtualTableStmt).moduleName?.text?.lowercase() == "fts5") {
val columnDef = moduleArgumentDef!!.columnDef!!
// If there is a space at the end of the constraints, preserve it.
val lengthModifier = if (columnDef.columnConstraintList.isNotEmpty() && columnDef.columnConstraintList.last()?.lastChild?.prevSibling is PsiWhiteSpace) 1 else 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app.cash.sqldelight.gradle

import app.cash.sqldelight.VERSION
import app.cash.sqldelight.core.capitalize
import app.cash.sqldelight.core.lang.MigrationFileType
import app.cash.sqldelight.core.lang.SqlDelightFileType
import app.cash.sqldelight.gradle.kotlin.Source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ internal class SqlDelightClassNameElementAnnotator : Annotator {
): PsiElement {
val elementText = javaTypeMixin.text
val className = classes.map { clazz -> findMissingNestedClassName(clazz, elementText) }
.maxBy { it.length }
.maxByOrNull { it.length }
?.substringBefore(".") ?: return javaTypeMixin.firstChild
return javaTypeMixin.children.first { it.textMatches(className) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class SqlDelightCopyPasteProcessor : CopyPastePostProcessor<ReferenceTransferabl
}

val references = values.first().data
if (references.isNullOrEmpty()) {
if (references.isEmpty()) {
return
}

Expand Down Expand Up @@ -129,7 +129,7 @@ class SqlDelightCopyPasteProcessor : CopyPastePostProcessor<ReferenceTransferabl
if (oldImports.isEmpty()) {
document.insertString(0, "$newImports\n\n")
} else {
val endOffset = importStmtList.map { it.textOffset + it.textLength }.max() ?: 0
val endOffset = importStmtList.maxOfOrNull { it.textOffset + it.textLength } ?: 0
document.replaceString(0, endOffset, newImports)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SqlDelightHighlightVisitor : SqlVisitor(), HighlightVisitor {
private var myHolder: HighlightInfoHolder? = null

override fun suitableForFile(file: PsiFile): Boolean {
val file = file as? SqlDelightFile ?: return false
if (file !is SqlDelightFile) return false
val module = file.module ?: return false
return SqlDelightProjectService.getInstance(file.project).fileIndex(module).isConfigured
}
Expand Down

0 comments on commit 494d5a6

Please sign in to comment.