How to highlight SQL syntax of Room Dao in Android Studio
Asked Answered
L

2

6

With new Room, How to highlight SQL Syntax in Dao Interfaces?

For example @Query(SELECT * FROM user) is it possible to highlight the words SELECT, FROM with a different color and text format than the word user?

Leopold answered 8/12, 2017 at 9:12 Comment(0)
L
14

I found the answer from this link

enter image description here

Leopold answered 8/12, 2017 at 10:13 Comment(2)
How do you activate that menu?Phenacaine
Alt+Enter on Linux or WindowsLeopold
S
0

I do not know why but if you are using kotlin-dsl (gradle ktx) and implement dependencies with buildSrc on build.gradle file like this (object reference):

enter image description here enter image description here

implementation(Dependencies.AndroidX.room)
implementation(Dependencies.AndroidX.roomKtx)
kapt(Dependencies.AndroidX.roomCompiler)
implementation(Dependencies.AndroidX.roomPaging)

That causes to not indexing (highlight or autocomplete) Android Room SQL Scripts, so when I tried to implement with directly using String like this:

enter image description here

val roomVersion = "2.4.2"
implementation("androidx.room:room-runtime:$roomVersion")
implementation("androidx.room:room-ktx:$roomVersion")
implementation("androidx.room:room-common:$roomVersion")
implementation("androidx.room:room-paging:$roomVersion")
kapt("androidx.room:room-compiler:$roomVersion")

that worked for me.

Also I tried:

  1. Changing the Java JDK version 11.0.11 to 11.0.15.1
  2. Invalidate Caches/Restart

Aditionally

build.gradle.kts (project)

buildscript {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
    dependencies {
        classpath(BuildProject.GradlePlugins.androidNavigation)
        classpath(BuildProject.GradlePlugins.hilt)
    }
}

plugins {
    id("com.android.application") version "7.2.1" apply false
    id("com.android.library") version "7.2.1" apply false
    id("org.jetbrains.kotlin.android") version "1.7.10" apply false
}

tasks.register("clean", Delete::class) {
    delete(rootProject.buildDir)
}

build.gradle.kts (module)

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("kotlin-parcelize")
    id("kotlin-android")
    id("kotlin-kapt")
    id("androidx.navigation.safeargs.kotlin")
    id("dagger.hilt.android.plugin")
}

android {
    compileSdk = BuildApplication.compileSdk

    defaultConfig {
        applicationId = BuildApplication.applicationId
        minSdk = BuildApplication.minSdk
        targetSdk = BuildApplication.targetSdk
        versionCode = BuildApplication.versionCode
        versionName = BuildApplication.versionName
        testInstrumentationRunner = BuildApplication.androidTestInstrumentation
        multiDexEnabled = true
        vectorDrawables.useSupportLibrary = true
        javaCompileOptions {
            annotationProcessorOptions {
                argument("room.schemaLocation", "$projectDir/schemas")
            }
        }
    }
    buildFeatures {
        dataBinding = true
        viewBinding = true
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
            multiDexEnabled = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
        getByName("debug") {
            isMinifyEnabled = false
            multiDexEnabled = true
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_11.toString()

    }
}

dependencies {
    ...
    val roomVersion = "2.4.2"
    implementation("androidx.room:room-runtime:$roomVersion")
    implementation("androidx.room:room-ktx:$roomVersion")
    implementation("androidx.room:room-common:$roomVersion")
    implementation("androidx.room:room-paging:$roomVersion")
    kapt("androidx.room:room-compiler:$roomVersion")
    ...
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.3")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
}

kapt {
    correctErrorTypes = true
}
Surveying answered 15/7, 2022 at 14:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.