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 {
|
||||
library as? LibraryEx ?: return JvmPlatform
|
||||
if (library !is LibraryEx) return JvmPlatform
|
||||
if (library.isDisposed) return JvmPlatform
|
||||
|
||||
return library.effectiveKind(project).platform
|
||||
|
||||
@@ -351,7 +351,7 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
private fun hasPlatformImplementations(declaration: KtNamedDeclaration, descriptor: DeclarationDescriptor?): Boolean {
|
||||
if (!declaration.hasExpectModifier()) return false
|
||||
|
||||
descriptor as? MemberDescriptor ?: return false
|
||||
if (descriptor !is MemberDescriptor) return false
|
||||
val commonModuleDescriptor = declaration.containingKtFile.findModuleDescriptor()
|
||||
|
||||
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) =
|
||||
declarationVisitor(fun(declaration) {
|
||||
declaration as? KtDeclarationWithBody ?: return
|
||||
if (declaration !is KtDeclarationWithBody) return
|
||||
val (toHighlightElement, suffix, highlightType) = statusFor(declaration) ?: return
|
||||
// Change range to start with left brace
|
||||
val hasHighlighting = highlightType != INFORMATION
|
||||
|
||||
+2
-2
@@ -44,7 +44,7 @@ class ObsoleteExperimentalCoroutinesInspection : AbstractKotlinInspection(), Cle
|
||||
|
||||
when (simpleNameExpression.text) {
|
||||
RESUME_MARKER, RESUME_WITH_EXCEPTION_MARKER -> {
|
||||
simpleNameExpression.parent as? KtCallExpression ?: return
|
||||
if (simpleNameExpression.parent !is KtCallExpression) return
|
||||
|
||||
val descriptor = simpleNameExpression.resolveMainReferenceToDescriptors().firstOrNull() ?: return
|
||||
val callableDescriptor = descriptor as? CallableDescriptor ?: return
|
||||
@@ -174,7 +174,7 @@ class ObsoleteExperimentalCoroutinesInspection : AbstractKotlinInspection(), Cle
|
||||
|
||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||
val element = descriptor.psiElement
|
||||
element as? KtSimpleNameExpression ?: return
|
||||
if (element !is KtSimpleNameExpression) return
|
||||
|
||||
val importFun =
|
||||
KotlinTopLevelFunctionFqnNameIndex.getInstance()
|
||||
|
||||
@@ -60,7 +60,7 @@ class MoveMemberToTopLevelIntention : MoveMemberOutOfObjectIntention("Move to to
|
||||
|
||||
override fun applicabilityRange(element: KtNamedDeclaration): TextRange? {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ class RemoveEmptyParenthesesFromLambdaCallIntention : SelfTargetingRangeIntentio
|
||||
val parent = element.parent as? KtCallExpression ?: return null
|
||||
val singleLambdaArgument = parent.lambdaArguments.singleOrNull() ?: 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
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ class ReplaceWithSafeCallFix(
|
||||
return ReplaceWithSafeCallFix(qualifiedExpression, qualifiedExpression.shouldHaveNotNullType())
|
||||
}
|
||||
else {
|
||||
psiElement as? KtNameReferenceExpression ?: return null
|
||||
if (psiElement !is KtNameReferenceExpression) return null
|
||||
if (psiElement.getResolvedCall(psiElement.analyze())?.getImplicitReceiverValue() != null) {
|
||||
val expressionToReplace: KtExpression = psiElement.parent as? KtCallExpression ?: psiElement
|
||||
return ReplaceImplicitReceiverCallFix(expressionToReplace, expressionToReplace.shouldHaveNotNullType())
|
||||
|
||||
Reference in New Issue
Block a user