Skip to content

Commit 5ed5e08

Browse files
committed
Warn about missing reason tag on Overwrites
Fixes #1852
1 parent f73c6b7 commit 5ed5e08

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

src/main/kotlin/platform/mixin/MixinCustomJavaDocTagProvider.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,16 @@ class MixinCustomJavaDocTagProvider : CustomJavadocTagProvider {
4141
override fun getName() = "author"
4242

4343
override fun checkTagValue(value: PsiDocTagValue?): String? {
44-
return "The @author JavaDoc tag must be filled in.".takeIf { value?.text?.trim().isNullOrEmpty() }
44+
return "The @author JavaDoc tag must be filled in.".takeIf { value?.text.isNullOrBlank() }
4545
}
4646
}
4747

4848
object Reason : InjectorTag() {
4949
override fun getName() = "reason"
50+
51+
override fun checkTagValue(value: PsiDocTagValue?): String? {
52+
return "The @reason JavaDoc tag must be filled in.".takeIf { value?.text.isNullOrBlank() }
53+
}
5054
}
5155
}
5256
}

src/main/kotlin/platform/mixin/inspection/overwrite/OverwriteAuthorInspection.kt

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,42 @@ class OverwriteAuthorInspection : OverwriteInspection() {
2828
override fun visitOverwrite(holder: ProblemsHolder, method: PsiMethod, overwrite: PsiAnnotation) {
2929
val javadoc = method.docComment
3030
if (javadoc == null) {
31-
registerMissingTag(holder, method)
31+
registerMissingTags(holder, method)
3232
return
3333
}
3434

35-
val tag = javadoc.findTagByName("author")
36-
if (tag == null) {
37-
registerMissingTag(holder, javadoc)
35+
val authorTag = javadoc.findTagByName("author")
36+
if (authorTag == null) {
37+
registerMissingTag(holder, javadoc, "author")
3838
}
39+
40+
val reasonTag = javadoc.findTagByName("reason")
41+
if (reasonTag == null) {
42+
registerMissingTag(holder, javadoc, "reason")
43+
}
44+
}
45+
46+
private fun registerMissingTag(holder: ProblemsHolder, element: PsiElement, tag: String) {
47+
holder.registerProblem(
48+
element,
49+
"@Overwrite methods must have an associated JavaDoc with a filled in @$tag tag",
50+
QuickFix(tag)
51+
)
3952
}
4053

41-
private fun registerMissingTag(holder: ProblemsHolder, element: PsiElement) {
54+
private fun registerMissingTags(holder: ProblemsHolder, element: PsiElement) {
4255
holder.registerProblem(
4356
element,
44-
"@Overwrite methods must have an associated JavaDoc with a filled in @author tag",
45-
QuickFix
57+
"@Overwrite methods must have an associated JavaDoc with filled in @author and @reason tags",
58+
QuickFix()
4659
)
4760
}
4861

49-
private object QuickFix : LocalQuickFix {
62+
private class QuickFix(val tag: String? = null) : LocalQuickFix {
63+
64+
override fun getFamilyName() = "Add missing Javadoc tag"
5065

51-
override fun getFamilyName() = "Add @author Javadoc tag"
66+
override fun getName(): String = if (tag == null) "Add all missing Javadoc tags" else "Add @$tag Javadoc tag"
5267

5368
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
5469
val element = descriptor.psiElement
@@ -58,14 +73,15 @@ class OverwriteAuthorInspection : OverwriteInspection() {
5873
if (javadoc == null) {
5974
// Create new Javadoc comment
6075
method.addBefore(
61-
JavaPsiFacade.getElementFactory(project).createDocCommentFromText("/**\n * @author \n */"),
76+
JavaPsiFacade.getElementFactory(project)
77+
.createDocCommentFromText("/**\n * @author \n * @reason \n */"),
6278
method.modifierList
6379
)
6480
return
6581
}
6682

6783
// Create new Javadoc tag
68-
val tag = JavaPsiFacade.getElementFactory(project).createDocTagFromText("@author")
84+
val tag = JavaPsiFacade.getElementFactory(project).createDocTagFromText("@$tag")
6985
javadoc.addAfter(tag, null)
7086
}
7187
}

0 commit comments

Comments
 (0)