Don't require documentation in test sources
#KT-21837 Fixed
This commit is contained in:
+11
-19
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.inspections.kdoc
|
||||
@@ -24,6 +13,7 @@ import com.intellij.openapi.editor.EditorModificationUtil
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
import com.siyeh.ig.psiutils.TestUtils
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility
|
||||
import org.jetbrains.kotlin.descriptors.MemberDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
||||
@@ -42,18 +32,21 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyPublicApi
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
|
||||
class KDocMissingDocumentationInspection() : AbstractKotlinInspection() {
|
||||
class KDocMissingDocumentationInspection : AbstractKotlinInspection() {
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor =
|
||||
KDocMissingDocumentationInspection(holder)
|
||||
KDocMissingDocumentationInspection(holder)
|
||||
|
||||
private class KDocMissingDocumentationInspection(private val holder: ProblemsHolder) : PsiElementVisitor() {
|
||||
override fun visitElement(element: PsiElement) {
|
||||
if (TestUtils.isInTestSourceContent(element)) {
|
||||
return
|
||||
}
|
||||
|
||||
if (element is KtNamedDeclaration) {
|
||||
val nameIdentifier = element.nameIdentifier
|
||||
val descriptor = element.resolveToDescriptorIfAny(BodyResolveMode.FULL)
|
||||
as? DeclarationDescriptorWithVisibility
|
||||
as? MemberDescriptor ?: return
|
||||
as? DeclarationDescriptorWithVisibility
|
||||
as? MemberDescriptor ?: return
|
||||
if (nameIdentifier != null && descriptor.isEffectivelyPublicApi) {
|
||||
if (descriptor.findKDoc { DescriptorToSourceUtilsIde.getAnyDeclaration(element.project, it) } == null) {
|
||||
val message = element.describe()?.let { "$it is missing documentation" } ?: "Missing documentation"
|
||||
@@ -72,8 +65,7 @@ class KDocMissingDocumentationInspection() : AbstractKotlinInspection() {
|
||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.psiElement)) return
|
||||
val declaration = descriptor.psiElement.getParentOfType<KtNamedDeclaration>(true)
|
||||
?: throw IllegalStateException("Can't find declaration")
|
||||
|
||||
?: throw IllegalStateException("Can't find declaration")
|
||||
|
||||
declaration.addBefore(KDocElementFactory(project).createKDocFromText("/**\n*\n*/\n"), declaration.firstChild)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user