Skip to content

Instantly share code, notes, and snippets.

@rubenquadros
Last active May 3, 2022 09:08
Show Gist options
  • Save rubenquadros/5efc77f3179fd36a260bde34a4a49108 to your computer and use it in GitHub Desktop.
Save rubenquadros/5efc77f3179fd36a260bde34a4a49108 to your computer and use it in GitHub Desktop.
Editor notification for missing annotation
class SerializedNameNotification :
EditorNotifications.Provider<EditorNotificationPanel>() {
companion object {
val KEY =
Key.create<EditorNotificationPanel>("Add missing annotation?")
}
override fun getKey(): Key<EditorNotificationPanel> = KEY
override fun createNotificationPanel(
file: VirtualFile,
fileEditor: FileEditor,
project: Project
): EditorNotificationPanel? {
val psiFile = file.toPsiFile(project)
val ktFile = psiFile as? KtFile
val psiClasses = ktFile?.classes
psiClasses?.let { psiClassList ->
psiClassList.forEach { psiClass ->
(psiClass as? KtLightClassForSourceDeclaration)?.let {
ktLightClassForSourceDeclaration ->
val ktClass =
ktLightClassForSourceDeclaration.kotlinOrigin
as? KtClass
if (ktClass?.isData() == true) {
val param = ktClass.getMissingAnnotationParam()
param?.let {
removeNotification(fileEditor)
return createPanel(
psiFile = psiFile,
project = project,
name = ktClass.name.orEmpty(),
onAddClick = {
addAnnotation(ktClass, project)
},
onIgnoreClick = {
ignoreInspection(
fileEditor,
psiFile,
project
)
}
)
} ?: removeNotification(fileEditor)
}
}
}
}
return null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment