From dfe2c16bc7a1e6fa77864d8e662ff2734bd2cddd Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 7 Jul 2017 13:57:36 +0300 Subject: [PATCH] More cleanup: lift return / assignment out --- .../kotlin/codegen/inline/MethodInliner.kt | 12 +++--- .../jetbrains/kotlin/codegen/inline/SMAP.kt | 6 +-- .../optimization/fixStack/FixStackAnalyzer.kt | 12 +++--- .../kotlin/cli/common/moduleVisibilityImpl.kt | 6 +-- .../kotlin/cli/jvm/repl/ReplCodeAnalyzer.kt | 6 +-- .../kotlin/cli/jvm/repl/ReplFromTerminal.kt | 6 +-- .../JavaPropertyInitializerEvaluatorImpl.kt | 10 ++--- .../kotlin/cfg/PseudocodeVariablesData.kt | 10 ++--- .../psi/EditCommaSeparatedListHelper.kt | 20 ++++----- .../kotlin/psi/KtObjectDeclaration.kt | 6 +-- .../org/jetbrains/kotlin/psi/KtPsiFactory.kt | 6 +-- .../org/jetbrains/kotlin/psi/KtTypeAlias.kt | 6 +-- .../jetbrains/kotlin/psi/TypeRefHelpers.kt | 6 +-- .../jetbrains/kotlin/psi/psiUtil/psiUtils.kt | 5 +-- .../resolve/FunctionDescriptorResolver.kt | 6 +-- .../jetbrains/kotlin/resolve/ImportPath.kt | 6 +-- .../kotlin/resolve/ModifiersChecker.kt | 6 +-- .../kotlin/resolve/OverrideResolver.kt | 6 +-- .../smartcasts/DelegatingDataFlowInfo.kt | 7 +--- .../diagnostics/KotlinSuppressCache.kt | 6 +-- .../expressions/FunctionsTypingVisitor.kt | 6 +-- .../PatternMatchingTypingVisitor.kt | 6 +-- .../unqualifiedSuper/unqualifiedSuper.kt | 6 +-- .../kotlin/util/MappedExtensionProvider.kt | 6 +-- .../backend/jvm/codegen/ExpressionCodegen.kt | 12 +++--- .../backend/jvm/lower/EnumClassLowering.kt | 6 +-- .../kotlin/javac/KotlinClassifiersCache.kt | 8 ++-- .../KtLightClassForSourceDeclaration.kt | 7 ++-- .../asJava/elements/KtLightFieldImpl.kt | 10 ++--- .../resolve/calls/tower/InvokeProcessors.kt | 12 +++--- .../DescriptorEquivalenceForOverrides.kt | 6 +-- .../org/jetbrains/kotlin/types/KotlinType.kt | 6 +-- .../types/checker/NewKotlinTypeChecker.kt | 7 +--- .../jetbrains/kotlin/types/checker/utils.kt | 16 ++++---- .../reflect/jvm/internal/RuntimeTypeMapper.kt | 26 +++++------- .../src/org/jetbrains/eval4j/jdi/jdiEval.kt | 6 +-- .../org/jetbrains/kotlin/idea/util/Utils.kt | 8 ++-- .../kotlin/idea/util/extensionsUtils.kt | 12 +++--- .../resolve/IDELightClassGenerationSupport.kt | 6 +-- .../caches/resolve/KotlinCacheServiceImpl.kt | 19 ++++----- .../caches/resolve/ResolutionFacadeImpl.kt | 8 ++-- .../idea/caches/resolve/getModuleInfo.kt | 6 +-- .../resolve/lightClasses/platformWrappers.kt | 6 +-- .../idea/caches/resolve/moduleDependents.kt | 6 +-- .../idea/caches/resolve/packageOracles.kt | 14 +++---- .../navigation/SourceNavigationHelper.kt | 10 ++--- .../navigation/findDecompiledDeclaration.kt | 6 +-- .../idea/highlighter/KotlinPsiChecker.kt | 6 +-- .../TypeKindHighlightingVisitor.kt | 17 +++----- .../kotlin/idea/references/KtReference.kt | 6 +-- .../idea/references/KtSimpleNameReference.kt | 6 +-- .../kotlin/idea/search/searchUtil.kt | 6 +-- .../ExpressionsOfTypeProcessor.kt | 24 +++++------ ...structuringDeclarationReferenceSearcher.kt | 6 +-- .../operators/OperatorReferenceSearcher.kt | 6 +-- .../android/KotlinOutputParserHelper.kt | 12 +++--- .../kotlin/android/ParcelableUtil.kt | 6 +-- .../completion/DeclarationLookupObjectImpl.kt | 6 +-- .../completion/KDocCompletionContributor.kt | 8 ++-- .../idea/completion/KeywordCompletion.kt | 6 +-- .../completion/KotlinCompletionContributor.kt | 12 +++--- .../idea/completion/OverridesCompletion.kt | 6 +-- .../kotlin/idea/completion/Weighers.kt | 2 +- .../handlers/KotlinClassifierInsertHandler.kt | 6 +-- .../smart/TypeInstantiationItems.kt | 6 +-- .../kotlin/idea/completion/smart/Utils.kt | 6 +-- .../kotlin/idea/core/ExpectedInfos.kt | 6 +-- .../kotlin/idea/core/ShortenReferences.kt | 12 +++--- .../idea/core/TypesWithOperatorDetector.kt | 6 +-- .../kotlin/idea/core/descriptorUtils.kt | 14 ++++--- .../OverrideMemberChooserObject.kt | 6 +-- .../util/DescriptorMemberChooserObject.kt | 6 +-- .../maven/actions/MavenPluginSourcesSwap.kt | 6 +-- .../SearchNotPropertyCandidatesAction.kt | 5 +-- .../KotlinBreadcrumbsInfoProvider.kt | 12 +++--- .../debugger/DebuggerClassNameProvider.kt | 7 ++-- .../debugger/InlineCallableUsagesSearcher.kt | 6 +-- .../breakpoints/KotlinFieldBreakpointType.kt | 6 +-- .../KotlinStepOverInlinedLinesHint.kt | 6 +-- .../editor/KotlinLiteralCopyPasteProcessor.kt | 8 ++-- .../idea/filters/KotlinExceptionFilter.kt | 6 +-- .../KotlinSuspendCallLineMarkerProvider.kt | 6 +-- .../KotlinLanguageInjectionSupport.kt | 9 ++-- .../ImplementAbstractMemberIntention.kt | 2 +- ...undantCallsOfConversionMethodsIntention.kt | 9 ++-- .../jetbrains/kotlin/idea/intentions/Utils.kt | 8 ++-- .../intentions/IfThenToSafeAccessIntention.kt | 6 +-- .../intentions/loopToCallChain/interfaces.kt | 18 ++++---- .../result/FindTransformationMatcher.kt | 17 ++++---- .../result/SumTransformation.kt | 6 +-- .../sequence/FilterTransformation.kt | 8 ++-- .../idea/intentions/loopToCallChain/utils.kt | 8 ++-- .../kotlin/idea/kdoc/KDocRenderer.kt | 6 +-- .../projectView/KtClassOrObjectTreeNode.kt | 6 +-- .../quickfix/ReplaceInfixOrOperatorCallFix.kt | 6 +-- .../callableBuilder/typeUtils.kt | 12 +++--- .../ui/KotlinChangeSignatureDialog.kt | 7 ++-- .../usages/KotlinCallableDefinitionUsage.kt | 6 +-- .../usages/KotlinFunctionCallUsage.kt | 7 ++-- .../ui/ExtractFunctionParameterTablePanel.kt | 8 ++-- .../idea/refactoring/kotlinRefactoringUtil.kt | 8 ++-- .../idea/util/ImportInsertHelperImpl.kt | 12 +++--- .../kotlin/j2k/ExpressionConverter.kt | 41 +++++++++---------- .../org/jetbrains/kotlin/j2k/ForConverter.kt | 6 +-- .../org/jetbrains/kotlin/j2k/SpecialMethod.kt | 6 +-- .../kotlin/j2k/StatementConverter.kt | 25 +++++------ .../org/jetbrains/kotlin/j2k/TypeVisitor.kt | 6 +-- j2k/src/org/jetbrains/kotlin/j2k/Utils.kt | 6 +-- .../jetbrains/kotlin/j2k/importConversion.kt | 8 ++-- .../MemberIntoObjectProcessing.kt | 6 +-- .../compilerRunner/JpsKotlinCompilerRunner.kt | 10 ++--- .../kotlin/js/naming/encodeSignature.kt | 6 +-- .../kotlin/js/inline/FunctionReader.kt | 8 ++-- .../js/DynamicTypeDeserializer.kt | 8 ++-- .../kotlin/java/model/types/JeDeclaredType.kt | 6 +-- .../KotlinUSimpleReferenceExpression.kt | 6 +-- 116 files changed, 472 insertions(+), 517 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt index 752e19d02d7..beea132d717 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt @@ -619,11 +619,11 @@ class MethodInliner( } private fun wrapException(originalException: Throwable, node: MethodNode, errorSuffix: String): RuntimeException { - if (originalException is InlineException) { - return InlineException("$errorPrefix: $errorSuffix", originalException) + return if (originalException is InlineException) { + InlineException("$errorPrefix: $errorSuffix", originalException) } else { - return InlineException("$errorPrefix: $errorSuffix\nCause: ${node.nodeText}", originalException) + InlineException("$errorPrefix: $errorSuffix\nCause: ${node.nodeText}", originalException) } } @@ -679,11 +679,11 @@ class MethodInliner( localReturns.add(LocalReturn(returnInsn, insertBeforeInsn, sourceValueFrame)) if (returnInsn.opcode != Opcodes.RETURN) { - if (returnInsn.opcode == Opcodes.LRETURN || returnInsn.opcode == Opcodes.DRETURN) { - returnVariableSize = 2 + returnVariableSize = if (returnInsn.opcode == Opcodes.LRETURN || returnInsn.opcode == Opcodes.DRETURN) { + 2 } else { - returnVariableSize = 1 + 1 } } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt index 23efe887a7c..a27338ac41d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt @@ -98,8 +98,8 @@ open class NestedSourceMapper( override fun mapLineNumber(lineNumber: Int): Int { val mappedLineNumber = visitedLines.get(lineNumber) - if (mappedLineNumber > 0) { - return mappedLineNumber + return if (mappedLineNumber > 0) { + mappedLineNumber } else { val rangeForMapping = @@ -111,7 +111,7 @@ open class NestedSourceMapper( visitedLines.put(lineNumber, newLineNumber) } lastVisitedRange = rangeForMapping - return newLineNumber + newLineNumber } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FixStackAnalyzer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FixStackAnalyzer.kt index 550e228958a..affee51a4a8 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FixStackAnalyzer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FixStackAnalyzer.kt @@ -142,20 +142,20 @@ internal class FixStackAnalyzer( } override fun pop(): BasicValue { - if (extraStack.isNotEmpty()) { - return extraStack.pop() + return if (extraStack.isNotEmpty()) { + extraStack.pop() } else { - return super.pop() + super.pop() } } override fun getStack(i: Int): BasicValue { - if (i < super.getMaxStackSize()) { - return super.getStack(i) + return if (i < super.getMaxStackSize()) { + super.getStack(i) } else { - return extraStack[i - maxStackSize] + extraStack[i - maxStackSize] } } } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/moduleVisibilityImpl.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/moduleVisibilityImpl.kt index afd2bb3724f..c45285c5e54 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/moduleVisibilityImpl.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/moduleVisibilityImpl.kt @@ -68,11 +68,11 @@ class ModuleVisibilityHelperImpl : ModuleVisibilityHelper { private fun findModule(descriptor: DeclarationDescriptor, modules: Collection): Module? { val sourceElement = getSourceElement(descriptor) - if (sourceElement is KotlinSourceElement) { - return modules.singleOrNull() ?: modules.firstOrNull { sourceElement.psi.containingKtFile.virtualFile.path in it.getSourceFiles() } + return if (sourceElement is KotlinSourceElement) { + modules.singleOrNull() ?: modules.firstOrNull { sourceElement.psi.containingKtFile.virtualFile.path in it.getSourceFiles() } } else { - return modules.firstOrNull { module -> + modules.firstOrNull { module -> isContainedByCompiledPartOfOurModule(descriptor, File(module.getOutputDirectory())) || module.getFriendPaths().any { isContainedByCompiledPartOfOurModule(descriptor, File(it)) } } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplCodeAnalyzer.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplCodeAnalyzer.kt index 71aecc6fc35..f548f9678ef 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplCodeAnalyzer.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplCodeAnalyzer.kt @@ -113,14 +113,14 @@ class ReplCodeAnalyzer(environment: KotlinCoreEnvironment) { val diagnostics = trace.bindingContext.diagnostics val hasErrors = diagnostics.any { it.severity == Severity.ERROR } - if (hasErrors) { + return if (hasErrors) { replState.lineFailure(linePsi, codeLine) - return ReplLineAnalysisResult.WithErrors(diagnostics) + ReplLineAnalysisResult.WithErrors(diagnostics) } else { val scriptDescriptor = context.scripts[linePsi.script]!! replState.lineSuccess(linePsi, codeLine, scriptDescriptor) - return ReplLineAnalysisResult.Successful(scriptDescriptor, diagnostics) + ReplLineAnalysisResult.Successful(scriptDescriptor, diagnostics) } } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplFromTerminal.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplFromTerminal.kt index a9dce9ece73..af0296b29ce 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplFromTerminal.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplFromTerminal.kt @@ -96,11 +96,11 @@ class ReplFromTerminal( } val lineResult = eval(line) - if (lineResult is ReplEvalResult.Incomplete) { - return WhatNextAfterOneLine.INCOMPLETE + return if (lineResult is ReplEvalResult.Incomplete) { + WhatNextAfterOneLine.INCOMPLETE } else { - return WhatNextAfterOneLine.READ_LINE + WhatNextAfterOneLine.READ_LINE } } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/components/JavaPropertyInitializerEvaluatorImpl.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/components/JavaPropertyInitializerEvaluatorImpl.kt index eec889718e2..365eca4e83a 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/components/JavaPropertyInitializerEvaluatorImpl.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/components/JavaPropertyInitializerEvaluatorImpl.kt @@ -27,14 +27,14 @@ class JavaPropertyInitializerEvaluatorImpl : JavaPropertyInitializerEvaluator { val evaluated = field.initializerValue ?: return null val factory = ConstantValueFactory(descriptor.builtIns) - when (evaluated) { - //Note: evaluated expression may be of class that does not match field type in some cases - // tested for Int, left other checks just in case + return when (evaluated) { + //Note: evaluated expression may be of class that does not match field type in some cases + // tested for Int, left other checks just in case is Byte, is Short, is Int, is Long -> { - return factory.createIntegerConstantValue((evaluated as Number).toLong(), descriptor.type) + factory.createIntegerConstantValue((evaluated as Number).toLong(), descriptor.type) } else -> { - return factory.createConstantValue(evaluated) + factory.createConstantValue(evaluated) } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeVariablesData.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeVariablesData.kt index efb173ceed7..29e5cd8de6d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeVariablesData.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeVariablesData.kt @@ -151,15 +151,13 @@ class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingCon val variableUseStatusData: Map> get() = pseudocodeVariableDataCollector.collectData(TraversalOrder.BACKWARD, UseControlFlowInfo()) { instruction: Instruction, incomingEdgesData: Collection -> - val enterResult: UseControlFlowInfo - if (incomingEdgesData.size == 1) { - enterResult = incomingEdgesData.single() + val enterResult: UseControlFlowInfo = if (incomingEdgesData.size == 1) { + incomingEdgesData.single() } else { - enterResult = incomingEdgesData.fold(UseControlFlowInfo()) { result, edgeData -> - edgeData.iterator().fold(result) { - subResult, (variableDescriptor, variableUseState) -> + incomingEdgesData.fold(UseControlFlowInfo()) { result, edgeData -> + edgeData.iterator().fold(result) { subResult, (variableDescriptor, variableUseState) -> subResult.put(variableDescriptor, variableUseState.merge(subResult.getOrNull(variableDescriptor))) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt index 848b598a15f..24120f60bf0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt @@ -32,22 +32,22 @@ object EditCommaSeparatedListHelper { fun addItemAfter(list: KtElement, allItems: List, item: TItem, anchor: TItem?, prefix: KtToken = KtTokens.LPAR): TItem { assert(anchor == null || anchor.parent == list) if (allItems.isEmpty()) { - if (list.firstChild?.node?.elementType == prefix) { - return list.addAfter(item, list.firstChild) as TItem + return if (list.firstChild?.node?.elementType == prefix) { + list.addAfter(item, list.firstChild) as TItem } else { - return list.add(item) as TItem + list.add(item) as TItem } } else { var comma = KtPsiFactory(list).createComma() - if (anchor != null) { + return if (anchor != null) { comma = list.addAfter(comma, anchor) - return list.addAfter(item, comma) as TItem + list.addAfter(item, comma) as TItem } else { comma = list.addBefore(comma, allItems.first()) - return list.addBefore(item, comma) as TItem + list.addBefore(item, comma) as TItem } } } @@ -55,18 +55,18 @@ object EditCommaSeparatedListHelper { @JvmOverloads fun addItemBefore(list: KtElement, allItems: List, item: TItem, anchor: TItem?, prefix: KtToken = KtTokens.LPAR): TItem { val anchorAfter: TItem? - if (allItems.isEmpty()) { + anchorAfter = if (allItems.isEmpty()) { assert(anchor == null) - anchorAfter = null + null } else { if (anchor != null) { val index = allItems.indexOf(anchor) assert(index >= 0) - anchorAfter = if (index > 0) allItems[index - 1] else null + if (index > 0) allItems[index - 1] else null } else { - anchorAfter = allItems[allItems.size - 1] + allItems[allItems.size - 1] } } return addItemAfter(list, allItems, item, anchorAfter, prefix) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtObjectDeclaration.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtObjectDeclaration.kt index 807e047264c..351ced03640 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtObjectDeclaration.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtObjectDeclaration.kt @@ -43,15 +43,15 @@ class KtObjectDeclaration : KtClassOrObject { } override fun setName(@NonNls name: String): PsiElement { - if (nameIdentifier == null) { + return if (nameIdentifier == null) { val psiFactory = KtPsiFactory(project) val result = addAfter(psiFactory.createIdentifier(name), getObjectKeyword()!!) addAfter(psiFactory.createWhiteSpace(), getObjectKeyword()!!) - return result + result } else { - return super.setName(name) + super.setName(name) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt index fa6674e4315..9330e739c8c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt @@ -660,13 +660,13 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m assert(name != CONSTRUCTOR_NAME || target == Target.CONSTRUCTOR) sb.append(name) - when (target) { + state = when (target) { Target.FUNCTION, Target.CONSTRUCTOR -> { sb.append("(") - state = State.FIRST_PARAM + State.FIRST_PARAM } else -> - state = State.TYPE_CONSTRAINTS + State.TYPE_CONSTRAINTS } return this diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtTypeAlias.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtTypeAlias.kt index f99c5dfffe6..92eff7f1679 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtTypeAlias.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtTypeAlias.kt @@ -41,12 +41,12 @@ class KtTypeAlias : KtTypeParameterListOwnerStub, KtNamedDe @IfNotParsed fun getTypeReference(): KtTypeReference? { - if (stub != null) { + return if (stub != null) { val typeReferences = getStubOrPsiChildrenAsList>(KtStubElementTypes.TYPE_REFERENCE) - return typeReferences[0] + typeReferences[0] } else { - return findChildByType(KtNodeTypes.TYPE_REFERENCE) + findChildByType(KtNodeTypes.TYPE_REFERENCE) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/TypeRefHelpers.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/TypeRefHelpers.kt index 3397d95db40..4d1bf58960d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/TypeRefHelpers.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/TypeRefHelpers.kt @@ -34,8 +34,8 @@ fun getTypeReference(declaration: KtCallableDeclaration): KtTypeReference? { fun setTypeReference(declaration: KtCallableDeclaration, addAfter: PsiElement?, typeRef: KtTypeReference?): KtTypeReference? { val oldTypeRef = getTypeReference(declaration) if (typeRef != null) { - if (oldTypeRef != null) { - return oldTypeRef.replace(typeRef) as KtTypeReference + return if (oldTypeRef != null) { + oldTypeRef.replace(typeRef) as KtTypeReference } else { val anchor = addAfter @@ -43,7 +43,7 @@ fun setTypeReference(declaration: KtCallableDeclaration, addAfter: PsiElement?, ?: (declaration as? KtParameter)?.destructuringDeclaration val newTypeRef = declaration.addAfter(typeRef, anchor) as KtTypeReference declaration.addAfter(KtPsiFactory(declaration.project).createColon(), anchor) - return newTypeRef + newTypeRef } } else { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt index bdbcef19ea8..c81f0ae99a7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt @@ -49,10 +49,7 @@ fun PsiElement.siblings(forward: Boolean = true, withItself: Boolean = true): Se override fun hasNext(): Boolean = next != null override fun next(): PsiElement { val result = next ?: throw NoSuchElementException() - if (forward) - next = result.nextSibling - else - next = result.prevSibling + next = if (forward) result.nextSibling else result.prevSibling return result } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt index 0d5ab0977f8..8ea81eef0d9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt @@ -347,7 +347,7 @@ class FunctionDescriptorResolver( } } else { - if (isFunctionLiteral(functionDescriptor) || isFunctionExpression(functionDescriptor)) { + type = if (isFunctionLiteral(functionDescriptor) || isFunctionExpression(functionDescriptor)) { val containsUninferredParameter = TypeUtils.contains(expectedType) { TypeUtils.isDontCarePlaceholder(it) || ErrorUtils.isUninferredParameter(it) } @@ -355,11 +355,11 @@ class FunctionDescriptorResolver( trace.report(CANNOT_INFER_PARAMETER_TYPE.on(valueParameter)) } - type = expectedType ?: TypeUtils.CANT_INFER_FUNCTION_PARAM_TYPE + expectedType ?: TypeUtils.CANT_INFER_FUNCTION_PARAM_TYPE } else { trace.report(VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION.on(valueParameter)) - type = ErrorUtils.createErrorType("Type annotation was missing for parameter ${valueParameter.nameAsSafeName}") + ErrorUtils.createErrorType("Type annotation was missing for parameter ${valueParameter.nameAsSafeName}") } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ImportPath.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ImportPath.kt index 2961ba41ebe..78ba9f6613a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ImportPath.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ImportPath.kt @@ -44,11 +44,11 @@ data class ImportPath @JvmOverloads constructor(val fqName: FqName, val isAllUnd companion object { @JvmStatic fun fromString(pathStr: String): ImportPath { - if (pathStr.endsWith(".*")) { - return ImportPath(FqName(pathStr.substring(0, pathStr.length - 2)), isAllUnder = true) + return if (pathStr.endsWith(".*")) { + ImportPath(FqName(pathStr.substring(0, pathStr.length - 2)), isAllUnder = true) } else { - return ImportPath(FqName(pathStr), isAllUnder = false) + ImportPath(FqName(pathStr), isAllUnder = false) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt index 0a3dfe8a284..d1ffa554d4a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt @@ -199,11 +199,11 @@ object ModifierCheckerCore { private fun deprecationRegister(vararg list: KtModifierKeywordToken) = compatibilityRegister(Compatibility.DEPRECATED, *list) private fun compatibility(first: KtModifierKeywordToken, second: KtModifierKeywordToken): Compatibility { - if (first == second) { - return Compatibility.REPEATED + return if (first == second) { + Compatibility.REPEATED } else { - return mutualCompatibility[Pair(first, second)] ?: Compatibility.COMPATIBLE + mutualCompatibility[Pair(first, second)] ?: Compatibility.COMPATIBLE } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.kt index ac7d1b26f79..30ca4057d06 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.kt @@ -799,11 +799,11 @@ class OverrideResolver( val substitutedSuperReturnType = typeSubstitutor.substitute(superDescriptor.type, Variance.OUT_VARIANCE)!! - if (superDescriptor.isVar) { - return KotlinTypeChecker.DEFAULT.equalTypes(subDescriptor.type, substitutedSuperReturnType) + return if (superDescriptor.isVar) { + KotlinTypeChecker.DEFAULT.equalTypes(subDescriptor.type, substitutedSuperReturnType) } else { - return KotlinTypeChecker.DEFAULT.isSubtypeOf(subDescriptor.type, substitutedSuperReturnType) + KotlinTypeChecker.DEFAULT.isSubtypeOf(subDescriptor.type, substitutedSuperReturnType) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt index 562ab9ed95d..a6200d42c56 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt @@ -211,12 +211,7 @@ internal class DelegatingDataFlowInfo private constructor( while (current != null) { if (current is DelegatingDataFlowInfo) { types.addAll(current.typeInfo.get(value)) - if (value == current.valueWithGivenTypeInfo) { - current = null - } - else { - current = current.parent - } + current = if (value == current.valueWithGivenTypeInfo) null else current.parent } else { types.addAll(current.getCollectedTypes(value)) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/KotlinSuppressCache.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/KotlinSuppressCache.kt index 6629eb7ac66..b7e7348d48c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/KotlinSuppressCache.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/KotlinSuppressCache.kt @@ -262,11 +262,11 @@ class BindingContextSuppressCache(val context: BindingContext) : KotlinSuppressC override fun getSuppressionAnnotations(annotated: KtAnnotated): List { val descriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, annotated) - if (descriptor != null) { - return descriptor.annotations.toList() + return if (descriptor != null) { + descriptor.annotations.toList() } else { - return annotated.annotationEntries.mapNotNull { context.get(BindingContext.ANNOTATION, it) } + annotated.annotationEntries.mapNotNull { context.get(BindingContext.ANNOTATION, it) } } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt index 2ab831b5a46..196ba6cbfd9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt @@ -119,11 +119,11 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre components.identifierChecker.checkDeclaration(function, context.trace) components.declarationsCheckerBuilder.withTrace(context.trace).checkFunction(function, functionDescriptor) - if (isDeclaration) { - return createTypeInfo(components.dataFlowAnalyzer.checkStatementType(function, context), context) + return if (isDeclaration) { + createTypeInfo(components.dataFlowAnalyzer.checkStatementType(function, context), context) } else { - return components.dataFlowAnalyzer.createCheckedTypeInfo(functionDescriptor.createFunctionType(), context, function) + components.dataFlowAnalyzer.createCheckedTypeInfo(functionDescriptor.createFunctionType(), context, function) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt index 31573206cc1..c4bd22f6aba 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt @@ -344,11 +344,11 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping val typeReference = condition.typeReference if (typeReference != null) { val result = checkTypeForIs(context, condition, condition.isNegated, subjectType, typeReference, subjectDataFlowValue) - if (condition.isNegated) { - newDataFlowInfo = ConditionalDataFlowInfo(result.elseInfo, result.thenInfo) + newDataFlowInfo = if (condition.isNegated) { + ConditionalDataFlowInfo(result.elseInfo, result.thenInfo) } else { - newDataFlowInfo = result + result } val rhsType = context.trace[BindingContext.TYPE, typeReference] if (subjectExpression != null) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/unqualifiedSuper/unqualifiedSuper.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/unqualifiedSuper/unqualifiedSuper.kt index 592a4845196..eae56af8a15 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/unqualifiedSuper/unqualifiedSuper.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/unqualifiedSuper/unqualifiedSuper.kt @@ -49,11 +49,11 @@ fun resolveUnqualifiedSuperFromExpressionContext( val calleeExpression = selectorExpression.calleeExpression if (calleeExpression is KtSimpleNameExpression) { val calleeName = calleeExpression.getReferencedNameAsName() - if (isCallingMethodOfAny(selectorExpression, calleeName)) { - return resolveSupertypesForMethodOfAny(supertypes, calleeName, anyType) + return if (isCallingMethodOfAny(selectorExpression, calleeName)) { + resolveSupertypesForMethodOfAny(supertypes, calleeName, anyType) } else { - return resolveSupertypesByCalleeName(supertypes, calleeName) + resolveSupertypesByCalleeName(supertypes, calleeName) } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/util/MappedExtensionProvider.kt b/compiler/frontend/src/org/jetbrains/kotlin/util/MappedExtensionProvider.kt index ea2c3d9cf08..d4036c03cee 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/util/MappedExtensionProvider.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/util/MappedExtensionProvider.kt @@ -31,11 +31,11 @@ protected constructor( fun get(): R { val cached = cached.get() ?: return update() val (app, extensions) = cached - if (app == ApplicationManager.getApplication()) { - return extensions + return if (app == ApplicationManager.getApplication()) { + extensions } else { - return update() + update() } } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index 3b177164ab7..4723195522f 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -903,11 +903,11 @@ class ExpressionCodegen( } if (descriptor is CallableMemberDescriptor && JvmCodegenUtil.getDirectMember(descriptor) is SyntheticJavaPropertyDescriptor) { val propertyDescriptor = JvmCodegenUtil.getDirectMember(descriptor) as SyntheticJavaPropertyDescriptor - if (descriptor is PropertyGetterDescriptor) { - descriptor = propertyDescriptor.getMethod + descriptor = if (descriptor is PropertyGetterDescriptor) { + propertyDescriptor.getMethod } else { - descriptor = propertyDescriptor.setMethod!! + propertyDescriptor.setMethod!! } } return typeMapper.mapToCallableMethod(descriptor as FunctionDescriptor, isSuper) @@ -935,11 +935,11 @@ class ExpressionCodegen( if (!isInline) return IrCallGenerator.DefaultCallGenerator val original = unwrapInitialSignatureDescriptor(DescriptorUtils.unwrapFakeOverride(descriptor.original as FunctionDescriptor)) - if (isDefaultCompilation) { - return TODO() + return if (isDefaultCompilation) { + TODO() } else { - return IrInlineCodegen(this, state, original, typeParameterMappings!!, IrSourceCompilerForInline(state, element)) + IrInlineCodegen(this, state, original, typeParameterMappings!!, IrSourceCompilerForInline(state, element)) } } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt index d4f721d14a5..df917fb3395 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt @@ -412,11 +412,11 @@ class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringPass { override fun visitGetValue(expression: IrGetValue): IrExpression { val loweredParameter = loweredEnumConstructorParameters[expression.descriptor] - if (loweredParameter != null) { - return IrGetValueImpl(expression.startOffset, expression.endOffset, loweredParameter, expression.origin) + return if (loweredParameter != null) { + IrGetValueImpl(expression.startOffset, expression.endOffset, loweredParameter, expression.origin) } else { - return expression + expression } } diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/KotlinClassifiersCache.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/KotlinClassifiersCache.kt index 38a33cffec4..45042ea12a0 100644 --- a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/KotlinClassifiersCache.kt +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/KotlinClassifiersCache.kt @@ -205,12 +205,12 @@ private fun tryToResolveInner(name: String, private fun KtFile.tryToResolvePackageClass(name: String, javac: JavacWrapper, nameParts: List = emptyList()): JavaClass? { - if (nameParts.size > 1) { - return find(FqName("${packageFqName.asString()}.${nameParts.first()}"), javac, nameParts) + return if (nameParts.size > 1) { + find(FqName("${packageFqName.asString()}.${nameParts.first()}"), javac, nameParts) } else { - return javac.findClass(FqName("${packageFqName.asString()}.$name")) - ?: javac.getKotlinClassifier(FqName("${packageFqName.asString()}.$name")) + javac.findClass(FqName("${packageFqName.asString()}.$name")) + ?: javac.getKotlinClassifier(FqName("${packageFqName.asString()}.$name")) } } diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/KtLightClassForSourceDeclaration.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/KtLightClassForSourceDeclaration.kt index f6f87cf30b6..c1ae4817e51 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/KtLightClassForSourceDeclaration.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/KtLightClassForSourceDeclaration.kt @@ -277,13 +277,12 @@ abstract class KtLightClassForSourceDeclaration(protected val classOrObject: KtC override fun isInheritor(baseClass: PsiClass, checkDeep: Boolean): Boolean { LightClassInheritanceHelper.getService(project).isInheritor(this, baseClass, checkDeep).ifSure { return it } - val qualifiedName: String? - if (baseClass is KtLightClassForSourceDeclaration) { + val qualifiedName: String? = if (baseClass is KtLightClassForSourceDeclaration) { val baseDescriptor = baseClass.getDescriptor() - qualifiedName = if (baseDescriptor != null) DescriptorUtils.getFqName(baseDescriptor).asString() else null + if (baseDescriptor != null) DescriptorUtils.getFqName(baseDescriptor).asString() else null } else { - qualifiedName = baseClass.qualifiedName + baseClass.qualifiedName } val thisDescriptor = getDescriptor() diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightFieldImpl.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightFieldImpl.kt index 9e3df58f567..3d5cce42896 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightFieldImpl.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightFieldImpl.kt @@ -112,13 +112,9 @@ sealed class KtLightFieldImpl( KtLightFieldImpl(origin, computeDelegate, containingClass, dummyDelegate) companion object Factory { - fun create(origin: LightMemberOrigin?, delegate: PsiField, containingClass: KtLightClass): KtLightField { - when (delegate) { - is PsiEnumConstant -> { - return KtLightEnumConstant(origin, { delegate }, containingClass, null) - } - else -> return KtLightFieldForDeclaration(origin, { delegate }, containingClass, null) - } + fun create(origin: LightMemberOrigin?, delegate: PsiField, containingClass: KtLightClass): KtLightField = when (delegate) { + is PsiEnumConstant -> KtLightEnumConstant(origin, { delegate }, containingClass, null) + else -> KtLightFieldForDeclaration(origin, { delegate }, containingClass, null) } fun lazy( diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt index 33f612cc64f..2ac6288728b 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt @@ -167,22 +167,22 @@ fun createCallTowerProcessorForExplicitInvoke( ): ScopeTowerProcessor { val invokeExtensionDescriptor = scopeTower.getExtensionInvokeCandidateDescriptor(expressionForInvoke) if (explicitReceiver != null) { - if (invokeExtensionDescriptor == null) { + return if (invokeExtensionDescriptor == null) { // case 1.(foo())(), where foo() isn't extension function - return KnownResultProcessor(emptyList()) + KnownResultProcessor(emptyList()) } else { - return InvokeExtensionScopeTowerProcessor(functionContext, invokeExtensionDescriptor, explicitReceiver = explicitReceiver) + InvokeExtensionScopeTowerProcessor(functionContext, invokeExtensionDescriptor, explicitReceiver = explicitReceiver) } } else { val usualInvoke = ExplicitReceiverScopeTowerProcessor(scopeTower, functionContext, expressionForInvoke) { getFunctions(OperatorNameConventions.INVOKE, it) } // todo operator - if (invokeExtensionDescriptor == null) { - return usualInvoke + return if (invokeExtensionDescriptor == null) { + usualInvoke } else { - return CompositeScopeTowerProcessor( + CompositeScopeTowerProcessor( usualInvoke, InvokeExtensionScopeTowerProcessor(functionContext, invokeExtensionDescriptor, explicitReceiver = null) ) diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorEquivalenceForOverrides.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorEquivalenceForOverrides.kt index 6b3d479b483..9ef762fdf48 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorEquivalenceForOverrides.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorEquivalenceForOverrides.kt @@ -98,11 +98,11 @@ object DescriptorEquivalenceForOverrides { // This check is needed when we call areTypeParametersEquivalent() from areCallableMemberDescriptorsEquivalent: // if the type parameter owners are, e.g., functions, we'll go into infinite recursion here - if (aOwner is CallableMemberDescriptor || bOwner is CallableMemberDescriptor) { - return equivalentCallables(aOwner, bOwner) + return if (aOwner is CallableMemberDescriptor || bOwner is CallableMemberDescriptor) { + equivalentCallables(aOwner, bOwner) } else { - return areEquivalent(aOwner, bOwner) + areEquivalent(aOwner, bOwner) } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt index 3e3b1ebaddb..f50fc71c6b8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt @@ -85,11 +85,11 @@ abstract class WrappedType : KotlinType() { } override fun toString(): String { - if (isComputed()) { - return delegate.toString() + return if (isComputed()) { + delegate.toString() } else { - return "" + "" } } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewKotlinTypeChecker.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewKotlinTypeChecker.kt index 659358638e1..0e2ca146fb7 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewKotlinTypeChecker.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewKotlinTypeChecker.kt @@ -287,12 +287,7 @@ object NewKotlinTypeChecker : KotlinTypeChecker { if (supertypes.size < 2) return supertypes val allPureSupertypes = supertypes.filter { it.arguments.all { !it.type.isFlexible() } } - if (allPureSupertypes.isNotEmpty()) { - return allPureSupertypes - } - else { - return supertypes - } + return if (allPureSupertypes.isNotEmpty()) allPureSupertypes else supertypes } private fun effectiveVariance(declared: Variance, useSite: Variance): Variance? { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/utils.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/utils.kt index 3d9ec2883a7..3cf0c4a5a74 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/utils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/utils.kt @@ -47,16 +47,16 @@ fun findCorrespondingSupertype( while (currentPathNode != null) { val currentType = currentPathNode.type - if (currentType.arguments.any { it.projectionKind != Variance.INVARIANT }) { - substituted = TypeConstructorSubstitution.create(currentType) - .wrapWithCapturingSubstitution().buildSubstitutor() - .safeSubstitute(substituted, Variance.INVARIANT) - .approximate() + substituted = if (currentType.arguments.any { it.projectionKind != Variance.INVARIANT }) { + TypeConstructorSubstitution.create(currentType) + .wrapWithCapturingSubstitution().buildSubstitutor() + .safeSubstitute(substituted, Variance.INVARIANT) + .approximate() } else { - substituted = TypeConstructorSubstitution.create(currentType) - .buildSubstitutor() - .safeSubstitute(substituted, Variance.INVARIANT) + TypeConstructorSubstitution.create(currentType) + .buildSubstitutor() + .safeSubstitute(substituted, Variance.INVARIANT) } isAnyMarkedNullable = isAnyMarkedNullable || currentType.isMarkedNullable diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/RuntimeTypeMapper.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/RuntimeTypeMapper.kt index 2d215a42530..2fb06aae857 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/RuntimeTypeMapper.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/RuntimeTypeMapper.kt @@ -105,18 +105,14 @@ internal sealed class JvmPropertySignature { val nameResolver: NameResolver, val typeTable: TypeTable ) : JvmPropertySignature() { - private val string: String - - init { - if (signature.hasGetter()) { - string = nameResolver.getString(signature.getter.name) + nameResolver.getString(signature.getter.desc) - } - else { - val (name, desc) = - JvmProtoBufUtil.getJvmFieldSignature(proto, nameResolver, typeTable) ?: - throw KotlinReflectionInternalError("No field signature for property: $descriptor") - string = JvmAbi.getterName(name) + getManglingSuffix() + "()" + desc - } + private val string: String = if (signature.hasGetter()) { + nameResolver.getString(signature.getter.name) + nameResolver.getString(signature.getter.desc) + } + else { + val (name, desc) = + JvmProtoBufUtil.getJvmFieldSignature(proto, nameResolver, typeTable) ?: + throw KotlinReflectionInternalError("No field signature for property: $descriptor") + JvmAbi.getterName(name) + getManglingSuffix() + "()" + desc } private fun getManglingSuffix(): String { @@ -194,11 +190,11 @@ internal object RuntimeTypeMapper { } is JavaClassConstructorDescriptor -> { val element = (function.source as? JavaSourceElement)?.javaElement - when { + return when { element is ReflectJavaConstructor -> - return JvmFunctionSignature.JavaConstructor(element.member) + JvmFunctionSignature.JavaConstructor(element.member) element is ReflectJavaClass && element.isAnnotationType -> - return JvmFunctionSignature.FakeJavaAnnotationConstructor(element.element) + JvmFunctionSignature.FakeJavaAnnotationConstructor(element.element) else -> throw KotlinReflectionInternalError("Incorrect resolution sequence for Java constructor $function ($element)") } } diff --git a/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt b/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt index cfa5febed4c..cfe7e0c07a1 100644 --- a/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt +++ b/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt @@ -327,13 +327,13 @@ class JDIEval( } val obj = instance.jdiObj.checkNull() - if (invokespecial) { + return if (invokespecial) { val method = findMethod(methodDesc) - return doInvokeMethod(obj, method, invokePolicy or ObjectReference.INVOKE_NONVIRTUAL) + doInvokeMethod(obj, method, invokePolicy or ObjectReference.INVOKE_NONVIRTUAL) } else { val method = findMethod(methodDesc, obj.referenceType() ?: methodDesc.ownerType.asReferenceType()) - return doInvokeMethod(obj, method, invokePolicy) + doInvokeMethod(obj, method, invokePolicy) } } diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/Utils.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/Utils.kt index e430040c13b..bef88eac4ed 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/Utils.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/Utils.kt @@ -79,10 +79,10 @@ private fun chooseMoreSpecific(type1: KotlinType, type2: KotlinType): KotlinType else -> { // type1IsSubtype && type2IsSubtype val flexible1 = type1.unwrap() as? FlexibleType val flexible2 = type2.unwrap() as? FlexibleType - when { - flexible1 != null && flexible2 == null -> return type2 - flexible2 != null && flexible1 == null -> return type1 - else -> return null //TODO? + return when { + flexible1 != null && flexible2 == null -> type2 + flexible2 != null && flexible1 == null -> type1 + else -> null //TODO? } } } diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/extensionsUtils.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/extensionsUtils.kt index 97a7f4eed95..681ce03b937 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/extensionsUtils.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/extensionsUtils.kt @@ -42,11 +42,11 @@ fun TCallable.substituteExtensionIfCallable( containingDeclarationOrModule: DeclarationDescriptor ): Collection { val sequence = receivers.asSequence().flatMap { substituteExtensionIfCallable(it, callType, context, dataFlowInfo, containingDeclarationOrModule).asSequence() } - if (typeParameters.isEmpty()) { // optimization for non-generic callables - return sequence.firstOrNull()?.let { listOf(it) } ?: listOf() + return if (typeParameters.isEmpty()) { // optimization for non-generic callables + sequence.firstOrNull()?.let { listOf(it) } ?: listOf() } else { - return sequence.toList() + sequence.toList() } } @@ -91,11 +91,11 @@ fun TCallable.substituteExtensionIfCallable( } substitutor } - if (typeParameters.isEmpty()) { // optimization for non-generic callables - return if (substitutors.any()) listOf(this) else listOf() + return if (typeParameters.isEmpty()) { // optimization for non-generic callables + if (substitutors.any()) listOf(this) else listOf() } else { - return substitutors + substitutors .mapNotNull { @Suppress("UNCHECKED_CAST") (substitute(it) as TCallable?) } .toList() } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.kt index ce8ff65e0fc..037b731628e 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.kt @@ -186,13 +186,13 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG facadeFiles: List, moduleInfo: IdeaModuleInfo ): List { - if (moduleInfo is ModuleSourceInfo) { + return if (moduleInfo is ModuleSourceInfo) { val lightClassForFacade = KtLightClassForFacade.createForFacade( psiManager, facadeFqName, moduleInfo.contentScope(), facadeFiles) - return withFakeLightClasses(lightClassForFacade, facadeFiles) + withFakeLightClasses(lightClassForFacade, facadeFiles) } else { - return facadeFiles.filterIsInstance().mapNotNull { createLightClassForDecompiledKotlinFile(it) } + facadeFiles.filterIsInstance().mapNotNull { createLightClassForDecompiledKotlinFile(it) } } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt index cd399e43838..790fa90548a 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt @@ -197,16 +197,15 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService { val syntheticFileModule = files.map(KtFile::getModuleInfo).toSet().single() val sdk = syntheticFileModule.sdk val settings = PlatformAnalysisSettings(targetPlatform, sdk, syntheticFileModule.supportsAdditionalBuiltInsMembers()) - val filesModificationTracker: ModificationTracker // File copies are created during completion and receive correct modification events through POM. // Dummy files created e.g. by J2K do not receive events. - if (files.all { it.originalFile != it }) { - filesModificationTracker = ModificationTracker { + val filesModificationTracker = if (files.all { it.originalFile != it }) { + ModificationTracker { files.sumByLong { it.outOfBlockModificationCount } } } else { - filesModificationTracker = ModificationTracker { + ModificationTracker { files.sumByLong { it.outOfBlockModificationCount + it.modificationStamp } } } @@ -322,11 +321,11 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService { val annotatedDescriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, annotated) - if (annotatedDescriptor != null) { - return annotatedDescriptor.annotations.toList() + return if (annotatedDescriptor != null) { + annotatedDescriptor.annotations.toList() } else { - return annotated.annotationEntries.mapNotNull { context.get(BindingContext.ANNOTATION, it) } + annotated.annotationEntries.mapNotNull { context.get(BindingContext.ANNOTATION, it) } } } }, LibraryModificationTracker.getInstance(project), PsiModificationTracker.MODIFICATION_COUNT) @@ -357,13 +356,13 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService { val file = files.first() val moduleInfo = file.getModuleInfo() val notInSourceFiles = files.filterNotInProjectSource(moduleInfo) - if (notInSourceFiles.isNotEmpty()) { + return if (notInSourceFiles.isNotEmpty()) { val projectFacade = getFacadeForSyntheticFiles(notInSourceFiles) - return ResolutionFacadeImpl(projectFacade, moduleInfo) + ResolutionFacadeImpl(projectFacade, moduleInfo) } else { val platform = TargetPlatformDetector.getPlatform(file) - return getResolutionFacadeByModuleInfo(moduleInfo, platform) + getResolutionFacadeByModuleInfo(moduleInfo, platform) } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/ResolutionFacadeImpl.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/ResolutionFacadeImpl.kt index a48370be7e8..15ca51ca5f1 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/ResolutionFacadeImpl.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/ResolutionFacadeImpl.kt @@ -61,14 +61,14 @@ internal class ResolutionFacadeImpl( = projectFacade.getAnalysisResultsForElements(elements) override fun resolveToDescriptor(declaration: KtDeclaration, bodyResolveMode: BodyResolveMode): DeclarationDescriptor { - if (KtPsiUtil.isLocal(declaration)) { + return if (KtPsiUtil.isLocal(declaration)) { val bindingContext = analyze(declaration, bodyResolveMode) - return bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, declaration] - ?: getFrontendService(moduleInfo, AbsentDescriptorHandler::class.java).diagnoseDescriptorNotFound(declaration) + bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, declaration] + ?: getFrontendService(moduleInfo, AbsentDescriptorHandler::class.java).diagnoseDescriptorNotFound(declaration) } else { val resolveSession = projectFacade.resolverForModuleInfo(declaration.getModuleInfo()).componentProvider.get() - return resolveSession.resolveToDescriptor(declaration) + resolveSession.resolveToDescriptor(declaration) } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/getModuleInfo.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/getModuleInfo.kt index 5f2e58c20b2..7bf31539a78 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/getModuleInfo.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/getModuleInfo.kt @@ -118,11 +118,11 @@ private fun getModuleInfoByVirtualFile(project: Project, virtualFile: VirtualFil val isBinary = virtualFile.isKotlinBinary() val scriptConfigurationManager = KotlinScriptConfigurationManager.getInstance(project) if (isBinary && virtualFile in scriptConfigurationManager.getAllScriptsClasspathScope()) { - if (treatAsLibrarySource) { - return ScriptDependenciesSourceModuleInfo(project) + return if (treatAsLibrarySource) { + ScriptDependenciesSourceModuleInfo(project) } else { - return ScriptDependenciesModuleInfo(project, null) + ScriptDependenciesModuleInfo(project, null) } } if (!isBinary && virtualFile in scriptConfigurationManager.getAllLibrarySourcesScope()) { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/lightClasses/platformWrappers.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/lightClasses/platformWrappers.kt index 38bb8ab28be..ee825c0a00f 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/lightClasses/platformWrappers.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/lightClasses/platformWrappers.kt @@ -247,11 +247,11 @@ private class KtLightMethodWrapper( private fun substituteType(psiType: PsiType): PsiType { val substituted = containingClass.substitutor.substitute(psiType) - if (TypeUtils.isJavaLangObject(substituted) && substituteObjectWith != null) { - return substituteObjectWith + return if (TypeUtils.isJavaLangObject(substituted) && substituteObjectWith != null) { + substituteObjectWith } else { - return substituted + substituted } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/moduleDependents.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/moduleDependents.kt index 976ac3339de..765db6451d9 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/moduleDependents.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/moduleDependents.kt @@ -32,11 +32,11 @@ import java.util.HashSet //NOTE: this is an approximation that may contain more module infos then the exact solution fun ModuleSourceInfo.getDependentModules(): Set { val dependents = getDependents(module) - if (isTests()) { - return dependents.mapTo(HashSet(), Module::testSourceInfo) + return if (isTests()) { + dependents.mapTo(HashSet(), Module::testSourceInfo) } else { - return dependents.flatMapTo(HashSet()) { listOf(it.productionSourceInfo(), it.testSourceInfo()) } + dependents.flatMapTo(HashSet()) { listOf(it.productionSourceInfo(), it.testSourceInfo()) } } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/packageOracles.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/packageOracles.kt index 982086bf102..e2865b9facb 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/packageOracles.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/packageOracles.kt @@ -31,15 +31,15 @@ class IdePackageOracleFactory(val project: Project) : PackageOracleFactory { override fun createOracle(moduleInfo: ModuleInfo): PackageOracle { if (moduleInfo !is IdeaModuleInfo) return PackageOracle.Optimistic - when { - moduleInfo.platform == JvmPlatform -> when (moduleInfo.moduleOrigin) { - ModuleOrigin.LIBRARY -> return JavaPackagesOracle(moduleInfo, project) - ModuleOrigin.MODULE -> return JvmSourceOracle(moduleInfo as ModuleSourceInfo, project) - ModuleOrigin.OTHER -> return PackageOracle.Optimistic + return when (moduleInfo.platform) { + JvmPlatform -> when (moduleInfo.moduleOrigin) { + ModuleOrigin.LIBRARY -> JavaPackagesOracle(moduleInfo, project) + ModuleOrigin.MODULE -> JvmSourceOracle(moduleInfo as ModuleSourceInfo, project) + ModuleOrigin.OTHER -> PackageOracle.Optimistic } else -> when (moduleInfo.moduleOrigin) { - ModuleOrigin.MODULE -> return KotlinSourceFilesOracle(moduleInfo as ModuleSourceInfo) - else -> return PackageOracle.Optimistic // binaries for non-jvm platform need some oracles based on their structure + ModuleOrigin.MODULE -> KotlinSourceFilesOracle(moduleInfo as ModuleSourceInfo) + else -> PackageOracle.Optimistic // binaries for non-jvm platform need some oracles based on their structure } } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/SourceNavigationHelper.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/SourceNavigationHelper.kt index 2f58b4e0e02..08fdfd6d5ea 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/SourceNavigationHelper.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/SourceNavigationHelper.kt @@ -196,12 +196,10 @@ object SourceNavigationHelper { private fun getIndexForTopLevelPropertyOrFunction( decompiledDeclaration: KtNamedDeclaration - ): StringStubIndexExtension { - when (decompiledDeclaration) { - is KtNamedFunction -> return KotlinTopLevelFunctionFqnNameIndex.getInstance() - is KtProperty -> return KotlinTopLevelPropertyFqnNameIndex.getInstance() - else -> throw IllegalArgumentException("Neither function nor declaration: " + decompiledDeclaration::class.java.name) - } + ): StringStubIndexExtension = when (decompiledDeclaration) { + is KtNamedFunction -> KotlinTopLevelFunctionFqnNameIndex.getInstance() + is KtProperty -> KotlinTopLevelPropertyFqnNameIndex.getInstance() + else -> throw IllegalArgumentException("Neither function nor declaration: " + decompiledDeclaration::class.java.name) } private fun getInitialMemberCandidates( diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/findDecompiledDeclaration.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/findDecompiledDeclaration.kt index 9bf34b4a753..17469050eee 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/findDecompiledDeclaration.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/findDecompiledDeclaration.kt @@ -85,11 +85,11 @@ private fun findInScope(referencedDescriptor: DeclarationDescriptor, scope: Glob } private fun isLocal(descriptor: DeclarationDescriptor): Boolean { - if (descriptor is ParameterDescriptor) { - return isLocal(descriptor.containingDeclaration) + return if (descriptor is ParameterDescriptor) { + isLocal(descriptor.containingDeclaration) } else { - return DescriptorUtils.isLocal(descriptor) + DescriptorUtils.isLocal(descriptor) } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt index 25a7e29b600..fde6123c5e8 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt @@ -317,11 +317,11 @@ private class AnnotationPresentationInfo( var message = IdeErrorMessages.render(diagnostic) if (KotlinInternalMode.enabled || ApplicationManager.getApplication().isUnitTestMode) { val factoryName = diagnostic.factory.name - if (message.startsWith("")) { - message = "[$factoryName] ${message.substring("".length)}" + message = if (message.startsWith("")) { + "[$factoryName] ${message.substring("".length)}" } else { - message = "[$factoryName] $message" + "[$factoryName] $message" } } if (!message.startsWith("")) { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/TypeKindHighlightingVisitor.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/TypeKindHighlightingVisitor.kt index 0ce2dcae75e..defcc96fa72 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/TypeKindHighlightingVisitor.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/TypeKindHighlightingVisitor.kt @@ -95,16 +95,11 @@ internal class TypeKindHighlightingVisitor(holder: AnnotationHolder, bindingCont // Do nothing: 'dynamic' is highlighted as a keyword } - private fun textAttributesKeyForClass(descriptor: ClassDescriptor): TextAttributesKey { - when (descriptor.kind) { - ClassKind.INTERFACE -> return TRAIT - ClassKind.ANNOTATION_CLASS -> return ANNOTATION - ClassKind.OBJECT -> return OBJECT - ClassKind.ENUM_ENTRY -> return ENUM_ENTRY - else -> return if (descriptor.modality === Modality.ABSTRACT) - ABSTRACT_CLASS - else - CLASS - } + private fun textAttributesKeyForClass(descriptor: ClassDescriptor): TextAttributesKey = when (descriptor.kind) { + ClassKind.INTERFACE -> TRAIT + ClassKind.ANNOTATION_CLASS -> ANNOTATION + ClassKind.OBJECT -> OBJECT + ClassKind.ENUM_ENTRY -> ENUM_ENTRY + else -> if (descriptor.modality === Modality.ABSTRACT) ABSTRACT_CLASS else CLASS } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtReference.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtReference.kt index debc251dae3..e4278cc4053 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtReference.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtReference.kt @@ -96,13 +96,13 @@ abstract class AbstractKtReference(element: T) : PsiPolyVariantRe } private fun resolveToPsiElements(ref: AbstractKtReference, targetDescriptor: DeclarationDescriptor): Collection { - if (targetDescriptor is PackageViewDescriptor) { + return if (targetDescriptor is PackageViewDescriptor) { val psiFacade = JavaPsiFacade.getInstance(ref.expression.project) val fqName = targetDescriptor.fqName.asString() - return listOfNotNull(psiFacade.findPackage(fqName)) + listOfNotNull(psiFacade.findPackage(fqName)) } else { - return DescriptorToSourceUtilsIde.getAllDeclarations(ref.expression.project, targetDescriptor, ref.expression.resolveScope) + DescriptorToSourceUtilsIde.getAllDeclarations(ref.expression.project, targetDescriptor, ref.expression.resolveScope) } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtSimpleNameReference.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtSimpleNameReference.kt index 19f9e79f8d7..d59cb422fa4 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtSimpleNameReference.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtSimpleNameReference.kt @@ -233,12 +233,12 @@ class KtSimpleNameReference(expression: KtSimpleNameExpression) : KtSimpleRefere tokenType, element.parent is KtUnaryExpression, element.parent is KtBinaryExpression ) ?: return emptyList() val counterpart = OperatorConventions.ASSIGNMENT_OPERATION_COUNTERPARTS[tokenType] - if (counterpart != null) { + return if (counterpart != null) { val counterpartName = OperatorConventions.getNameForOperationSymbol(counterpart, false, true)!! - return listOf(name, counterpartName) + listOf(name, counterpartName) } else { - return listOf(name) + listOf(name) } } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/searchUtil.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/searchUtil.kt index d4dd8ae6480..ed7528d071d 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/searchUtil.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/searchUtil.kt @@ -70,14 +70,14 @@ fun SearchScope.restrictToKotlinSources(): SearchScope { fun SearchScope.excludeKotlinSources(): SearchScope = excludeFileTypes(KotlinFileType.INSTANCE) fun SearchScope.excludeFileTypes(vararg fileTypes: FileType): SearchScope { - if (this is GlobalSearchScope) { + return if (this is GlobalSearchScope) { val includedFileTypes = FileTypeRegistry.getInstance().registeredFileTypes.filter { it !in fileTypes }.toTypedArray() - return GlobalSearchScope.getScopeRestrictedByFileTypes(this, *includedFileTypes) + GlobalSearchScope.getScopeRestrictedByFileTypes(this, *includedFileTypes) } else { this as LocalSearchScope val filteredElements = scope.filter { it.containingFile.fileType !in fileTypes } - return if (filteredElements.isNotEmpty()) + if (filteredElements.isNotEmpty()) LocalSearchScope(filteredElements.toTypedArray()) else GlobalSearchScope.EMPTY_SCOPE diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/ExpressionsOfTypeProcessor.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/ExpressionsOfTypeProcessor.kt index 22bed4c566a..c9ddec29023 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/ExpressionsOfTypeProcessor.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/ExpressionsOfTypeProcessor.kt @@ -433,21 +433,19 @@ class ExpressionsOfTypeProcessor( /** * Process reference to declaration whose type is our class (or our class used anywhere inside that type) */ - private fun processReferenceToCallableOfOurType(reference: PsiReference): Boolean { - when (reference.element.language) { - KotlinLanguage.INSTANCE -> { - if (reference is KtDestructuringDeclarationReference) { - // declaration usage in form of destructuring declaration entry - addCallableDeclarationOfOurType(reference.element) - } - else { - (reference.element as? KtReferenceExpression)?.let { processSuspiciousExpression(it) } - } - return true + private fun processReferenceToCallableOfOurType(reference: PsiReference) = when (reference.element.language) { + KotlinLanguage.INSTANCE -> { + if (reference is KtDestructuringDeclarationReference) { + // declaration usage in form of destructuring declaration entry + addCallableDeclarationOfOurType(reference.element) } - - else -> return false // reference in unknown language - we don't know how to handle it + else { + (reference.element as? KtReferenceExpression)?.let { processSuspiciousExpression(it) } + } + true } + + else -> false // reference in unknown language - we don't know how to handle it } private fun addSamInterfaceToProcess(psiClass: PsiClass) { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/operators/DestructuringDeclarationReferenceSearcher.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/operators/DestructuringDeclarationReferenceSearcher.kt index 4daf378b83b..57100d3b713 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/operators/DestructuringDeclarationReferenceSearcher.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/operators/DestructuringDeclarationReferenceSearcher.kt @@ -39,11 +39,11 @@ class DestructuringDeclarationReferenceSearcher( ) : OperatorReferenceSearcher(targetDeclaration, searchScope, consumer, optimizer, options, wordsToSearch = listOf("(")) { override fun resolveTargetToDescriptor(): FunctionDescriptor? { - if (targetDeclaration is KtParameter) { - return targetDeclaration.dataClassComponentFunction() + return if (targetDeclaration is KtParameter) { + targetDeclaration.dataClassComponentFunction() } else { - return super.resolveTargetToDescriptor() + super.resolveTargetToDescriptor() } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/operators/OperatorReferenceSearcher.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/operators/OperatorReferenceSearcher.kt index ffd32d00e89..79ec7cd5abe 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/operators/OperatorReferenceSearcher.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/operators/OperatorReferenceSearcher.kt @@ -81,11 +81,11 @@ abstract class OperatorReferenceSearcher( protected fun processReferenceElement(element: TReferenceElement): Boolean { val reference = extractReference(element) ?: return true testLog { "Resolved ${logPresentation(element)}" } - if (reference.isReferenceTo(targetDeclaration)) { - return consumer.process(reference) + return if (reference.isReferenceTo(targetDeclaration)) { + consumer.process(reference) } else { - return true + true } } diff --git a/idea/idea-android/idea-android-output-parser/src/org/jetbrains/kotlin/android/KotlinOutputParserHelper.kt b/idea/idea-android/idea-android-output-parser/src/org/jetbrains/kotlin/android/KotlinOutputParserHelper.kt index 1e50b587fef..bd2550c1703 100644 --- a/idea/idea-android/idea-android-output-parser/src/org/jetbrains/kotlin/android/KotlinOutputParserHelper.kt +++ b/idea/idea-android/idea-android-output-parser/src/org/jetbrains/kotlin/android/KotlinOutputParserHelper.kt @@ -246,11 +246,11 @@ object KotlinOutputParserHelper { try { val severityConst: Any = severityObjectMap[severity] ?: return null - if (isNewAndroidPlugin) { - return createNewMessage(severityConst, text.trim(), file, lineNumber, columnIndex, offset) + return if (isNewAndroidPlugin) { + createNewMessage(severityConst, text.trim(), file, lineNumber, columnIndex, offset) } else { - return createOldMessage(severityConst, text.trim(), file, lineNumber, columnIndex) + createOldMessage(severityConst, text.trim(), file, lineNumber, columnIndex) } } catch(e: Throwable) { @@ -294,11 +294,11 @@ object KotlinOutputParserHelper { lineNumber: Int?, columnIndex: Int? ): Any? { - if (file == null || lineNumber == null || columnIndex == null) { - return simpleMessageConstructor.newInstance(severityConst, text) + return if (file == null || lineNumber == null || columnIndex == null) { + simpleMessageConstructor.newInstance(severityConst, text) } else { - return complexMessageConstructor.newInstance( + complexMessageConstructor.newInstance( severityConst, text, file, lineNumber, columnIndex) diff --git a/idea/idea-android/src/org/jetbrains/kotlin/android/ParcelableUtil.kt b/idea/idea-android/src/org/jetbrains/kotlin/android/ParcelableUtil.kt index b1426cfcadf..a8583676775 100644 --- a/idea/idea-android/src/org/jetbrains/kotlin/android/ParcelableUtil.kt +++ b/idea/idea-android/src/org/jetbrains/kotlin/android/ParcelableUtil.kt @@ -375,12 +375,12 @@ private fun KtClass.createSecondaryConstructor(factory: KtPsiFactory): KtConstru val constructor = factory.createSecondaryConstructor(constructorText) val lastProperty = declarations.findLast { it is KtProperty } - if (lastProperty != null) { - return addDeclarationAfter(constructor, lastProperty).apply { addNewLineBeforeDeclaration() } + return if (lastProperty != null) { + addDeclarationAfter(constructor, lastProperty).apply { addNewLineBeforeDeclaration() } } else { val firstFunction = declarations.find { it is KtFunction } - return addDeclarationBefore(constructor, firstFunction).apply { addNewLineBeforeDeclaration() } + addDeclarationBefore(constructor, firstFunction).apply { addNewLineBeforeDeclaration() } } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/DeclarationLookupObjectImpl.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/DeclarationLookupObjectImpl.kt index e7c3dc44c9b..28853857c34 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/DeclarationLookupObjectImpl.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/DeclarationLookupObjectImpl.kt @@ -58,10 +58,10 @@ abstract class DeclarationLookupObjectImpl( if (this === other) return true if (other == null || this::class.java != other::class.java) return false val lookupObject = other as DeclarationLookupObjectImpl - if (descriptor != null) - return descriptorsEqualWithSubstitution(descriptor, lookupObject.descriptor) + return if (descriptor != null) + descriptorsEqualWithSubstitution(descriptor, lookupObject.descriptor) else - return lookupObject.descriptor == null && psiElement == lookupObject.psiElement + lookupObject.descriptor == null && psiElement == lookupObject.psiElement } override val isDeprecated: Boolean diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KDocCompletionContributor.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KDocCompletionContributor.kt index 1f5fbcb5558..3ffb20ed26a 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KDocCompletionContributor.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KDocCompletionContributor.kt @@ -147,19 +147,19 @@ class KDocNameCompletionSession( fun collectDescriptorsForLinkCompletion(declarationDescriptor: DeclarationDescriptor, kDocLink: KDocLink): Sequence { val qualifiedLink = kDocLink.getLinkText().split('.').dropLast(1) val nameFilter = descriptorNameFilter.toNameFilter() - if (qualifiedLink.isNotEmpty()) { + return if (qualifiedLink.isNotEmpty()) { val parentDescriptors = resolveKDocLink(bindingContext, resolutionFacade, declarationDescriptor, kDocLink.getTagIfSubject(), qualifiedLink) val childDescriptorsOfPartialLink = parentDescriptors.asSequence().flatMap { val scope = getKDocLinkResolutionScope(resolutionFacade, it) collectDescriptorsFromScope(scope, nameFilter, false) } - return (collectPackageViewDescriptors(qualifiedLink, nameFilter) + childDescriptorsOfPartialLink) + (collectPackageViewDescriptors(qualifiedLink, nameFilter) + childDescriptorsOfPartialLink) } else { val scope = getKDocLinkResolutionScope(resolutionFacade, declarationDescriptor) - return (collectDescriptorsFromScope(scope, nameFilter, true) - + collectPackageViewDescriptors(qualifiedLink, nameFilter)) + (collectDescriptorsFromScope(scope, nameFilter, true) + + collectPackageViewDescriptors(qualifiedLink, nameFilter)) } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt index a102a39f92c..8ab1047458a 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt @@ -254,11 +254,11 @@ object KeywordCompletion { val scope = parent.parent when (scope) { is KtClassOrObject -> { - if (parent is KtPrimaryConstructor) { - return buildFilterWithReducedContext("class X ", parent, position) + return if (parent is KtPrimaryConstructor) { + buildFilterWithReducedContext("class X ", parent, position) } else { - return buildFilterWithReducedContext("class X { ", parent, position) + buildFilterWithReducedContext("class X { ", parent, position) } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt index fc935bd5ed2..d1aaf5994d4 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt @@ -386,22 +386,22 @@ class KotlinCompletionContributor : CompletionContributor() { val nameRef = nameToken.parent as? KtNameReferenceExpression ?: return null val bindingContext = nameRef.getResolutionFacade().analyze(nameRef, BodyResolveMode.PARTIAL) val targets = nameRef.getReferenceTargets(bindingContext) - if (targets.isNotEmpty() && targets.all { it is FunctionDescriptor || it is ClassDescriptor && it.kind == ClassKind.CLASS }) { - return CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED + ">".repeat(balance) + "$" + return if (targets.isNotEmpty() && targets.all { it is FunctionDescriptor || it is ClassDescriptor && it.kind == ClassKind.CLASS }) { + CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED + ">".repeat(balance) + "$" } else { - return null + null } } private fun unclosedTypeArgListNameAndBalance(tokenBefore: PsiElement): Pair? { val nameToken = findCallNameTokenIfInTypeArgs(tokenBefore) ?: return null val pair = unclosedTypeArgListNameAndBalance(nameToken) - if (pair == null) { - return Pair(nameToken, 1) + return if (pair == null) { + Pair(nameToken, 1) } else { - return Pair(pair.first, pair.second + 1) + Pair(pair.first, pair.second + 1) } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/OverridesCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/OverridesCompletion.kt index fab98f7de02..f87329b46b0 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/OverridesCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/OverridesCompletion.kt @@ -154,11 +154,11 @@ class OverridesCompletion( is KtValVarKeywordOwner -> { if (descriptorToOverride !is PropertyDescriptor) return false - if (declaration.valOrVarKeyword?.node?.elementType == KtTokens.VAL_KEYWORD) { - return !descriptorToOverride.isVar + return if (declaration.valOrVarKeyword?.node?.elementType == KtTokens.VAL_KEYWORD) { + !descriptorToOverride.isVar } else { - return true // var can override either var or val + true // var can override either var or val } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/Weighers.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/Weighers.kt index 4e90a8f314f..569f36088b8 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/Weighers.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/Weighers.kt @@ -214,7 +214,7 @@ object PreferGetSetMethodsToPropertyWeigher : LookupElementWeigher("kotlin.prefe val prefixMatcher = context.itemMatcher(element) if (prefixMatcher.prefixMatches(property.name.asString())) return 0 val matchedLookupStrings = element.allLookupStrings.filter { prefixMatcher.prefixMatches(it) } - if (matchedLookupStrings.all { it.startsWith("get") || it.startsWith("set") }) return 1 else return 0 + return if (matchedLookupStrings.all { it.startsWith("get") || it.startsWith("set") }) 1 else 0 } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassifierInsertHandler.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassifierInsertHandler.kt index 5de7819f274..4c0505b4e3e 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassifierInsertHandler.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassifierInsertHandler.kt @@ -94,12 +94,12 @@ object KotlinClassifierInsertHandler : BaseDeclarationInsertHandler() { private fun qualifiedNameToInsert(item: LookupElement): String { val lookupObject = item.`object` as DeclarationLookupObject - if (lookupObject.descriptor != null) { - return IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(lookupObject.descriptor as ClassifierDescriptor) + return if (lookupObject.descriptor != null) { + IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(lookupObject.descriptor as ClassifierDescriptor) } else { val qualifiedName = (lookupObject.psiElement as PsiClass).qualifiedName!! - return if (FqNameUnsafe.isValid(qualifiedName)) FqNameUnsafe(qualifiedName).render() else qualifiedName + if (FqNameUnsafe.isValid(qualifiedName)) FqNameUnsafe(qualifiedName).render() else qualifiedName } } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt index 6c4ad3d7318..2c542818048 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt @@ -176,11 +176,11 @@ class TypeInstantiationItems( val typeArgsToUse = typeArgs.map { TypeProjectionImpl(Variance.INVARIANT, it.type) } val allTypeArgsKnown = fuzzyType.freeParameters.isEmpty() || typeArgs.none { it.type.areTypeParametersUsedInside(fuzzyType.freeParameters) } - if (allTypeArgsKnown) { - itemText += IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderTypeArguments(typeArgsToUse) + itemText += if (allTypeArgsKnown) { + IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderTypeArguments(typeArgsToUse) } else { - itemText += "<...>" + "<...>" } val constructorParenthesis = if (classifier.kind != ClassKind.INTERFACE) "()" else "" diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt index 1a1c8e3f492..012ff2dc18d 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt @@ -315,11 +315,11 @@ fun DeclarationDescriptor.fuzzyTypesForSmartCompletion( return emptyList() } - if (this is VariableDescriptor) { //TODO: generic properties! - return smartCastCalculator.types(this).map { it.toFuzzyType(emptyList()) } + return if (this is VariableDescriptor) { //TODO: generic properties! + smartCastCalculator.types(this).map { it.toFuzzyType(emptyList()) } } else { - return listOf(returnType) + listOf(returnType) } } else if (this is ClassDescriptor && kind.isSingleton) { diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt index 47127b92591..a658fef7729 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ExpectedInfos.kt @@ -500,9 +500,9 @@ class ExpectedInfos( if (expressionWithType != block.statements.last()) return null val functionLiteral = block.parent as? KtFunctionLiteral - if (functionLiteral != null) { + return if (functionLiteral != null) { val literalExpression = functionLiteral.parent as KtLambdaExpression - return calculate(literalExpression) + calculate(literalExpression) .mapNotNull { it.fuzzyType } .filter { it.type.isFunctionType } .map { @@ -511,7 +511,7 @@ class ExpectedInfos( } } else { - return calculate(block).map { ExpectedInfo(it.filter, it.expectedName, null) } + calculate(block).map { ExpectedInfo(it.filter, it.expectedName, null) } } } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt index 68d122a2cea..a723d44efd8 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt @@ -287,12 +287,12 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT val tryImport = result.descriptors.isNotEmpty() && result.descriptors.none { it in failedToImportDescriptors } && result.descriptors.all { mayImport(it, file) } - if (tryImport) { + toBeShortened = if (tryImport) { descriptorsToImport.addAll(result.descriptors) - toBeShortened = true + true } else { - toBeShortened = false + false } } @@ -548,11 +548,11 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT private fun targetsMatch(targets1: Collection, targets2: Collection): Boolean { if (targets1.size != targets2.size) return false - if (targets1.size == 1) { - return targets1.single().asString() == targets2.single().asString() + return if (targets1.size == 1) { + targets1.single().asString() == targets2.single().asString() } else { - return targets1.map { it.asString() }.toSet() == targets2.map { it.asString() }.toSet() + targets1.map { it.asString() }.toSet() == targets2.map { it.asString() }.toSet() } } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/TypesWithOperatorDetector.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/TypesWithOperatorDetector.kt index 6b58dc32665..a9abdef6557 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/TypesWithOperatorDetector.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/TypesWithOperatorDetector.kt @@ -77,13 +77,13 @@ abstract class TypesWithOperatorDetector( } fun findOperator(type: FuzzyType): Pair? { - if (cache.containsKey(type)) { - return cache[type] + return if (cache.containsKey(type)) { + cache[type] } else { val result = findOperatorNoCache(type) cache[type] = result - return result + result } } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/descriptorUtils.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/descriptorUtils.kt index 8e23556adb4..2aa4f7b0d5b 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/descriptorUtils.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/descriptorUtils.kt @@ -118,15 +118,17 @@ fun compareDescriptors(project: Project, currentDescriptor: DeclarationDescripto fun Visibility.toKeywordToken(): KtModifierKeywordToken { val normalized = normalize() - when (normalized) { - Visibilities.PUBLIC -> return KtTokens.PUBLIC_KEYWORD - Visibilities.PROTECTED -> return KtTokens.PROTECTED_KEYWORD - Visibilities.INTERNAL -> return KtTokens.INTERNAL_KEYWORD + return when (normalized) { + Visibilities.PUBLIC -> KtTokens.PUBLIC_KEYWORD + Visibilities.PROTECTED -> KtTokens.PROTECTED_KEYWORD + Visibilities.INTERNAL -> KtTokens.INTERNAL_KEYWORD else -> { if (Visibilities.isPrivate(normalized)) { - return KtTokens.PRIVATE_KEYWORD + KtTokens.PRIVATE_KEYWORD + } + else { + error("Unexpected visibility '$normalized'") } - error("Unexpected visibility '$normalized'") } } } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/overrideImplement/OverrideMemberChooserObject.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/overrideImplement/OverrideMemberChooserObject.kt index 9168009b991..526672dab6a 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/overrideImplement/OverrideMemberChooserObject.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/overrideImplement/OverrideMemberChooserObject.kt @@ -60,11 +60,11 @@ interface OverrideMemberChooserObject : ClassMember { preferConstructorParameter: Boolean = false ): OverrideMemberChooserObject { val declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor) - if (declaration != null) { - return WithDeclaration(descriptor, declaration, immediateSuper, bodyType, preferConstructorParameter) + return if (declaration != null) { + WithDeclaration(descriptor, declaration, immediateSuper, bodyType, preferConstructorParameter) } else { - return WithoutDeclaration(descriptor, immediateSuper, bodyType, preferConstructorParameter) + WithoutDeclaration(descriptor, immediateSuper, bodyType, preferConstructorParameter) } } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/util/DescriptorMemberChooserObject.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/util/DescriptorMemberChooserObject.kt index 0926ed3101e..79447062cda 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/util/DescriptorMemberChooserObject.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/util/DescriptorMemberChooserObject.kt @@ -84,14 +84,14 @@ open class DescriptorMemberChooserObject( if (declaration != null && declaration.isValid) { val isClass = declaration is PsiClass || declaration is KtClass val flags = if (isClass) 0 else Iconable.ICON_FLAG_VISIBILITY - if (declaration is KtDeclaration) { + return if (declaration is KtDeclaration) { // kotlin declaration // visibility and abstraction better detect by a descriptor - return KotlinDescriptorIconProvider.getIcon(descriptor, declaration, flags) + KotlinDescriptorIconProvider.getIcon(descriptor, declaration, flags) } else { // it is better to show java icons for java code - return declaration.getIcon(flags) + declaration.getIcon(flags) } } else { diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/actions/MavenPluginSourcesSwap.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/actions/MavenPluginSourcesSwap.kt index f7e86ac40e5..ebabe1bb9d3 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/actions/MavenPluginSourcesSwap.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/actions/MavenPluginSourcesSwap.kt @@ -146,11 +146,11 @@ class MavenPluginSourcesMoveToBuild : PsiElementBaseIntentionAction() { } } - if (couldMove == 1) { + return if (couldMove == 1) { block(pom, sourceDirsToMove.single(), execution, build) - return true + true } else { - return false + false } } diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/internal/SearchNotPropertyCandidatesAction.kt b/idea/src/org/jetbrains/kotlin/idea/actions/internal/SearchNotPropertyCandidatesAction.kt index d345628707b..1a877d82490 100644 --- a/idea/src/org/jetbrains/kotlin/idea/actions/internal/SearchNotPropertyCandidatesAction.kt +++ b/idea/src/org/jetbrains/kotlin/idea/actions/internal/SearchNotPropertyCandidatesAction.kt @@ -107,10 +107,7 @@ class SearchNotPropertyCandidatesAction : AnAction() { val t = this.text val s = t.indexOf('{') val e = t.lastIndexOf('}') - if (s != e && s != -1) { - return t.substring(s, e).lines().size <= 3 - } - else return true + return if (s != e && s != -1) t.substring(s, e).lines().size <= 3 else true } diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinBreadcrumbsInfoProvider.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinBreadcrumbsInfoProvider.kt index 057b7152e3a..168a0da42ff 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinBreadcrumbsInfoProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinBreadcrumbsInfoProvider.kt @@ -365,12 +365,12 @@ class KotlinBreadcrumbsInfoProvider : BreadcrumbsInfoProvider() { val condition = conditions.firstOrNull() ?: return "->" val firstConditionText = condition.buildText(kind) - if (conditions.size == 1) { - return firstConditionText + " ->" + return if (conditions.size == 1) { + firstConditionText + " ->" } else { //TODO: show all conditions for tooltip - return (if (firstConditionText.endsWith(ellipsis)) firstConditionText else firstConditionText + ",$ellipsis") + " ->" + (if (firstConditionText.endsWith(ellipsis)) firstConditionText else firstConditionText + ",$ellipsis") + " ->" } } } @@ -434,12 +434,12 @@ class KotlinBreadcrumbsInfoProvider : BreadcrumbsInfoProvider() { override fun getParent(e: PsiElement): PsiElement? { val node = e.node ?: return null - when (node.elementType) { + return when (node.elementType) { KtNodeTypes.PROPERTY_ACCESSOR -> - return e.parent.parent + e.parent.parent else -> - return e.parent + e.parent } } diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/DebuggerClassNameProvider.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/DebuggerClassNameProvider.kt index 17b73c9e4da..f7a1566710f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/DebuggerClassNameProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/DebuggerClassNameProvider.kt @@ -188,13 +188,12 @@ class DebuggerClassNameProvider( val classNamesOfContainingDeclaration = getOuterClassNamesForElement(element.relevantParentInReadAction) - val nonInlineClasses: ComputedClassNames - if (runReadAction { element.name == null || element.isLocal }) { - nonInlineClasses = classNamesOfContainingDeclaration + ComputedClassNames.Cached( + val nonInlineClasses: ComputedClassNames = if (runReadAction { element.name == null || element.isLocal }) { + classNamesOfContainingDeclaration + ComputedClassNames.Cached( asmTypeForAnonymousClass(typeMapper.bindingContext, element).internalName.toJdiName()) } else { - nonInlineClasses = classNamesOfContainingDeclaration + classNamesOfContainingDeclaration } if (!findInlineUseSites || !element.isInlineInReadAction) { diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/InlineCallableUsagesSearcher.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/InlineCallableUsagesSearcher.kt index f23915f5319..2e7cb537db5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/InlineCallableUsagesSearcher.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/InlineCallableUsagesSearcher.kt @@ -101,11 +101,11 @@ class InlineCallableUsagesSearcher(val myDebugProcess: DebugProcess, val scopes: private fun getScopeForInlineDeclarationUsages(inlineDeclaration: KtDeclaration): GlobalSearchScope { val virtualFile = runReadAction { inlineDeclaration.containingFile.virtualFile } - if (virtualFile != null && ProjectRootsUtil.isLibraryFile(myDebugProcess.project, virtualFile)) { - return GlobalSearchScope.union(scopes.toTypedArray()) + return if (virtualFile != null && ProjectRootsUtil.isLibraryFile(myDebugProcess.project, virtualFile)) { + GlobalSearchScope.union(scopes.toTypedArray()) } else { - return myDebugProcess.searchScope + myDebugProcess.searchScope } } } \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointType.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointType.kt index 40f076f6ada..1dd5efc1970 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointType.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointType.kt @@ -160,11 +160,11 @@ class KotlinFieldBreakpointType : JavaBreakpointType): String? { val kotlinBreakpoint = BreakpointManager.getJavaBreakpoint(breakpoint) as? BreakpointWithHighlighter - if (kotlinBreakpoint != null) { - return kotlinBreakpoint.description + return if (kotlinBreakpoint != null) { + kotlinBreakpoint.description } else { - return super.getDisplayText(breakpoint) + super.getDisplayText(breakpoint) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinStepOverInlinedLinesHint.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinStepOverInlinedLinesHint.kt index 2edcaf6014d..0bb67a28e9e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinStepOverInlinedLinesHint.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinStepOverInlinedLinesHint.kt @@ -44,11 +44,11 @@ class KotlinStepOverInlinedLinesHint( val frameProxy = context.frameProxy if (frameProxy != null) { if (isTheSameFrame(context)) { - if (filter.locationMatches(context, frameProxy.location())) { - return STOP + return if (filter.locationMatches(context, frameProxy.location())) { + STOP } else { - return StepRequest.STEP_OVER + StepRequest.STEP_OVER } } diff --git a/idea/src/org/jetbrains/kotlin/idea/editor/KotlinLiteralCopyPasteProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/editor/KotlinLiteralCopyPasteProcessor.kt index 11b210b7e72..c645dc14f8d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/editor/KotlinLiteralCopyPasteProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/editor/KotlinLiteralCopyPasteProcessor.kt @@ -58,14 +58,14 @@ private fun deduceBlockSelectionWidth(startOffsets: IntArray, endOffsets: IntArr val fragmentCount = startOffsets.size assert(fragmentCount > 0) var totalLength = fragmentCount - 1 // number of line breaks inserted between fragments - for (i in 0..fragmentCount - 1) { + for (i in 0 until fragmentCount) { totalLength += endOffsets[i] - startOffsets[i] } - if (totalLength < text.length && (text.length + 1) % fragmentCount == 0) { - return (text.length + 1) / fragmentCount - 1 + return if (totalLength < text.length && (text.length + 1) % fragmentCount == 0) { + (text.length + 1) / fragmentCount - 1 } else { - return -1 + -1 } } diff --git a/idea/src/org/jetbrains/kotlin/idea/filters/KotlinExceptionFilter.kt b/idea/src/org/jetbrains/kotlin/idea/filters/KotlinExceptionFilter.kt index 5ffb0c91b30..19ce6cef9bb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/filters/KotlinExceptionFilter.kt +++ b/idea/src/org/jetbrains/kotlin/idea/filters/KotlinExceptionFilter.kt @@ -83,11 +83,11 @@ class KotlinExceptionFilter(private val searchScope: GlobalSearchScope) : Filter } if (filesByName.isNotEmpty()) { - if (filesByName.size > 1) { - return HyperlinkInfoFactoryImpl.getInstance().createMultipleFilesHyperlinkInfo(filesByName.toList(), lineNumber, project) + return if (filesByName.size > 1) { + HyperlinkInfoFactoryImpl.getInstance().createMultipleFilesHyperlinkInfo(filesByName.toList(), lineNumber, project) } else { - return OpenFileHyperlinkInfo(project, filesByName.first(), lineNumber) + OpenFileHyperlinkInfo(project, filesByName.first(), lineNumber) } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuspendCallLineMarkerProvider.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuspendCallLineMarkerProvider.kt index 9e0f60a61bb..b23c03a95f3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuspendCallLineMarkerProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuspendCallLineMarkerProvider.kt @@ -82,11 +82,11 @@ class KotlinSuspendCallLineMarkerProvider : LineMarkerProvider { if (!calleeDescriptor.isSuspend) continue markedLineNumbers += lineNumber - if (element is KtForExpression) { - result += SuspendCallMarkerInfo(element.loopRange!!, "Suspending iteration") + result += if (element is KtForExpression) { + SuspendCallMarkerInfo(element.loopRange!!, "Suspending iteration") } else { - result += SuspendCallMarkerInfo(element, "Suspend function call") + SuspendCallMarkerInfo(element, "Suspend function call") } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/injection/KotlinLanguageInjectionSupport.kt b/idea/src/org/jetbrains/kotlin/idea/injection/KotlinLanguageInjectionSupport.kt index f16c6ea2646..af3aba95603 100644 --- a/idea/src/org/jetbrains/kotlin/idea/injection/KotlinLanguageInjectionSupport.kt +++ b/idea/src/org/jetbrains/kotlin/idea/injection/KotlinLanguageInjectionSupport.kt @@ -228,15 +228,14 @@ private fun prevWalker(element: PsiElement, scope: PsiElement): Iterator return true - else -> return false - } +fun KtExpression.isExitStatement(): Boolean = when (this) { + is KtContinueExpression, is KtBreakExpression, is KtThrowExpression, is KtReturnExpression -> true + else -> false } // returns false for call of super, static method or method from package diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToSafeAccessIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToSafeAccessIntention.kt index c4724daded7..d5219634545 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToSafeAccessIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToSafeAccessIntention.kt @@ -41,11 +41,11 @@ class IfThenToSafeAccessIntention : SelfTargetingOffsetIndependentIntention return - in range.first!!.siblingsBefore() -> range = PsiChildRange(elementToAdd, range.last) + in range.first!!.siblingsBefore() -> PsiChildRange(elementToAdd, range.last) - else -> range = PsiChildRange(range.first, elementToAdd) + else -> PsiChildRange(range.first, elementToAdd) } } @@ -196,11 +196,11 @@ class CommentSavingRangeHolder(range: PsiChildRange) { .siblings(forward = true, withItself = false) .takeWhile { it != range.last!!.nextSibling } .firstOrNull { it !is PsiWhiteSpace } - if (newFirst != null) { - range = PsiChildRange(newFirst, range.last) + range = if (newFirst != null) { + PsiChildRange(newFirst, range.last) } else { - range = PsiChildRange.EMPTY + PsiChildRange.EMPTY } } @@ -209,11 +209,11 @@ class CommentSavingRangeHolder(range: PsiChildRange) { .siblings(forward = false, withItself = false) .takeWhile { it != range.first!!.prevSibling } .firstOrNull { it !is PsiWhiteSpace } - if (newLast != null) { - range = PsiChildRange(range.first, newLast) + range = if (newLast != null) { + PsiChildRange(range.first, newLast) } else { - range = PsiChildRange.EMPTY + PsiChildRange.EMPTY } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/FindTransformationMatcher.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/FindTransformationMatcher.kt index 3ccce0896a4..e582f0ef9fb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/FindTransformationMatcher.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/FindTransformationMatcher.kt @@ -235,13 +235,13 @@ object FindTransformationMatcher : TransformationMatcher { if (valueIfFound.isVariableReference(indexVariable) && valueIfNotFound.text == "-1") { val filterExpression = filterCondition!!.asExpression() val containsArgument = filterExpression.isFilterForContainsOperation(inputVariable, loop) - if (containsArgument != null) { + return if (containsArgument != null) { val functionName = if (findFirst) "indexOf" else "lastIndexOf" - return SimpleGenerator(functionName, inputVariable, null, containsArgument) + SimpleGenerator(functionName, inputVariable, null, containsArgument) } else { val functionName = if (findFirst) "indexOfFirst" else "indexOfLast" - return SimpleGenerator(functionName, inputVariable, filterExpression) + SimpleGenerator(functionName, inputVariable, filterExpression) } } @@ -337,15 +337,14 @@ object FindTransformationMatcher : TransformationMatcher { val containsArgument = filterExpression.isFilterForContainsOperation(inputVariable, loop) if (containsArgument != null) { val generator = SimpleGenerator("contains", inputVariable, null, containsArgument) - if (negated) { - return object : FindOperationGenerator(generator) { - override fun generate(chainedCallGenerator: ChainedCallGenerator): KtExpression { - return generator.generate(chainedCallGenerator).negate() - } + return if (negated) { + object : FindOperationGenerator(generator) { + override fun generate(chainedCallGenerator: ChainedCallGenerator): KtExpression = + generator.generate(chainedCallGenerator).negate() } } else { - return generator + generator } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/SumTransformation.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/SumTransformation.kt index 191fa8d5cc0..d0197a99d90 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/SumTransformation.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/SumTransformation.kt @@ -36,11 +36,11 @@ abstract class SumTransformationBase( override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { val call = generateCall(chainedCallGenerator) - if (initialization.initializer.isZeroConstant()) { - return call + return if (initialization.initializer.isZeroConstant()) { + call } else { - return KtPsiFactory(call).createExpressionByPattern("$0 + $1", initialization.initializer, call) + KtPsiFactory(call).createExpressionByPattern("$0 + $1", initialization.initializer, call) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FilterTransformation.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FilterTransformation.kt index 1407755d967..25a988594c1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FilterTransformation.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FilterTransformation.kt @@ -101,12 +101,12 @@ abstract class FilterTransformationBase : SequenceTransformation { assert(transformations.isNotEmpty()) val findTransformationMatch = FindTransformationMatcher.matchWithFilterBefore(currentState, transformations.last()) - if (findTransformationMatch != null) { - return TransformationMatch.Result(findTransformationMatch.resultTransformation, - transformations.dropLast(1) + findTransformationMatch.sequenceTransformations) + return if (findTransformationMatch != null) { + TransformationMatch.Result(findTransformationMatch.resultTransformation, + transformations.dropLast(1) + findTransformationMatch.sequenceTransformations) } else { - return TransformationMatch.Sequence(transformations, currentState) + TransformationMatch.Sequence(transformations, currentState) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/utils.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/utils.kt index 2929bc9d60f..ee26279ee51 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/utils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/utils.kt @@ -376,15 +376,15 @@ fun KtExpression.countEmbeddedBreaksAndContinues(): Int { private fun isEmbeddedBreakOrContinue(expression: KtExpressionWithLabel): Boolean { if (expression !is KtBreakExpression && expression !is KtContinueExpression) return false val parent = expression.parent - when (parent) { - is KtBlockExpression -> return false + return when (parent) { + is KtBlockExpression -> false is KtContainerNode -> { val containerExpression = parent.parent as KtExpression - return containerExpression.isUsedAsExpression(containerExpression.analyze(BodyResolveMode.PARTIAL)) + containerExpression.isUsedAsExpression(containerExpression.analyze(BodyResolveMode.PARTIAL)) } - else -> return true + else -> true } } diff --git a/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt b/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt index 5f8c18f275a..c78d5b7a57b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt @@ -162,11 +162,11 @@ object KDocRenderer { // Avoid wrapping the entire converted contents in a

tag if it's just a single paragraph val maybeSingleParagraph = markdownNode.children.singleOrNull { it.type != MarkdownTokenTypes.EOL } - if (maybeSingleParagraph != null && !allowSingleParagraph) { - return maybeSingleParagraph.children.joinToString("") { it.toHtml() } + return if (maybeSingleParagraph != null && !allowSingleParagraph) { + maybeSingleParagraph.children.joinToString("") { it.toHtml() } } else { - return markdownNode.toHtml() + markdownNode.toHtml() } } diff --git a/idea/src/org/jetbrains/kotlin/idea/projectView/KtClassOrObjectTreeNode.kt b/idea/src/org/jetbrains/kotlin/idea/projectView/KtClassOrObjectTreeNode.kt index d8b165aad3f..891df55c475 100644 --- a/idea/src/org/jetbrains/kotlin/idea/projectView/KtClassOrObjectTreeNode.kt +++ b/idea/src/org/jetbrains/kotlin/idea/projectView/KtClassOrObjectTreeNode.kt @@ -34,8 +34,8 @@ class KtClassOrObjectTreeNode(project: Project?, ktClassOrObject: KtClassOrObjec override fun extractPsiFromValue(): PsiElement? = value override fun getChildrenImpl(): Collection>? { - if (value != null && settings.isShowMembers) { - return value.getStructureDeclarations().map { declaration -> + return if (value != null && settings.isShowMembers) { + value.getStructureDeclarations().map { declaration -> if (declaration is KtClassOrObject) KtClassOrObjectTreeNode(project, declaration, settings) else @@ -43,7 +43,7 @@ class KtClassOrObjectTreeNode(project: Project?, ktClassOrObject: KtClassOrObjec } } else { - return emptyList() + emptyList() } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceInfixOrOperatorCallFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceInfixOrOperatorCallFix.kt index 1d99a4ceded..fa4b8a499a4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceInfixOrOperatorCallFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceInfixOrOperatorCallFix.kt @@ -68,10 +68,10 @@ class ReplaceInfixOrOperatorCallFix( replacement = element.replace(newExpression) } is KtBinaryExpression -> { - if (element.operationToken == KtTokens.IDENTIFIER) { + replacement = if (element.operationToken == KtTokens.IDENTIFIER) { val newExpression = psiFactory.createExpressionByPattern( "$0?.$1($2)$elvis", element.left ?: return, element.operationReference, element.right ?: return) - replacement = element.replace(newExpression) + element.replace(newExpression) } else { val nameExpression = OperatorToFunctionIntention.convert(element).second @@ -79,7 +79,7 @@ class ReplaceInfixOrOperatorCallFix( val qualifiedExpression = callExpression.parent as KtDotQualifiedExpression val safeExpression = psiFactory.createExpressionByPattern( "$0?.$1$elvis", qualifiedExpression.receiverExpression, callExpression) - replacement = qualifiedExpression.replace(safeExpression) + qualifiedExpression.replace(safeExpression) } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt index 9eaa5320b87..bd068856ea8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt @@ -220,12 +220,12 @@ private fun KtNamedDeclaration.guessType(context: BindingContext): Array KotlinTypeChecker.DEFAULT.equalTypes(currentType, substitution.forType) Variance.IN_VARIANCE -> KotlinTypeChecker.DEFAULT.isSubtypeOf(currentType, substitution.forType) Variance.OUT_VARIANCE -> KotlinTypeChecker.DEFAULT.isSubtypeOf(substitution.forType, currentType) }) { - return TypeUtils.makeNullableAsSpecified(substitution.byType, nullable) + TypeUtils.makeNullableAsSpecified(substitution.byType, nullable) } else { val newArguments = arguments.zip(constructor.parameters).map { pair -> val (projection, typeParameter) = pair TypeProjectionImpl(Variance.INVARIANT, projection.type.substitute(substitution, typeParameter.variance)) } - return KotlinTypeFactory.simpleType(annotations, constructor, newArguments, isMarkedNullable, memberScope) + KotlinTypeFactory.simpleType(annotations, constructor, newArguments, isMarkedNullable, memberScope) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt index 9c0758b73b8..275b504a075 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt @@ -87,16 +87,15 @@ class KotlinChangeSignatureDialog( override fun getRowPresentation(item: ParameterTableModelItemBase, selected: Boolean, focused: Boolean): JComponent? { val panel = JPanel(BorderLayout()) - val valOrVar: String - if (myMethod.kind === Kind.PRIMARY_CONSTRUCTOR) { - valOrVar = when (item.parameter.valOrVar) { + val valOrVar = if (myMethod.kind === Kind.PRIMARY_CONSTRUCTOR) { + when (item.parameter.valOrVar) { KotlinValVar.None -> " " KotlinValVar.Val -> "val " KotlinValVar.Var -> "var " } } else { - valOrVar = "" + "" } val parameterName = getPresentationName(item) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinCallableDefinitionUsage.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinCallableDefinitionUsage.kt index 3027048c087..948b74bf5a0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinCallableDefinitionUsage.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinCallableDefinitionUsage.kt @@ -197,11 +197,11 @@ class KotlinCallableDefinitionUsage( if (newParameterList == null) return if (parameterList != null) { - if (canReplaceEntireList) { - newParameterList = parameterList.replace(newParameterList) as KtParameterList + newParameterList = if (canReplaceEntireList) { + parameterList.replace(newParameterList) as KtParameterList } else { - newParameterList = replaceListPsiAndKeepDelimiters(parameterList, newParameterList) { parameters } + replaceListPsiAndKeepDelimiters(parameterList, newParameterList) { parameters } } } else { diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt index 7ecc129f705..8ccffa7c4d0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt @@ -435,8 +435,7 @@ class KotlinFunctionCallUsage( var newElement: KtElement = element if (newReceiverInfo != originalReceiverInfo) { - val replacingElement: PsiElement - if (newReceiverInfo != null) { + val replacingElement: PsiElement = if (newReceiverInfo != null) { val receiverArgument = getResolvedValueArgument(newReceiverInfo.oldIndex)?.arguments?.singleOrNull() val extensionReceiverExpression = receiverArgument?.getArgumentExpression() val defaultValueForCall = newReceiverInfo.defaultValueForCall @@ -444,10 +443,10 @@ class KotlinFunctionCallUsage( ?: defaultValueForCall ?: psiFactory.createExpression("_") - replacingElement = psiFactory.createExpressionByPattern("$0.$1", receiver, element) + psiFactory.createExpressionByPattern("$0.$1", receiver, element) } else { - replacingElement = psiFactory.createExpression(element.text) + psiFactory.createExpression(element.text) } newElement = fullCallElement.replace(replacingElement) as KtElement diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractFunction/ui/ExtractFunctionParameterTablePanel.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractFunction/ui/ExtractFunctionParameterTablePanel.kt index bd0bec33aaf..f1aab815ae5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractFunction/ui/ExtractFunctionParameterTablePanel.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractFunction/ui/ExtractFunctionParameterTablePanel.kt @@ -116,10 +116,10 @@ open class ExtractFunctionParameterTablePanel : AbstractParameterTablePanel return super.isCellEditable(rowIndex, columnIndex) && !info.isReceiver - PARAMETER_TYPE_COLUMN -> return isEnabled && info.isEnabled && info.originalParameter.getParameterTypeCandidates(false).size > 1 - else -> return super.isCellEditable(rowIndex, columnIndex) + return when (columnIndex) { + AbstractParameterTablePanel.PARAMETER_NAME_COLUMN -> super.isCellEditable(rowIndex, columnIndex) && !info.isReceiver + PARAMETER_TYPE_COLUMN -> isEnabled && info.isEnabled && info.originalParameter.getParameterTypeCandidates(false).size > 1 + else -> super.isCellEditable(rowIndex, columnIndex) } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt index 152b746e522..c35f9cb0499 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt @@ -875,10 +875,10 @@ fun checkSuperMethods( val exitCode = showYesNoCancelDialog( CHECK_SUPER_METHODS_YES_NO_DIALOG, declaration.project, message, IdeBundle.message("title.warning"), Messages.getQuestionIcon(), Messages.YES) - when (exitCode) { - Messages.YES -> return overriddenElementsToDescriptor.keys.toList() - Messages.NO -> return listOf(declaration) - else -> return emptyList() + return when (exitCode) { + Messages.YES -> overriddenElementsToDescriptor.keys.toList() + Messages.NO -> listOf(declaration) + else -> emptyList() } } diff --git a/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt b/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt index e2a4f5b3c06..f3d59170d1a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt +++ b/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt @@ -78,11 +78,11 @@ class ImportInsertHelperImpl(private val project: Project) : ImportInsertHelper( override fun importDescriptor(file: KtFile, descriptor: DeclarationDescriptor, forceAllUnderImport: Boolean): ImportDescriptorResult { val importer = Importer(file) - if (forceAllUnderImport) { - return importer.importDescriptorWithStarImport(descriptor) + return if (forceAllUnderImport) { + importer.importDescriptorWithStarImport(descriptor) } else { - return importer.importDescriptor(descriptor) + importer.importDescriptor(descriptor) } } @@ -378,9 +378,9 @@ class ImportInsertHelperImpl(private val project: Project) : ImportInsertHelper( if (importList != null) { val newDirective = psiFactory.createImportDirective(importPath) val imports = importList.imports - if (imports.isEmpty()) { //TODO: strange hack + return if (imports.isEmpty()) { //TODO: strange hack importList.add(psiFactory.createNewLine()) - return importList.add(newDirective) as KtImportDirective + importList.add(newDirective) as KtImportDirective } else { val insertAfter = imports @@ -388,7 +388,7 @@ class ImportInsertHelperImpl(private val project: Project) : ImportInsertHelper( val directivePath = it.importPath directivePath != null && ImportPathComparator.compare(directivePath, importPath) <= 0 } - return importList.addAfter(newDirective, insertAfter) as KtImportDirective + importList.addAfter(newDirective, insertAfter) as KtImportDirective } } else { diff --git a/j2k/src/org/jetbrains/kotlin/j2k/ExpressionConverter.kt b/j2k/src/org/jetbrains/kotlin/j2k/ExpressionConverter.kt index 3f48a468fa0..92dcef60175 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/ExpressionConverter.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/ExpressionConverter.kt @@ -101,11 +101,11 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter { } val operator = Operator(tokenType).assignPrototype(expression.operationSign) - if (secondOp) { - result = AssignmentExpression(lhs, BinaryExpression(lhs, rhs, operator).assignNoPrototype(), Operator.EQ) + result = if (secondOp) { + AssignmentExpression(lhs, BinaryExpression(lhs, rhs, operator).assignNoPrototype(), Operator.EQ) } else { - result = AssignmentExpression(lhs, rhs, operator) + AssignmentExpression(lhs, rhs, operator) } } @@ -532,14 +532,14 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter { override fun visitPrefixExpression(expression: PsiPrefixExpression) { val operand = codeConverter.convertExpression(expression.operand, expression.operand!!.type) val token = expression.operationTokenType - if (token == JavaTokenType.TILDE) { - result = MethodCallExpression.buildNonNull(operand, "inv") + result = if (token == JavaTokenType.TILDE) { + MethodCallExpression.buildNonNull(operand, "inv") } else if (token == JavaTokenType.EXCL && operand is BinaryExpression && operand.op.asString() == "==") { // happens when equals is converted to == - result = BinaryExpression(operand.left, operand.right, Operator(JavaTokenType.NE).assignPrototype(expression.operand)) + BinaryExpression(operand.left, operand.right, Operator(JavaTokenType.NE).assignPrototype(expression.operand)) } else { - result = PrefixExpression(Operator(token).assignPrototype(expression.operand), operand) + PrefixExpression(Operator(token).assignPrototype(expression.operand), operand) } } @@ -612,16 +612,15 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter { if (!converter.inConversionScope(target)) return false - val canChangeType: Boolean - when (target) { + val canChangeType: Boolean = when (target) { is PsiLocalVariable -> { if (converter.settings.specifyLocalVariableTypeByDefault) return false - canChangeType = codeConverter.canChangeType(target) + codeConverter.canChangeType(target) } is PsiField -> { if (converter.settings.specifyFieldTypeByDefault) return false - canChangeType = target.hasModifierProperty(PsiModifier.PRIVATE) + target.hasModifierProperty(PsiModifier.PRIVATE) } else -> return false @@ -652,8 +651,8 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter { val typeText = castType.type.canonicalText val typeConversion = PRIMITIVE_TYPE_CONVERSIONS[typeText] val operandConverted = codeConverter.convertExpression(operand) - if (operandType is PsiPrimitiveType && typeConversion != null) { - result = MethodCallExpression.buildNonNull(operandConverted, typeConversion) + result = if (operandType is PsiPrimitiveType && typeConversion != null) { + MethodCallExpression.buildNonNull(operandConverted, typeConversion) } else { val nullability = if (operandConverted.isNullable && !expression.isQualifier()) @@ -661,16 +660,16 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter { else Nullability.NotNull val typeConverted = typeConverter.convertType(castType.type, nullability) - result = TypeCastExpression(typeConverted, operandConverted) + TypeCastExpression(typeConverted, operandConverted) } } private fun PsiExpression.isQualifier(): Boolean { val parent = parent - when (parent) { - is PsiParenthesizedExpression -> return parent.isQualifier() - is PsiReferenceExpression -> return this == parent.qualifierExpression - else -> return false + return when (parent) { + is PsiParenthesizedExpression -> parent.isQualifier() + is PsiReferenceExpression -> this == parent.qualifierExpression + else -> false } } @@ -876,12 +875,12 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter { val lambdaExpression = LambdaExpression(lambdaParameterList, Block.of(statement).assignNoPrototype()).assignNoPrototype() - if (isKotlinFunctionType) { - result = lambdaExpression + result = if (isKotlinFunctionType) { + lambdaExpression } else { val convertedFunctionalType = converter.typeConverter.convertType(functionalType) - result = MethodCallExpression.buildNonNull( + MethodCallExpression.buildNonNull( null, convertedFunctionalType.canonicalCode(), ArgumentList.withNoPrototype(lambdaExpression) diff --git a/j2k/src/org/jetbrains/kotlin/j2k/ForConverter.kt b/j2k/src/org/jetbrains/kotlin/j2k/ForConverter.kt index 897e2fed54a..8a1b9052b9c 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/ForConverter.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/ForConverter.kt @@ -60,16 +60,16 @@ class ForConverter( val continueConverted = this@ForConverter.codeConverter.convertStatement(statement) val statements = listOf(updateConverted, continueConverted) - if (statement.parent is PsiCodeBlock) { + return if (statement.parent is PsiCodeBlock) { // generate fictive statement which will generate multiple statements - return object : Statement() { + object : Statement() { override fun generateCode(builder: CodeBuilder) { builder.append(statements, "\n") } } } else { - return Block.of(statements) + Block.of(statements) } } }) diff --git a/j2k/src/org/jetbrains/kotlin/j2k/SpecialMethod.kt b/j2k/src/org/jetbrains/kotlin/j2k/SpecialMethod.kt index 3ba95c312e9..ecdcfa5fcb0 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/SpecialMethod.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/SpecialMethod.kt @@ -307,11 +307,11 @@ enum class SpecialMethod(val qualifiedClassName: String?, val methodName: String = super.matches(method, superMethodsSearcher) && method.parameterList.let { it.parametersCount == 2 && it.parameters.last().isVarArgs } override fun ConvertCallData.convertCall(): Expression? { - if (arguments.size == 2 && arguments.last().isAssignableToCharSequenceArray()) { - return STRING_JOIN.convertCall(this) + return if (arguments.size == 2 && arguments.last().isAssignableToCharSequenceArray()) { + STRING_JOIN.convertCall(this) } else { - return MethodCallExpression.buildNonNull( + MethodCallExpression.buildNonNull( MethodCallExpression.buildNonNull(null, "arrayOf", ArgumentList.withNoPrototype(codeConverter.convertExpressionsInList(arguments.drop(1)))).assignNoPrototype(), "joinToString", ArgumentList.withNoPrototype(codeConverter.convertExpressionsInList(arguments.take(1))) diff --git a/j2k/src/org/jetbrains/kotlin/j2k/StatementConverter.kt b/j2k/src/org/jetbrains/kotlin/j2k/StatementConverter.kt index 26773cc15f9..9beae944c76 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/StatementConverter.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/StatementConverter.kt @@ -53,13 +53,13 @@ class DefaultStatementConverter : JavaElementVisitor(), StatementConverter { override fun visitAssertStatement(statement: PsiAssertStatement) { val descriptionExpr = statement.assertDescription val condition = codeConverter.convertExpression(statement.assertCondition) - if (descriptionExpr == null) { - result = MethodCallExpression.buildNonNull(null, "assert", ArgumentList.withNoPrototype(condition)) + result = if (descriptionExpr == null) { + MethodCallExpression.buildNonNull(null, "assert", ArgumentList.withNoPrototype(condition)) } else { val description = codeConverter.convertExpression(descriptionExpr) val lambda = LambdaExpression(null, Block.of(description).assignNoPrototype()) - result = MethodCallExpression.buildNonNull(null, "assert", ArgumentList.withNoPrototype(condition, lambda)) + MethodCallExpression.buildNonNull(null, "assert", ArgumentList.withNoPrototype(condition, lambda)) } } @@ -69,20 +69,20 @@ class DefaultStatementConverter : JavaElementVisitor(), StatementConverter { } override fun visitBreakStatement(statement: PsiBreakStatement) { - if (statement.labelIdentifier == null) { - result = BreakStatement(Identifier.Empty) + result = if (statement.labelIdentifier == null) { + BreakStatement(Identifier.Empty) } else { - result = BreakStatement(converter.convertIdentifier(statement.labelIdentifier)) + BreakStatement(converter.convertIdentifier(statement.labelIdentifier)) } } override fun visitContinueStatement(statement: PsiContinueStatement) { - if (statement.labelIdentifier == null) { - result = ContinueStatement(Identifier.Empty) + result = if (statement.labelIdentifier == null) { + ContinueStatement(Identifier.Empty) } else { - result = ContinueStatement(converter.convertIdentifier(statement.labelIdentifier)) + ContinueStatement(converter.convertIdentifier(statement.labelIdentifier)) } } @@ -139,12 +139,13 @@ class DefaultStatementConverter : JavaElementVisitor(), StatementConverter { override fun visitLabeledStatement(statement: PsiLabeledStatement) { val statementConverted = codeConverter.convertStatement(statement.statement) val identifier = converter.convertIdentifier(statement.labelIdentifier) - if (statementConverted is ForConverter.WhileWithInitializationPseudoStatement) { // special case - if our loop gets converted to while with initialization we should move the label to the loop + result = if (statementConverted is ForConverter.WhileWithInitializationPseudoStatement) { + // special case - if our loop gets converted to while with initialization we should move the label to the loop val labeledLoop = LabeledStatement(identifier, statementConverted.loop).assignPrototype(statement) - result = ForConverter.WhileWithInitializationPseudoStatement(statementConverted.initialization, labeledLoop, statementConverted.kind) + ForConverter.WhileWithInitializationPseudoStatement(statementConverted.initialization, labeledLoop, statementConverted.kind) } else { - result = LabeledStatement(identifier, statementConverted) + LabeledStatement(identifier, statementConverted) } } diff --git a/j2k/src/org/jetbrains/kotlin/j2k/TypeVisitor.kt b/j2k/src/org/jetbrains/kotlin/j2k/TypeVisitor.kt index f17c5dbaa6e..fa49b48a208 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/TypeVisitor.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/TypeVisitor.kt @@ -83,11 +83,11 @@ class TypeVisitor( } private fun convertTypeArgs(classType: PsiClassType): List { - if (classType.parameterCount == 0) { - return createTypeArgsForRawTypeUsage(classType, Mutability.Default) + return if (classType.parameterCount == 0) { + createTypeArgsForRawTypeUsage(classType, Mutability.Default) } else { - return typeConverter.convertTypes(classType.parameters) + typeConverter.convertTypes(classType.parameters) } } diff --git a/j2k/src/org/jetbrains/kotlin/j2k/Utils.kt b/j2k/src/org/jetbrains/kotlin/j2k/Utils.kt index 9180e3d9c30..b6fd0e645e1 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/Utils.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/Utils.kt @@ -111,16 +111,16 @@ fun PsiExpressionList.lPar(): PsiElement? = node.findChildByType(JavaTokenType.L fun PsiExpressionList.rPar(): PsiElement? = node.findChildByType(JavaTokenType.RPARENTH)?.psi fun PsiMember.isImported(file: PsiJavaFile): Boolean { - if (this is PsiClass) { + return if (this is PsiClass) { val fqName = qualifiedName val index = fqName?.lastIndexOf('.') ?: -1 val parentName = if (index >= 0) fqName!!.substring(0, index) else null - return file.importList?.allImportStatements?.any { + file.importList?.allImportStatements?.any { it.importReference?.qualifiedName == (if (it.isOnDemand) parentName else fqName) } ?: false } else { - return containingClass != null && file.importList?.importStaticStatements?.any { + containingClass != null && file.importList?.importStaticStatements?.any { it.resolveTargetClass() == containingClass && (it.isOnDemand || it.referenceName == name) } ?: false } diff --git a/j2k/src/org/jetbrains/kotlin/j2k/importConversion.kt b/j2k/src/org/jetbrains/kotlin/j2k/importConversion.kt index a4e9bab739d..fccd5a52c7a 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/importConversion.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/importConversion.kt @@ -70,16 +70,16 @@ private fun Converter.convertImport(fqName: FqName, ref: PsiJavaCodeReferenceEle //TODO: how to detect compiled Kotlin here? val target = ref.resolve() - if (isImportStatic) { + return if (isImportStatic) { if (isOnDemand) { - return convertStaticImportOnDemand(fqName, target) + convertStaticImportOnDemand(fqName, target) } else { - return convertStaticExplicitImport(fqName, target) + convertStaticExplicitImport(fqName, target) } } else { - return convertNonStaticImport(fqName, isOnDemand, target) + convertNonStaticImport(fqName, isOnDemand, target) } } diff --git a/j2k/src/org/jetbrains/kotlin/j2k/usageProcessing/MemberIntoObjectProcessing.kt b/j2k/src/org/jetbrains/kotlin/j2k/usageProcessing/MemberIntoObjectProcessing.kt index 79c47a838eb..440cc54ba33 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/usageProcessing/MemberIntoObjectProcessing.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/usageProcessing/MemberIntoObjectProcessing.kt @@ -32,15 +32,15 @@ class MemberIntoObjectProcessing(private val member: PsiMember, private val obje val refExpr = reference.element as? PsiReferenceExpression ?: return null val qualifier = refExpr.qualifierExpression val factory = PsiElementFactory.SERVICE.getInstance(member.project) - if (qualifier != null) { + return if (qualifier != null) { val newQualifier = factory.createExpressionFromText(qualifier.text + "." + objectName, null) qualifier.replace(newQualifier) - return arrayOf(reference) + arrayOf(reference) } else { var qualifiedExpr = factory.createExpressionFromText(objectName + "." + refExpr.text, null) as PsiReferenceExpression qualifiedExpr = refExpr.replace(qualifiedExpr) as PsiReferenceExpression - return arrayOf(qualifiedExpr) + arrayOf(qualifiedExpr) } } } diff --git a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt index b3f71c05b45..c32fe8ac171 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt @@ -224,12 +224,10 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { } } - private fun getReturnCodeFromObject(rc: Any?): String { - when { - rc == null -> return INTERNAL_ERROR - ExitCode::class.java.name == rc::class.java.name -> return rc.toString() - else -> throw IllegalStateException("Unexpected return: " + rc) - } + private fun getReturnCodeFromObject(rc: Any?): String = when { + rc == null -> INTERNAL_ERROR + ExitCode::class.java.name == rc::class.java.name -> rc.toString() + else -> throw IllegalStateException("Unexpected return: " + rc) } override fun getDaemonConnection(environment: JpsCompilerEnvironment): CompileServiceSession? = diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/naming/encodeSignature.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/naming/encodeSignature.kt index 21f6f584728..a1fd6f49752 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/naming/encodeSignature.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/naming/encodeSignature.kt @@ -106,8 +106,8 @@ private fun StringBuilder.encodeForSignature( parameter: TypeParameterDescriptor, typeParameterNamer: (TypeParameterDescriptor) -> String ): StringBuilder { - if (projection.isStarProjection) { - return append("*") + return if (projection.isStarProjection) { + append("*") } else { when (getEffectiveVariance(parameter.variance, projection.projectionKind)) { @@ -115,7 +115,7 @@ private fun StringBuilder.encodeForSignature( Variance.OUT_VARIANCE -> append("+") Variance.INVARIANT -> {} } - return encodeForSignature(projection.type, typeParameterNamer) + encodeForSignature(projection.type, typeParameterNamer) } } diff --git a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionReader.kt b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionReader.kt index 60cabc14ef5..69b25d9f1a5 100644 --- a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionReader.kt +++ b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionReader.kt @@ -224,12 +224,10 @@ private fun JsFunction.markInlineArguments(descriptor: CallableDescriptor) { val visitor = object: JsVisitorWithContextImpl() { override fun endVisit(x: JsInvocation, ctx: JsContext<*>) { - val qualifier: JsExpression? - - if (isCallInvocation(x)) { - qualifier = (x.qualifier as? JsNameRef)?.qualifier + val qualifier: JsExpression? = if (isCallInvocation(x)) { + (x.qualifier as? JsNameRef)?.qualifier } else { - qualifier = x.qualifier + x.qualifier } (qualifier as? JsNameRef)?.name?.let { name -> diff --git a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/DynamicTypeDeserializer.kt b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/DynamicTypeDeserializer.kt index a8dcf56b792..47d54263f5b 100644 --- a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/DynamicTypeDeserializer.kt +++ b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/DynamicTypeDeserializer.kt @@ -30,12 +30,12 @@ object DynamicTypeDeserializer : FlexibleTypeDeserializer { override fun create(proto: ProtoBuf.Type, flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType { if (flexibleId != id) return ErrorUtils.createErrorType("Unexpected id: $flexibleId. ($lowerBound..$upperBound)") - if (StrictEqualityTypeChecker.strictEqualTypes(lowerBound, lowerBound.builtIns.nothingType) && - StrictEqualityTypeChecker.strictEqualTypes(upperBound, upperBound.builtIns.nullableAnyType)) { - return createDynamicType(lowerBound.builtIns) + return if (StrictEqualityTypeChecker.strictEqualTypes(lowerBound, lowerBound.builtIns.nothingType) && + StrictEqualityTypeChecker.strictEqualTypes(upperBound, upperBound.builtIns.nullableAnyType)) { + createDynamicType(lowerBound.builtIns) } else { - return ErrorUtils.createErrorType("Illegal type range for dynamic type: $lowerBound..$upperBound") + ErrorUtils.createErrorType("Illegal type range for dynamic type: $lowerBound..$upperBound") } } } \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeDeclaredType.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeDeclaredType.kt index 532561b1850..3159182185d 100644 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeDeclaredType.kt +++ b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/types/JeDeclaredType.kt @@ -78,10 +78,10 @@ class JeDeclaredType( val args = mutableListOf() for (typeParameter in psiClass.typeParameters) { val substitutedParameter = substitutor.substitute(typeParameter) - if (substitutedParameter != null) - args += substitutedParameter.toJeType(psiManager) + args += if (substitutedParameter != null) + substitutedParameter.toJeType(psiManager) else - args += JeTypeVariableType(typeParameter.getTypeWithTypeParameters(), typeParameter) + JeTypeVariableType(typeParameter.getTypeWithTypeParameters(), typeParameter) } args diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt index d2f3c5fc563..d013813342b 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt @@ -168,9 +168,9 @@ open class KotlinUSimpleReferenceExpression( val assignment = expression.getAssignmentByLHS() if (assignment != null) { - when (assignment.operationToken) { - KtTokens.EQ -> return ReferenceAccess.WRITE - else -> return ReferenceAccess.READ_WRITE + return when (assignment.operationToken) { + KtTokens.EQ -> ReferenceAccess.WRITE + else -> ReferenceAccess.READ_WRITE } }