Minor. Green code.
This commit is contained in:
+5
-12
@@ -19,9 +19,7 @@ package org.jetbrains.kotlin.idea.inspections
|
|||||||
import com.intellij.codeInspection.*
|
import com.intellij.codeInspection.*
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiElementVisitor
|
import com.intellij.psi.PsiElementVisitor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
|
||||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
|
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
|
||||||
@@ -30,23 +28,18 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
|||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.isOverridable
|
import org.jetbrains.kotlin.psi.psiUtil.isOverridable
|
||||||
import org.jetbrains.kotlin.psi.typeRefHelpers.setReceiverTypeReference
|
import org.jetbrains.kotlin.psi.typeRefHelpers.setReceiverTypeReference
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
|
|
||||||
import kotlin.properties.Delegates
|
|
||||||
|
|
||||||
public class UnusedReceiverParameterInspection : AbstractKotlinInspection() {
|
public class UnusedReceiverParameterInspection : AbstractKotlinInspection() {
|
||||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||||
return object : KtVisitorVoid() {
|
return object : KtVisitorVoid() {
|
||||||
private fun check(callableDeclaration: KtCallableDeclaration) {
|
private fun check(callableDeclaration: KtCallableDeclaration) {
|
||||||
val receiverTypeReference = callableDeclaration.getReceiverTypeReference()
|
val receiverTypeReference = callableDeclaration.receiverTypeReference
|
||||||
if (receiverTypeReference == null || receiverTypeReference.textRange.isEmpty) return
|
if (receiverTypeReference == null || receiverTypeReference.textRange.isEmpty) return
|
||||||
if (callableDeclaration.isOverridable() || callableDeclaration.hasModifier(KtTokens.OVERRIDE_KEYWORD)) return
|
if (callableDeclaration.isOverridable() || callableDeclaration.hasModifier(KtTokens.OVERRIDE_KEYWORD)) return
|
||||||
|
|
||||||
if (callableDeclaration is KtProperty && callableDeclaration.getAccessors().isEmpty()) return
|
if (callableDeclaration is KtProperty && callableDeclaration.accessors.isEmpty()) return
|
||||||
if (callableDeclaration is KtNamedFunction && !callableDeclaration.hasBody()) return
|
if (callableDeclaration is KtNamedFunction && !callableDeclaration.hasBody()) return
|
||||||
|
|
||||||
val callable = callableDeclaration.descriptor
|
val callable = callableDeclaration.descriptor
|
||||||
@@ -60,11 +53,11 @@ public class UnusedReceiverParameterInspection : AbstractKotlinInspection() {
|
|||||||
val bindingContext = element.analyze()
|
val bindingContext = element.analyze()
|
||||||
val resolvedCall = element.getResolvedCall(bindingContext) ?: return
|
val resolvedCall = element.getResolvedCall(bindingContext) ?: return
|
||||||
|
|
||||||
if (resolvedCall.getDispatchReceiver().getThisReceiverOwner(bindingContext) == callable ||
|
if (resolvedCall.dispatchReceiver.getThisReceiverOwner(bindingContext) == callable ||
|
||||||
(resolvedCall.extensionReceiver as ReceiverValue?).getThisReceiverOwner(bindingContext) == callable) {
|
(resolvedCall.extensionReceiver as ReceiverValue?).getThisReceiverOwner(bindingContext) == callable) {
|
||||||
used = true
|
used = true
|
||||||
}
|
}
|
||||||
else if ((resolvedCall.getCandidateDescriptor() as? ReceiverParameterDescriptor)?.getContainingDeclaration() == callable) {
|
else if ((resolvedCall.candidateDescriptor as? ReceiverParameterDescriptor)?.containingDeclaration == callable) {
|
||||||
used = true
|
used = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,6 +92,6 @@ public class UnusedReceiverParameterInspection : AbstractKotlinInspection() {
|
|||||||
declaration.setReceiverTypeReference(null)
|
declaration.setReceiverTypeReference(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getFamilyName(): String = getName()
|
override fun getFamilyName(): String = name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user