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

Show desktop preview tool for common preview (#4839) #4979

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class PreviewEntryPoint : EntryPoint() {
override fun isEntryPoint(refElement: RefElement, psiElement: PsiElement): Boolean = isEntryPoint(psiElement)

override fun isEntryPoint(psiElement: PsiElement): Boolean =
psiElement is PsiMethod && psiElement.hasAnnotation(DESKTOP_PREVIEW_ANNOTATION_FQN)
psiElement is PsiMethod && (psiElement.hasAnnotation(DESKTOP_PREVIEW_ANNOTATION_FQN) ||
psiElement.hasAnnotation(COMMON_PREVIEW_ANNOTATION_FQN))

override fun readExternal(element: Element) = element.deserializeInto(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode

internal const val DESKTOP_PREVIEW_ANNOTATION_FQN = "androidx.compose.desktop.ui.tooling.preview.Preview"
internal const val COMMON_PREVIEW_ANNOTATION_FQN = "org.jetbrains.compose.ui.tooling.preview.Preview"
internal const val COMPOSABLE_FQ_NAME = "androidx.compose.runtime.Composable"

/**
Expand Down Expand Up @@ -120,7 +121,9 @@ internal fun KtNamedFunction.isValidComposablePreviewFunction(): Boolean {
while (annotationIt.hasNext() && !(hasComposableAnnotation && hasPreviewAnnotation)) {
val annotation = annotationIt.next()
hasComposableAnnotation = hasComposableAnnotation || annotation.fqNameMatches(COMPOSABLE_FQ_NAME)
hasPreviewAnnotation = hasPreviewAnnotation || annotation.fqNameMatches(DESKTOP_PREVIEW_ANNOTATION_FQN)
hasPreviewAnnotation = hasPreviewAnnotation ||
annotation.fqNameMatches(DESKTOP_PREVIEW_ANNOTATION_FQN) ||
annotation.fqNameMatches(COMMON_PREVIEW_ANNOTATION_FQN)
}

return hasComposableAnnotation && hasPreviewAnnotation
Expand Down