Last active
May 3, 2022 09:09
-
-
Save rubenquadros/f2a75cb0cf5438f6e42170f2d48d1ab9 to your computer and use it in GitHub Desktop.
Add 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
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