Browse Source

[Do not merge] Use KotlinFullClassNameIndex instead of JavaPsiFacade to support Compose for Web

compose-tooling
Ilya Ryzhenkov 2 years ago
parent
commit
11bb275850
  1. 1
      idea-plugin/src/main/kotlin/com/android/tools/compose/intentions/ComposeCreatePreviewAction.kt
  2. 9
      idea-plugin/src/main/kotlin/com/android/tools/modules/Module.kt

1
idea-plugin/src/main/kotlin/com/android/tools/compose/intentions/ComposeCreatePreviewAction.kt

@ -19,6 +19,7 @@ import com.android.tools.compose.COMPOSABLE_FQ_NAMES
import com.android.tools.compose.ComposeBundle
import com.android.tools.compose.ComposeLibraryNamespace
import com.android.tools.compose.isComposableAnnotation
import com.android.tools.compose.fqNameMatches
import com.android.tools.idea.flags.StudioFlags
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.openapi.editor.Editor

9
idea-plugin/src/main/kotlin/com/android/tools/modules/Module.kt

@ -11,17 +11,18 @@ import com.intellij.openapi.roots.*
import com.intellij.psi.*
import com.intellij.psi.search.*
import com.intellij.psi.util.*
import org.jetbrains.kotlin.idea.stubindex.KotlinFullClassNameIndex
import org.jetbrains.kotlin.idea.util.*
fun PsiElement.inComposeModule() = module?.isComposeModule() ?: false
fun Module.isComposeModule(): Boolean {
return CachedValuesManager.getManager(project).getCachedValue(this) {
val javaPsiFacade = JavaPsiFacade.getInstance(this.project)
val value = COMPOSABLE_FQ_NAMES.any {
javaPsiFacade.findClass(it, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(this)) != null
val scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(this)
val hasComposable = COMPOSABLE_FQ_NAMES.any {
KotlinFullClassNameIndex.getInstance().get(it, project, scope).any()
}
val rootModificationTracker = ProjectRootModificationTracker.getInstance(project)
CachedValueProvider.Result.create(value, rootModificationTracker)
CachedValueProvider.Result.create(hasComposable, rootModificationTracker)
}
}

Loading…
Cancel
Save