Code cleanup: x as? Type ?: return -> if (x !is Type) return
This commit is contained in:
@@ -52,7 +52,7 @@ val PersistentLibraryKind<*>?.platform: TargetPlatform
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getLibraryPlatform(project: Project, library: Library): TargetPlatform {
|
fun getLibraryPlatform(project: Project, library: Library): TargetPlatform {
|
||||||
library as? LibraryEx ?: return JvmPlatform
|
if (library !is LibraryEx) return JvmPlatform
|
||||||
if (library.isDisposed) return JvmPlatform
|
if (library.isDisposed) return JvmPlatform
|
||||||
|
|
||||||
return library.effectiveKind(project).platform
|
return library.effectiveKind(project).platform
|
||||||
|
|||||||
@@ -351,7 +351,7 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
|
|||||||
private fun hasPlatformImplementations(declaration: KtNamedDeclaration, descriptor: DeclarationDescriptor?): Boolean {
|
private fun hasPlatformImplementations(declaration: KtNamedDeclaration, descriptor: DeclarationDescriptor?): Boolean {
|
||||||
if (!declaration.hasExpectModifier()) return false
|
if (!declaration.hasExpectModifier()) return false
|
||||||
|
|
||||||
descriptor as? MemberDescriptor ?: return false
|
if (descriptor !is MemberDescriptor) return false
|
||||||
val commonModuleDescriptor = declaration.containingKtFile.findModuleDescriptor()
|
val commonModuleDescriptor = declaration.containingKtFile.findModuleDescriptor()
|
||||||
|
|
||||||
return commonModuleDescriptor.implementingDescriptors.any { it.hasActualsFor(descriptor) } ||
|
return commonModuleDescriptor.implementingDescriptors.any { it.hasActualsFor(descriptor) } ||
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ class UseExpressionBodyInspection(private val convertEmptyToUnit: Boolean) : Abs
|
|||||||
|
|
||||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) =
|
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) =
|
||||||
declarationVisitor(fun(declaration) {
|
declarationVisitor(fun(declaration) {
|
||||||
declaration as? KtDeclarationWithBody ?: return
|
if (declaration !is KtDeclarationWithBody) return
|
||||||
val (toHighlightElement, suffix, highlightType) = statusFor(declaration) ?: return
|
val (toHighlightElement, suffix, highlightType) = statusFor(declaration) ?: return
|
||||||
// Change range to start with left brace
|
// Change range to start with left brace
|
||||||
val hasHighlighting = highlightType != INFORMATION
|
val hasHighlighting = highlightType != INFORMATION
|
||||||
|
|||||||
+2
-2
@@ -44,7 +44,7 @@ class ObsoleteExperimentalCoroutinesInspection : AbstractKotlinInspection(), Cle
|
|||||||
|
|
||||||
when (simpleNameExpression.text) {
|
when (simpleNameExpression.text) {
|
||||||
RESUME_MARKER, RESUME_WITH_EXCEPTION_MARKER -> {
|
RESUME_MARKER, RESUME_WITH_EXCEPTION_MARKER -> {
|
||||||
simpleNameExpression.parent as? KtCallExpression ?: return
|
if (simpleNameExpression.parent !is KtCallExpression) return
|
||||||
|
|
||||||
val descriptor = simpleNameExpression.resolveMainReferenceToDescriptors().firstOrNull() ?: return
|
val descriptor = simpleNameExpression.resolveMainReferenceToDescriptors().firstOrNull() ?: return
|
||||||
val callableDescriptor = descriptor as? CallableDescriptor ?: return
|
val callableDescriptor = descriptor as? CallableDescriptor ?: return
|
||||||
@@ -174,7 +174,7 @@ class ObsoleteExperimentalCoroutinesInspection : AbstractKotlinInspection(), Cle
|
|||||||
|
|
||||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
val element = descriptor.psiElement
|
val element = descriptor.psiElement
|
||||||
element as? KtSimpleNameExpression ?: return
|
if (element !is KtSimpleNameExpression) return
|
||||||
|
|
||||||
val importFun =
|
val importFun =
|
||||||
KotlinTopLevelFunctionFqnNameIndex.getInstance()
|
KotlinTopLevelFunctionFqnNameIndex.getInstance()
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ class MoveMemberToTopLevelIntention : MoveMemberOutOfObjectIntention("Move to to
|
|||||||
|
|
||||||
override fun applicabilityRange(element: KtNamedDeclaration): TextRange? {
|
override fun applicabilityRange(element: KtNamedDeclaration): TextRange? {
|
||||||
if (element !is KtNamedFunction && element !is KtProperty) return null
|
if (element !is KtNamedFunction && element !is KtProperty) return null
|
||||||
element.containingClassOrObject as? KtObjectDeclaration ?: return null
|
if (element.containingClassOrObject !is KtObjectDeclaration) return null
|
||||||
return element.nameIdentifier?.textRange
|
return element.nameIdentifier?.textRange
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -44,7 +44,7 @@ class RemoveEmptyParenthesesFromLambdaCallIntention : SelfTargetingRangeIntentio
|
|||||||
val parent = element.parent as? KtCallExpression ?: return null
|
val parent = element.parent as? KtCallExpression ?: return null
|
||||||
val singleLambdaArgument = parent.lambdaArguments.singleOrNull() ?: return null
|
val singleLambdaArgument = parent.lambdaArguments.singleOrNull() ?: return null
|
||||||
if (element.getLineNumber(start = false) != singleLambdaArgument.getLineNumber(start = true)) return null
|
if (element.getLineNumber(start = false) != singleLambdaArgument.getLineNumber(start = true)) return null
|
||||||
element.getPrevSiblingIgnoringWhitespaceAndComments() as? KtCallExpression ?: return element.range
|
if (element.getPrevSiblingIgnoringWhitespaceAndComments() !is KtCallExpression) return element.range
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class ReplaceWithSafeCallFix(
|
|||||||
return ReplaceWithSafeCallFix(qualifiedExpression, qualifiedExpression.shouldHaveNotNullType())
|
return ReplaceWithSafeCallFix(qualifiedExpression, qualifiedExpression.shouldHaveNotNullType())
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
psiElement as? KtNameReferenceExpression ?: return null
|
if (psiElement !is KtNameReferenceExpression) return null
|
||||||
if (psiElement.getResolvedCall(psiElement.analyze())?.getImplicitReceiverValue() != null) {
|
if (psiElement.getResolvedCall(psiElement.analyze())?.getImplicitReceiverValue() != null) {
|
||||||
val expressionToReplace: KtExpression = psiElement.parent as? KtCallExpression ?: psiElement
|
val expressionToReplace: KtExpression = psiElement.parent as? KtCallExpression ?: psiElement
|
||||||
return ReplaceImplicitReceiverCallFix(expressionToReplace, expressionToReplace.shouldHaveNotNullType())
|
return ReplaceImplicitReceiverCallFix(expressionToReplace, expressionToReplace.shouldHaveNotNullType())
|
||||||
|
|||||||
Reference in New Issue
Block a user