Implement Missing Documentation Inspection

#KT-1494 Fixed
This commit is contained in:
Manas Chaudhari
2016-01-30 12:26:20 +05:30
committed by Dmitry Jemerov
parent 3626e90788
commit 88fcad02a9
5 changed files with 134 additions and 0 deletions
@@ -0,0 +1,51 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.kdoc
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiElementVisitor
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.MemberDescriptor
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import org.jetbrains.kotlin.idea.inspections.AbstractKotlinInspection
import org.jetbrains.kotlin.psi.KtNamedDeclaration
import org.jetbrains.kotlin.resolve.source.getPsi
class KDocMissingDocumentationInspection(): AbstractKotlinInspection() {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor =
KDocMissingDocumentationInspection(holder)
private class KDocMissingDocumentationInspection(private val holder: ProblemsHolder): PsiElementVisitor() {
override fun visitElement(element: PsiElement) {
if (element is KtNamedDeclaration) {
val nameIdentifier = element.nameIdentifier
val descriptor = element.resolveToDescriptor() as? MemberDescriptor;
if (nameIdentifier != null && descriptor?.visibility == Visibilities.PUBLIC) {
val hasDocumentation = element.docComment != null ||
(descriptor as? CallableMemberDescriptor)?.overriddenDescriptors
?.any { (it.source.getPsi() as? KtNamedDeclaration)?.docComment != null } ?: false
if (!hasDocumentation) {
holder.registerProblem(nameIdentifier, "Missing documentation")
}
}
}
}
}
}
+7
View File
@@ -1332,6 +1332,13 @@
level="WARNING"
/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.kdoc.KDocMissingDocumentationInspection"
displayName="Missing KDoc comments for public declarations"
groupName="Kotlin"
enabledByDefault="true"
level="WARNING"
/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.refactoring.move.changePackage.PackageDirectoryMismatchInspection"
displayName="Package name does not match containing directory"
groupName="Kotlin"
+69
View File
@@ -0,0 +1,69 @@
public fun <warning descr="Missing documentation">publicUndocumentedFun</warning>() {}
fun <warning descr="Missing documentation">defaultUndocumentedFun</warning>() {}
/** Some documentation */
public fun publicDocumentedFun() {}
/** Some documentation */
fun defaultDocumentedFun() {}
private fun privateUndocumentedFun() {}
internal fun internalUndocumentedFun() {}
public class <warning descr="Missing documentation">publicUndocumentedClass</warning>() {}
class <warning descr="Missing documentation">defaultUndocumentedClass</warning>() {}
/** Some documentation */
public class publicDocumentedClass() {}
/** Some documentation */
class defaultDocumentedClass() {}
private class privateUndocumentedClass() {}
internal class internalUndocumentedClass() {}
private open class Properties {
public open val <warning descr="Missing documentation">publicUndocumentedProperty</warning>: Int = 0
open val <warning descr="Missing documentation">defaultUndocumentedProperty</warning>: Int = 0
/** Some documentation */
public open val publicDocumentedProperty: Int = 0
/** Some documentation */
open val defaultDocumentedProperty: Int = 0
private val privateUndocumentedProperty: Int = 0
internal open val internalUndocumentedProperty: Int = 0
protected open val protectedUndocumentedProperty: Int = 0
protected class protectedUndocumentedClass {}
protected fun protectedUndocumentedFun() {}
/** Some documentation */
protected open val protectedDocumentedProperty: Int = 0
}
private open class ChildClass : Properties() {
override val <warning descr="Missing documentation">publicUndocumentedProperty</warning>: Int = 4
override val <warning descr="Missing documentation">defaultUndocumentedProperty</warning>: Int = 4
override val publicDocumentedProperty: Int = 4
override val defaultDocumentedProperty: Int = 4
/** Some documentation */
override public val internalUndocumentedProperty: Int = 4
override public val <warning descr="Missing documentation">protectedUndocumentedProperty</warning>: Int = 4
override public val protectedDocumentedProperty: Int = 4
}
private class GrandChildClass : ChildClass() {
override public val internalUndocumentedProperty: Int = 6
}
// NO_CHECK_INFOS
@@ -23,5 +23,6 @@ public abstract class AbstractKDocHighlightingTest extends AbstractHighlightingT
protected void setUp() {
super.setUp();
myFixture.enableInspections(KDocUnresolvedReferenceInspection.class);
myFixture.enableInspections(KDocMissingDocumentationInspection.class);
}
}
@@ -35,6 +35,12 @@ public class KDocHighlightingTestGenerated extends AbstractKDocHighlightingTest
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/kdoc/highlighting"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("MissingDocumentation.kt")
public void testMissingDocumentation() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/kdoc/highlighting/MissingDocumentation.kt");
doTest(fileName);
}
@TestMetadata("UnresolvedReference.kt")
public void testUnresolvedReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/kdoc/highlighting/UnresolvedReference.kt");