Repository: cqfn/diKTat (kotlin)
Issue: Incorrect detection of Kdoc
If the method has any annotations - we won't be able to see the Kdoc. Easy fix

```
@ExperimentalFileSystem
/**
 * Simple file reading with okio (returning a list with strings)
 *
 * @param toml string with a path to a file
 * @return list with strings
 * @throws e FileNotFoundException if the toml file is missing
 */
internal fun readAndParseFile(toml: String): List<String> {
    try {
        val ktomlPath = toml.toPath()
        return FileSystem.SYSTEM.read(ktomlPath) {
            // FixMe: may be we need to read and at the same time parse (to make it parallel)
            generateSequence { readUtf8Line() }.toList()
        }
    } catch (e: FileNotFoundException) {
        println("Not able to find toml-file in the following path: $toml")
        throw e
    }
}
```

```
D:\ktoml\ktoml-file\src\commonMain\kotlin\com\akuleshov7\ktoml\file\FileUtils.kt:12:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc
```
Pull request description: ## Kdoc: now diKTat sees Kdoc between function and annotation

This pull request closes #1034 
If there is an annotation before function, AST is a bit more complex, so we need to check if there is any Kdoc among children of modifier list

## Actions checklist
* [ ] Implemented Rule, added Warnings
* [ ] Added tests on checks

Patch:
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt
index f83a522c5c..ade7dd4f0d 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt
@@ -310,7 +310,10 @@ class KdocComments(configRules: List<RulesConfig>) : DiktatRule(
      */
     @Suppress("UnsafeCallOnNullableType")
     private fun checkDoc(node: ASTNode, warning: Warnings) {
-        val kdoc = node.getFirstChildWithType(KDOC)
+        // if there is an annotation before function, AST is a bit more complex, so we need to look for Kdoc among
+        // children of modifier list
+        val kdoc = node.getFirstChildWithType(KDOC) ?: node.getFirstChildWithType(MODIFIER_LIST)?.getFirstChildWithType(KDOC)
+
         val name = node.getIdentifierName()
         val isModifierAccessibleOutsideOrActual = node.getFirstChildWithType(MODIFIER_LIST).run {
             isAccessibleOutside() && this?.hasChildOfType(ElementType.ACTUAL_KEYWORD) != true


Test patch:
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocCommentsWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocCommentsWarnTest.kt
index 8ab669c7da..8114839701 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocCommentsWarnTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocCommentsWarnTest.kt
@@ -528,4 +528,51 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) {
             LintError(6, 1, ruleId, "${MISSING_KDOC_TOP_LEVEL.warnText()} B")
         )
     }
+
+    @Test
+    fun `should find Kdoc after annotation of function`() {
+        lintMethod(
+            """
+                |@SomeAnnotation
+                |/**
+                | * Just print a string
+                | *
+                | * @param f string to print
+                | * @return 1
+                | */
+                |internal fun prnt(f: String) {
+                |   println(f)
+                |   return 1
+                |}
+            """.trimMargin()
+        )
+    }
+
+    @Test
+    fun `should find Kdoc after annotation of class`() {
+        lintMethod(
+            """
+                |@SomeAnnotation
+                |/**
+                | * Test class
+                | */
+                |class example(f: String) {
+                |
+                |}
+            """.trimMargin()
+        )
+    }
+
+    @Test
+    fun `should find Kdoc inside a modifier list`() {
+        lintMethod(
+            """
+                |public
+                |/**
+                | * foo
+                | */
+                |actual fun foo() { }
+            """.trimMargin()
+        )
+    }
 }