Move: RedundantUnitReturnTypeInspection to inspections package

This commit is contained in:
Mikhail Glukhikh
2017-07-19 20:20:14 +03:00
parent 8f78446bff
commit e154e4cf75
4 changed files with 50 additions and 21 deletions
+1 -1
View File
@@ -1981,7 +1981,7 @@
language="kotlin"
/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.RedundantUnitReturnTypeInspection"
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.RedundantUnitReturnTypeInspection"
displayName="Redundant 'Unit' return type"
groupPath="Kotlin"
groupName="Redundant constructs"
@@ -0,0 +1,48 @@
/*
* 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 com.intellij.codeInspection.IntentionWrapper
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.PsiElementVisitor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.intentions.RemoveExplicitTypeIntention
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
import org.jetbrains.kotlin.psi.KtCodeFragment
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.KtVisitorVoid
import org.jetbrains.kotlin.types.typeUtil.isUnit
class RedundantUnitReturnTypeInspection : AbstractKotlinInspection() {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
return object : KtVisitorVoid() {
override fun visitNamedFunction(function: KtNamedFunction) {
super.visitNamedFunction(function)
if (function.containingFile is KtCodeFragment) return
if ((function.descriptor as? FunctionDescriptor)?.returnType?.isUnit() == true) {
function.typeReference?.typeElement?.let {
holder.registerProblem(it,
"Redundant 'Unit' return type",
ProblemHighlightType.LIKE_UNUSED_SYMBOL,
IntentionWrapper(RemoveExplicitTypeIntention(), function.containingKtFile))
}
}
}
}
}
}
@@ -43,25 +43,6 @@ class RemoveSetterParameterTypeInspection : AbstractKotlinInspection() {
}
}
class RedundantUnitReturnTypeInspection : AbstractKotlinInspection() {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
return object : KtVisitorVoid() {
override fun visitNamedFunction(function: KtNamedFunction) {
super.visitNamedFunction(function)
if (function.containingFile is KtCodeFragment) return
if ((function.descriptor as? FunctionDescriptor)?.returnType?.isUnit() ?: false) {
function.typeReference?.typeElement?.let {
holder.registerProblem(it,
"Redundant 'Unit' return type",
ProblemHighlightType.LIKE_UNUSED_SYMBOL,
IntentionWrapper(RemoveExplicitTypeIntention(), function.containingKtFile))
}
}
}
}
}
}
class RemoveExplicitTypeIntention : SelfTargetingRangeIntention<KtCallableDeclaration>(
KtCallableDeclaration::class.java,
"Remove explicit type specification"
@@ -1 +1 @@
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.intentions.RedundantUnitReturnTypeInspection
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.RedundantUnitReturnTypeInspection