Skip to content

Instantly share code, notes, and snippets.

@rubenquadros
Last active May 3, 2022 09:09
Show Gist options
  • Save rubenquadros/f2a75cb0cf5438f6e42170f2d48d1ab9 to your computer and use it in GitHub Desktop.
Save rubenquadros/f2a75cb0cf5438f6e42170f2d48d1ab9 to your computer and use it in GitHub Desktop.
Add missing annotation
fun addAnnotation(ktClass: KtClass, project: Project) {
val param = ktClass.getMissingAnnotationParam()
param?.let {
WriteCommandAction.runWriteCommandAction(project) {
param.addAnnotation(
annotationFqName =
FqName("com.google.gson.annotations.SerializedName"),
annotationInnerText = "\"${param.name}\""
)
JavaCodeStyleManager.getInstance(project)
.shortenClassReferences(param)
CodeStyleManager.getInstance(project).reformat(ktClass)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment