KT-20883: Add more details to MissingDocumentationInspection message

#KT-20883 fixed
This commit is contained in:
Simon Ogorodnik
2017-10-23 00:22:48 +03:00
parent d28e9fd22d
commit f21e1c60e0
10 changed files with 68 additions and 16 deletions
+1 -1
View File
@@ -1869,7 +1869,7 @@
language="kotlin"
/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.kdoc.KDocMissingDocumentationInspection"
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.kdoc.KDocMissingDocumentationInspection"
displayName="Missing KDoc comments for public declarations"
groupPath="Kotlin"
groupName="Other problems"
@@ -138,17 +138,7 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
return object : KtVisitorVoid() {
override fun visitDeclaration(declaration: KtDeclaration) {
if (declaration !is KtNamedDeclaration) return
val name = declaration.name ?: return
val message = when (declaration) {
is KtClass -> "Class ''$name'' is never used"
is KtObjectDeclaration -> "Object ''$name'' is never used"
is KtNamedFunction -> "Function ''$name'' is never used"
is KtSecondaryConstructor -> "Constructor is never used"
is KtProperty, is KtParameter -> "Property ''$name'' is never used"
is KtTypeParameter -> "Type parameter ''$name'' is never used"
is KtTypeAlias -> "Type alias ''$name'' is never used"
else -> return
}
val message = declaration.describe()?.let { "$it is never used" } ?: return
if (!ProjectRootsUtil.isInProjectSource(declaration)) return
@@ -0,0 +1,33 @@
/*
* Copyright 2010-2017 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.inspections
import org.jetbrains.kotlin.psi.*
/**
* @returns string description of declaration, like Function ''name''
*/
fun KtNamedDeclaration.describe(): String? = when (this) {
is KtClass -> "Class ''$name''"
is KtObjectDeclaration -> "Object ''$name''"
is KtNamedFunction -> "Function ''$name''"
is KtSecondaryConstructor -> "Constructor"
is KtProperty, is KtParameter -> "Property ''$name''"
is KtTypeParameter -> "Type parameter ''$name''"
is KtTypeAlias -> "Type alias ''$name''"
else -> null
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.kdoc
package org.jetbrains.kotlin.idea.inspections.kdoc
import com.intellij.codeInsight.FileModificationService
import com.intellij.codeInspection.LocalQuickFix
@@ -30,7 +30,9 @@ import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.core.unblockDocument
import org.jetbrains.kotlin.idea.inspections.AbstractKotlinInspection
import org.jetbrains.kotlin.idea.inspections.describe
import org.jetbrains.kotlin.idea.inspections.findExistingEditor
import org.jetbrains.kotlin.idea.kdoc.KDocElementFactory
import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection
import org.jetbrains.kotlin.psi.KtNamedDeclaration
import org.jetbrains.kotlin.psi.KtPsiFactory
@@ -55,7 +57,8 @@ class KDocMissingDocumentationInspection() : AbstractKotlinInspection() {
(descriptor as? CallableMemberDescriptor)?.overriddenDescriptors
?.any { (it.source.getPsi() as? KtNamedDeclaration)?.docComment != null } ?: false
if (!hasDocumentation) {
holder.registerProblem(nameIdentifier, "Missing documentation", AddDocumentationFix())
val message = element.describe()?.let { "$it is missing documentation" } ?: "Missing documentation"
holder.registerProblem(nameIdentifier, message, AddDocumentationFix())
}
}
}
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.kdoc.KDocMissingDocumentationInspection
@@ -0,0 +1,3 @@
// PROBLEM: "Class ''A'' is missing documentation"
class <caret>A
@@ -0,0 +1,6 @@
// PROBLEM: "Class ''A'' is missing documentation"
/**
* <caret>
*/
class A
@@ -1 +1 @@
org.jetbrains.kotlin.idea.kdoc.KDocMissingDocumentationInspection
org.jetbrains.kotlin.idea.inspections.kdoc.KDocMissingDocumentationInspection
@@ -582,6 +582,21 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
}
}
@TestMetadata("idea/testData/inspectionsLocal/kdocMissingDocumentation")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class KdocMissingDocumentation extends AbstractLocalInspectionTest {
public void testAllFilesPresentInKdocMissingDocumentation() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/kdocMissingDocumentation"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/kdocMissingDocumentation/simple.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/inspectionsLocal/leakingThis")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.idea.kdoc;
import org.jetbrains.kotlin.idea.highlighter.AbstractHighlightingTest;
import org.jetbrains.kotlin.idea.inspections.kdoc.KDocMissingDocumentationInspection;
public abstract class AbstractKDocHighlightingTest extends AbstractHighlightingTest {
@Override