Last active
May 3, 2022 09:08
-
-
Save rubenquadros/5efc77f3179fd36a260bde34a4a49108 to your computer and use it in GitHub Desktop.
Editor notification for missing annotation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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