From 9c06739594533ebde39ae46777385dd1b34230a5 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 28 Jun 2017 14:30:52 +0300 Subject: [PATCH] Cleanup: apply "lift out..." inspection (+ some others) --- .../inline/AnonymousObjectTransformer.kt | 18 ++++---- .../kotlin/cli/common/repl/BasicReplState.kt | 6 +-- .../cfg/ConstructorConsistencyChecker.kt | 2 +- .../cfg/ControlFlowInformationProvider.kt | 12 +++-- .../kotlin/cfg/ControlFlowProcessor.kt | 27 ++++++------ .../ControlFlowInstructionsGenerator.kt | 17 +++---- .../jetbrains/kotlin/psi/createByPattern.kt | 18 ++++---- .../kotlin/types/CastDiagnosticsUtil.kt | 7 ++- .../ConstAndJvmFieldPropertiesLowering.kt | 6 +-- .../BranchingExpressionGenerator.kt | 10 ++--- .../resolve/constants/constantValues.kt | 18 ++++---- .../deserialization/AnnotationDeserializer.kt | 6 +-- .../jetbrains/kotlin/idea/util/CallType.kt | 6 +-- .../jetbrains/kotlin/android/AndroidUtil.kt | 6 +-- .../idea/completion/BasicCompletionSession.kt | 22 +++++----- .../completion/BasicLookupElementFactory.kt | 44 ++++++++++--------- .../idea/completion/CompletionSession.kt | 6 +-- .../kotlin/idea/completion/CompletionUtils.kt | 12 ++--- .../kotlin/console/CommandHistory.kt | 6 +-- .../breakpoints/breakpointTypeUtils.kt | 6 +-- .../idea/inspections/CanBeValInspection.kt | 6 +-- .../ConflictingExtensionPropertyInspection.kt | 36 +++++++-------- .../idea/intentions/AddBracesIntention.kt | 8 ++-- ...naryExpressionWithDemorgansLawIntention.kt | 6 +-- ...ertPropertyInitializerToGetterIntention.kt | 6 +-- .../ConvertToStringTemplateIntention.kt | 6 +-- .../branchedTransformationUtils.kt | 22 ++++------ .../loopToCallChain/baseTransformations.kt | 6 +-- .../intentions/loopToCallChain/commonUtils.kt | 6 +-- .../result/AddToCollectionTransformation.kt | 44 +++++++++---------- .../result/CountTransformation.kt | 6 +-- .../quickfix/AddFunctionToSupertypeFix.kt | 6 +-- .../quickfix/ChangeCallableReturnTypeFix.kt | 6 +-- .../quickfix/ChangeFunctionSignatureFix.kt | 8 ++-- .../ChangeMemberFunctionSignatureFix.kt | 6 +-- .../idea/quickfix/ChangeVariableTypeFix.kt | 12 ++--- .../callableBuilder/CallableBuilder.kt | 19 ++++---- .../CreateTypeParameterFromUsageFix.kt | 6 +-- .../idea/refactoring/CallableRefactoring.kt | 12 ++--- .../kotlin/j2k/AnnotationConverter.kt | 9 ++-- .../kotlin/j2k/ClassBodyConverter.kt | 6 +-- .../org/jetbrains/kotlin/j2k/CodeBuilder.kt | 8 ++-- .../kotlin/j2k/ConstructorConverter.kt | 6 +-- j2k/src/org/jetbrains/kotlin/j2k/Converter.kt | 28 ++++++------ .../AccessorToPropertyProcessing.kt | 6 +-- .../js/descriptorUtils/descriptorUtils.kt | 8 ++-- .../js/translate/callTranslator/CallInfo.kt | 6 +-- .../callTranslator/CallInfoExtensions.kt | 10 ++--- .../callTranslator/CallTranslator.kt | 14 +++--- .../intrinsic/functions/factories/ArrayFIF.kt | 6 +-- .../reference/CallArgumentTranslator.kt | 10 ++--- .../kotlin/js/translate/utils/astUtils.kt | 6 +-- 52 files changed, 294 insertions(+), 311 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt index 2063654220d..d93894acbc1 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt @@ -78,11 +78,11 @@ class AnonymousObjectTransformer( override fun visitField(access: Int, name: String, desc: String, signature: String?, value: Any?): FieldVisitor? { addUniqueField(name) - if (isCapturedFieldName(name)) { - return null + return if (isCapturedFieldName(name)) { + null } else { - return classBuilder.newField(JvmDeclarationOrigin.NO_ORIGIN, access, name, desc, signature, value) + classBuilder.newField(JvmDeclarationOrigin.NO_ORIGIN, access, name, desc, signature, value) } } @@ -95,12 +95,12 @@ class AnonymousObjectTransformer( }, ClassReader.SKIP_FRAMES) if (!inliningContext.isInliningLambda) { - if (debugInfo != null && !debugInfo!!.isEmpty()) { - sourceMapper = SourceMapper.createFromSmap(SMAPParser.parse(debugInfo!!)) + sourceMapper = if (debugInfo != null && !debugInfo!!.isEmpty()) { + SourceMapper.createFromSmap(SMAPParser.parse(debugInfo!!)) } else { //seems we can't do any clever mapping cause we don't know any about original class name - sourceMapper = IdenticalSourceMapper + IdenticalSourceMapper } if (sourceInfo != null && !GENERATE_SMAP) { classBuilder.visitSource(sourceInfo!!, debugInfo) @@ -458,12 +458,12 @@ class AnonymousObjectTransformer( private fun getNewFieldName(oldName: String, originalField: Boolean): String { if (THIS_0 == oldName) { - if (!originalField) { - return oldName + return if (!originalField) { + oldName } else { //rename original 'this$0' in declaration site lambda (inside inline function) to use this$0 only for outer lambda/object access on call site - return addUniqueField(oldName + INLINE_FUN_THIS_0_SUFFIX) + addUniqueField(oldName + INLINE_FUN_THIS_0_SUFFIX) } } return addUniqueField(oldName + INLINE_TRANSFORMATION_SUFFIX) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/BasicReplState.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/BasicReplState.kt index 16834b3c1c7..de787924bdd 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/BasicReplState.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/BasicReplState.kt @@ -61,13 +61,13 @@ open class BasicReplStageHistory(override val lock: ReentrantReadWriteLock = lock.write { val idx = indexOfFirst { it.id == id } if (idx < 0) throw java.util.NoSuchElementException("Cannot rest to inexistent line ${id.no}") - if (idx < lastIndex) { + return if (idx < lastIndex) { val removed = asSequence().drop(idx + 1).map { it.id }.toList() removeRange(idx + 1, size) currentGeneration.incrementAndGet() - return removed + removed } - else return emptyList() + else emptyList() } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ConstructorConsistencyChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ConstructorConsistencyChecker.kt index 000e76c1ac4..5ff0193fefb 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ConstructorConsistencyChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ConstructorConsistencyChecker.kt @@ -75,7 +75,7 @@ class ConstructorConsistencyChecker private constructor( return true } if (descriptor.containingDeclaration != classDescriptor) return true - if (insideLValue(reference)) return descriptor.setter?.isDefault != false else return descriptor.getter?.isDefault != false + return if (insideLValue(reference)) descriptor.setter?.isDefault != false else descriptor.getter?.isDefault != false } return true } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt index 2c5cd06c435..c18796a82d8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt @@ -1119,23 +1119,21 @@ class ControlFlowInformationProvider private constructor( } private fun combineKinds(kind: TailRecursionKind, existingKind: TailRecursionKind?): TailRecursionKind { - val resultingKind: TailRecursionKind - if (existingKind == null || existingKind == kind) { - resultingKind = kind + return if (existingKind == null || existingKind == kind) { + kind } else { if (check(kind, existingKind, IN_TRY, TAIL_CALL)) { - resultingKind = IN_TRY + IN_TRY } else if (check(kind, existingKind, IN_TRY, NON_TAIL)) { - resultingKind = IN_TRY + IN_TRY } else { // TAIL_CALL, NON_TAIL - resultingKind = NON_TAIL + NON_TAIL } } - return resultingKind } private fun check(a: Any, b: Any, x: Any, y: Any) = a === x && b === y || a === y && b === x diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt index 1f6e9bb1c9f..6d01ed4b077 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt @@ -518,13 +518,12 @@ class ControlFlowProcessor(private val trace: BindingTrace) { val incrementOrDecrement = isIncrementOrDecrement(operationType) val resolvedCall = expression.getResolvedCall(trace.bindingContext) - val rhsValue: PseudoValue? - if (resolvedCall != null) { - rhsValue = generateCall(resolvedCall).outputValue + val rhsValue: PseudoValue? = if (resolvedCall != null) { + generateCall(resolvedCall).outputValue } else { generateInstructions(baseExpression) - rhsValue = createNonSyntheticValue(expression, MagicKind.UNRESOLVED_CALL, baseExpression) + createNonSyntheticValue(expression, MagicKind.UNRESOLVED_CALL, baseExpression) } if (incrementOrDecrement) { @@ -866,12 +865,12 @@ class ControlFlowProcessor(private val trace: BindingTrace) { if (labelName != null) { val targetLabel = expression.getTargetLabel()!! val labeledElement = trace.get(BindingContext.LABEL_TARGET, targetLabel) - if (labeledElement is KtLoopExpression) { - loop = labeledElement + loop = if (labeledElement is KtLoopExpression) { + labeledElement } else { trace.report(NOT_A_LOOP_LABEL.on(expression, targetLabel.text)) - loop = null + null } } else { @@ -946,18 +945,18 @@ class ControlFlowProcessor(private val trace: BindingTrace) { val labelElement = expression.getTargetLabel() val subroutine: KtElement? val labelName = expression.getLabelName() - if (labelElement != null && labelName != null) { + subroutine = if (labelElement != null && labelName != null) { val labeledElement = trace.get(BindingContext.LABEL_TARGET, labelElement) if (labeledElement != null) { assert(labeledElement is KtElement) - subroutine = labeledElement as KtElement? + labeledElement as KtElement? } else { - subroutine = null + null } } else { - subroutine = builder.returnSubroutine + builder.returnSubroutine // TODO : a context check } @@ -1147,15 +1146,15 @@ class ControlFlowProcessor(private val trace: BindingTrace) { val resolvedCall = trace.get(BindingContext.COMPONENT_RESOLVED_CALL, entry) val writtenValue: PseudoValue? - if (resolvedCall != null) { - writtenValue = builder.call( + writtenValue = if (resolvedCall != null) { + builder.call( entry, resolvedCall, getReceiverValues(resolvedCall), emptyMap()).outputValue } else { - writtenValue = initializer?.let { createSyntheticValue(entry, MagicKind.UNRESOLVED_CALL, it) } + initializer?.let { createSyntheticValue(entry, MagicKind.UNRESOLVED_CALL, it) } } if (generateWriteForEntries) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/ControlFlowInstructionsGenerator.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/ControlFlowInstructionsGenerator.kt index e2cebacee90..3438fe7e598 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/ControlFlowInstructionsGenerator.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/ControlFlowInstructionsGenerator.kt @@ -56,11 +56,11 @@ class ControlFlowInstructionsGenerator : ControlFlowBuilderAdapter() { private fun popBuilder(): ControlFlowInstructionsGeneratorWorker { val worker = builders.pop() - if (!builders.isEmpty()) { - builder = builders.peek() + builder = if (!builders.isEmpty()) { + builders.peek() } else { - builder = null + null } return worker } @@ -400,13 +400,10 @@ class ControlFlowInstructionsGenerator : ControlFlowBuilderAdapter() { return magic(expression, expression, inputValues, getMagicKind(operation)) } - private fun getMagicKind(operation: ControlFlowBuilder.PredefinedOperation): MagicKind { - when (operation) { - ControlFlowBuilder.PredefinedOperation.AND -> return MagicKind.AND - ControlFlowBuilder.PredefinedOperation.OR -> return MagicKind.OR - ControlFlowBuilder.PredefinedOperation.NOT_NULL_ASSERTION -> return MagicKind.NOT_NULL_ASSERTION - else -> throw IllegalArgumentException("Invalid operation: " + operation) - } + private fun getMagicKind(operation: ControlFlowBuilder.PredefinedOperation) = when (operation) { + ControlFlowBuilder.PredefinedOperation.AND -> MagicKind.AND + ControlFlowBuilder.PredefinedOperation.OR -> MagicKind.OR + ControlFlowBuilder.PredefinedOperation.NOT_NULL_ASSERTION -> MagicKind.NOT_NULL_ASSERTION } override fun read( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt index 21a32109194..206190d43cf 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt @@ -68,11 +68,7 @@ private object PsiChildRangeArgumentType : PsiElementPlaceholderArgumentType createByPattern(pattern: String, vararg args: Any, re .sortedByDescending { it.startOffset } // reformat whole text except for String arguments (as they can contain user's formatting to be preserved) - if (stringPlaceholderRanges.none()) { - resultElement = codeStyleManager.reformat(resultElement, true) as TElement + resultElement = if (stringPlaceholderRanges.none()) { + codeStyleManager.reformat(resultElement, true) as TElement } else { var bound = resultElement.endOffset - 1 @@ -165,7 +165,7 @@ fun createByPattern(pattern: String, vararg args: Any, re resultElement = codeStyleManager.reformatRange(resultElement, range.endOffset + start, bound + 1, true) as TElement bound = range.startOffset + start } - resultElement = codeStyleManager.reformatRange(resultElement, start, bound + 1, true) as TElement + codeStyleManager.reformatRange(resultElement, start, bound + 1, true) as TElement } // do not reformat the whole expression in PostprocessReformattingAspect diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/CastDiagnosticsUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/CastDiagnosticsUtil.kt index d16097d4259..8db2ba9874a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/CastDiagnosticsUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/CastDiagnosticsUtil.kt @@ -164,18 +164,17 @@ object CastDiagnosticsUtil { val variables = subtypeWithVariables.constructor.parameters val variableConstructors = variables.map { descriptor -> descriptor.typeConstructor }.toSet() - val substitution: MutableMap - if (supertypeWithVariables != null) { + val substitution: MutableMap = if (supertypeWithVariables != null) { // Now, let's try to unify Collection and Collection solution is a map from T to Foo val solution = TypeUnifier.unify( TypeProjectionImpl(supertype), TypeProjectionImpl(supertypeWithVariables), variableConstructors::contains ) - substitution = Maps.newHashMap(solution.substitution) + Maps.newHashMap(solution.substitution) } else { // If there's no corresponding supertype, no variables are determined // This may be OK, e.g. in case 'Any as List<*>' - substitution = Maps.newHashMapWithExpectedSize(variables.size) + Maps.newHashMapWithExpectedSize(variables.size) } // If some of the parameters are not determined by unification, it means that these parameters are lost, diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstAndJvmFieldPropertiesLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstAndJvmFieldPropertiesLowering.kt index 5485481392a..2433ac494dc 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstAndJvmFieldPropertiesLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstAndJvmFieldPropertiesLowering.kt @@ -65,11 +65,11 @@ class ConstAndJvmFieldPropertiesLowering : IrElementTransformerVoid(), FileLower val property = descriptor.correspondingProperty if (JvmCodegenUtil.isConstOrHasJvmFieldAnnotation(property)) { - if (descriptor is PropertyGetterDescriptor) { - return substituteGetter(descriptor, expression) + return if (descriptor is PropertyGetterDescriptor) { + substituteGetter(descriptor, expression) } else { - return substituteSetter(descriptor, expression) + substituteSetter(descriptor, expression) } } else if (property is SyntheticJavaPropertyDescriptor) { diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BranchingExpressionGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BranchingExpressionGenerator.kt index 12d0052ebf9..e07abb25775 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BranchingExpressionGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BranchingExpressionGenerator.kt @@ -141,23 +141,23 @@ class BranchingExpressionGenerator(statementGenerator: StatementGenerator) : Sta } private fun generateWhenBody(expression: KtWhenExpression, irSubject: IrVariable?, irWhen: IrWhen): IrExpression { - if (irSubject == null) { + return if (irSubject == null) { if (irWhen.branches.isEmpty()) - return IrBlockImpl(expression.startOffset, expression.endOffset, context.builtIns.unitType, IrStatementOrigin.WHEN) + IrBlockImpl(expression.startOffset, expression.endOffset, context.builtIns.unitType, IrStatementOrigin.WHEN) else - return irWhen + irWhen } else { if (irWhen.branches.isEmpty()) { val irBlock = IrBlockImpl(expression.startOffset, expression.endOffset, context.builtIns.unitType, IrStatementOrigin.WHEN) irBlock.statements.add(irSubject) - return irBlock + irBlock } else { val irBlock = IrBlockImpl(expression.startOffset, expression.endOffset, irWhen.type, IrStatementOrigin.WHEN) irBlock.statements.add(irSubject) irBlock.statements.add(irWhen) - return irBlock + irBlock } } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/constantValues.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/constantValues.kt index 26c312f834a..3227bd87fce 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/constantValues.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/constantValues.kt @@ -101,16 +101,14 @@ class CharValue( override fun toString() = "\\u%04X ('%s')".format(value.toInt(), getPrintablePart(value)) - private fun getPrintablePart(c: Char): String { - when (c) { - '\b' -> return "\\b" - '\t' -> return "\\t" - '\n' -> return "\\n" - //TODO: KT-8507 - 12.toChar() -> return "\\f" - '\r' -> return "\\r" - else -> return if (isPrintableUnicode(c)) Character.toString(c) else "?" - } + private fun getPrintablePart(c: Char): String = when (c) { + '\b' -> "\\b" + '\t' -> "\\t" + '\n' -> "\\n" + //TODO: KT-8507 + 12.toChar() -> "\\f" + '\r' -> "\\r" + else -> if (isPrintableUnicode(c)) Character.toString(c) else "?" } private fun isPrintableUnicode(c: Char): Boolean { diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationDeserializer.kt index 0b923040031..1ba65480bc0 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationDeserializer.kt @@ -123,12 +123,12 @@ class AnnotationDeserializer(private val module: ModuleDescriptor, private val n else -> error("Unsupported annotation argument type: ${value.type} (expected $expectedType)") } - if (result.type.isSubtypeOf(expectedType)) { - return result + return if (result.type.isSubtypeOf(expectedType)) { + result } else { // This means that an annotation class has been changed incompatibly without recompiling clients - return factory.createErrorValue("Unexpected argument value") + factory.createErrorValue("Unexpected argument value") } } diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/CallType.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/CallType.kt index 1fef5aeb914..d2d9e9fdaa5 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/CallType.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/CallType.kt @@ -259,13 +259,13 @@ fun CallTypeAndReceiver<*, *>.receiverTypesWithIndex( is CallTypeAndReceiver.SUPER_MEMBERS -> { val qualifier = receiver.superTypeQualifier - if (qualifier != null) { - return listOfNotNull(bindingContext.getType(receiver)).map { ReceiverType(it, 0) } + return if (qualifier != null) { + listOfNotNull(bindingContext.getType(receiver)).map { ReceiverType(it, 0) } } else { val resolutionScope = contextElement.getResolutionScope(bindingContext, resolutionFacade) val classDescriptor = resolutionScope.ownerDescriptor.parentsWithSelf.firstIsInstanceOrNull() ?: return emptyList() - return classDescriptor.typeConstructor.supertypesWithAny().map { ReceiverType(it, 0) } + classDescriptor.typeConstructor.supertypesWithAny().map { ReceiverType(it, 0) } } } diff --git a/idea/idea-android/src/org/jetbrains/kotlin/android/AndroidUtil.kt b/idea/idea-android/src/org/jetbrains/kotlin/android/AndroidUtil.kt index 2765d06dfcf..47abad15d06 100644 --- a/idea/idea-android/src/org/jetbrains/kotlin/android/AndroidUtil.kt +++ b/idea/idea-android/src/org/jetbrains/kotlin/android/AndroidUtil.kt @@ -86,11 +86,11 @@ internal fun JavaPropertyDescriptor.getResourceReferenceType(): AndroidPsiUtils. val rClass = containingClass.containingDeclaration as? JavaClassDescriptor ?: return NONE if (R_CLASS == rClass.name.asString()) { - if ((rClass.containingDeclaration as? PackageFragmentDescriptor)?.fqName?.asString() == ANDROID_PKG) { - return FRAMEWORK + return if ((rClass.containingDeclaration as? PackageFragmentDescriptor)?.fqName?.asString() == ANDROID_PKG) { + FRAMEWORK } else { - return APP + APP } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt index 2709895596d..ca3cdbc2039 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt @@ -332,20 +332,20 @@ class BasicCompletionSession( if (callTypeAndReceiver.receiver == null && prefix.isNotEmpty()) { val classKindFilter: ((ClassKind) -> Boolean)? val includeTypeAliases: Boolean - when (callTypeAndReceiver) { + includeTypeAliases = when (callTypeAndReceiver) { is CallTypeAndReceiver.ANNOTATION -> { classKindFilter = { it == ClassKind.ANNOTATION_CLASS } - includeTypeAliases = true + true } is CallTypeAndReceiver.DEFAULT, is CallTypeAndReceiver.TYPE -> { classKindFilter = { it != ClassKind.ENUM_ENTRY } - includeTypeAliases = true + true } else -> { classKindFilter = null - includeTypeAliases = false + false } } @@ -728,24 +728,24 @@ class BasicCompletionSession( private fun referenceScope(declaration: KtNamedDeclaration): KtElement? { val parent = declaration.parent - when (parent) { - is KtParameterList -> return parent.parent as KtElement + return when (parent) { + is KtParameterList -> parent.parent as KtElement is KtClassBody -> { val classOrObject = parent.parent as KtClassOrObject if (classOrObject is KtObjectDeclaration && classOrObject.isCompanion()) { - return classOrObject.containingClassOrObject + classOrObject.containingClassOrObject } else { - return classOrObject + classOrObject } } - is KtFile -> return parent + is KtFile -> parent - is KtBlockExpression -> return parent + is KtBlockExpression -> parent - else -> return null + else -> null } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicLookupElementFactory.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicLookupElementFactory.kt index 5117684c45a..a60c04a8527 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicLookupElementFactory.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicLookupElementFactory.kt @@ -138,30 +138,32 @@ class BasicLookupElementFactory( } val lookupObject: DeclarationLookupObject - val name: String - if (descriptor is ConstructorDescriptor) { - // for constructor use name and icon of containing class - val classifierDescriptor = descriptor.containingDeclaration - lookupObject = object : DeclarationLookupObjectImpl(descriptor) { - override val psiElement by lazy { DescriptorToSourceUtilsIde.getAnyDeclaration(project, classifierDescriptor) } - override fun getIcon(flags: Int) = KotlinDescriptorIconProvider.getIcon(classifierDescriptor, psiElement, flags) + val name: String = when (descriptor) { + is ConstructorDescriptor -> { + // for constructor use name and icon of containing class + val classifierDescriptor = descriptor.containingDeclaration + lookupObject = object : DeclarationLookupObjectImpl(descriptor) { + override val psiElement by lazy { DescriptorToSourceUtilsIde.getAnyDeclaration(project, classifierDescriptor) } + override fun getIcon(flags: Int) = KotlinDescriptorIconProvider.getIcon(classifierDescriptor, psiElement, flags) + } + classifierDescriptor.name.asString() } - name = classifierDescriptor.name.asString() - } - else if (descriptor is SyntheticJavaPropertyDescriptor) { - lookupObject = object : DeclarationLookupObjectImpl(descriptor) { - override val psiElement by lazy { DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor.getMethod) } - override fun getIcon(flags: Int) = KotlinDescriptorIconProvider.getIcon(descriptor, null, flags) + is SyntheticJavaPropertyDescriptor -> { + lookupObject = object : DeclarationLookupObjectImpl(descriptor) { + override val psiElement by lazy { DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor.getMethod) } + override fun getIcon(flags: Int) = KotlinDescriptorIconProvider.getIcon(descriptor, null, flags) + } + descriptor.name.asString() } - name = descriptor.name.asString() - } - else { - lookupObject = object : DeclarationLookupObjectImpl(descriptor) { - override val psiElement: PsiElement? - get() = declarationLazy - override fun getIcon(flags: Int) = KotlinDescriptorIconProvider.getIcon(descriptor, psiElement, flags) + else -> { + lookupObject = object : DeclarationLookupObjectImpl(descriptor) { + override val psiElement: PsiElement? + get() = declarationLazy + + override fun getIcon(flags: Int) = KotlinDescriptorIconProvider.getIcon(descriptor, psiElement, flags) + } + descriptor.name.asString() } - name = descriptor.name.asString() } var element = LookupElementBuilder.create(lookupObject, name) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt index d7576a7b726..4c297476196 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt @@ -237,11 +237,11 @@ abstract class CompletionSession( sorter = sorter.weighAfter("stats", VariableOrFunctionWeigher, ImportedWeigher(importableFqNameClassifier)) val preferContextElementsWeigher = PreferContextElementsWeigher(inDescriptor) - if (callTypeAndReceiver is CallTypeAndReceiver.SUPER_MEMBERS) { // for completion after "super." strictly prefer the current member - sorter = sorter.weighBefore("kotlin.deprecated", preferContextElementsWeigher) + sorter = if (callTypeAndReceiver is CallTypeAndReceiver.SUPER_MEMBERS) { // for completion after "super." strictly prefer the current member + sorter.weighBefore("kotlin.deprecated", preferContextElementsWeigher) } else { - sorter = sorter.weighBefore("kotlin.proximity", preferContextElementsWeigher) + sorter.weighBefore("kotlin.proximity", preferContextElementsWeigher) } sorter = sorter.weighBefore("middleMatching", PreferMatchingItemWeigher) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt index ef97a97204f..9d53439eb5b 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt @@ -59,11 +59,11 @@ tailrec fun LookupElement.putUserDataDeep(key: Key, value: T?) { } tailrec fun LookupElement.getUserDataDeep(key: Key): T? { - if (this is LookupElementDecorator<*>) { - return getDelegate().getUserDataDeep(key) + return if (this is LookupElementDecorator<*>) { + getDelegate().getUserDataDeep(key) } else { - return getUserData(key) + getUserData(key) } } @@ -298,10 +298,10 @@ fun breakOrContinueExpressionItems(position: KtElement, breakOrContinue: String) fun BasicLookupElementFactory.createLookupElementForType(type: KotlinType): LookupElement? { if (type.isError) return null - if (type.isFunctionType) { + return if (type.isFunctionType) { val text = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(type) val baseLookupElement = LookupElementBuilder.create(text).withIcon(KotlinIcons.LAMBDA) - return BaseTypeLookupElement(type, baseLookupElement) + BaseTypeLookupElement(type, baseLookupElement) } else { val classifier = type.constructor.declarationDescriptor ?: return null @@ -317,7 +317,7 @@ fun BasicLookupElementFactory.createLookupElementForType(type: KotlinType): Look } // if type is simply classifier without anything else, use classifier's lookup element to avoid duplicates (works after "as" in basic completion) - return if (typeLookupElement.fullText == IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(classifier)) + if (typeLookupElement.fullText == IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(classifier)) baseLookupElement else typeLookupElement diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/console/CommandHistory.kt b/idea/idea-repl/src/org/jetbrains/kotlin/console/CommandHistory.kt index 87c111b5680..a7f0f11001f 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/console/CommandHistory.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/console/CommandHistory.kt @@ -38,11 +38,11 @@ class CommandHistory { } fun lastUnprocessedEntry(): CommandHistory.Entry? { - if (processedEntriesCount < size) { - return get(processedEntriesCount) + return if (processedEntriesCount < size) { + get(processedEntriesCount) } else { - return null + null } } diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/breakpointTypeUtils.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/breakpointTypeUtils.kt index 0706e5287a7..8286a753b68 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/breakpointTypeUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/breakpointTypeUtils.kt @@ -68,11 +68,11 @@ fun canPutAt(file: VirtualFile, line: Int, project: Project, breakpointTypeClass } if (element is KtProperty || element is KtParameter) { - if ((element is KtParameter && element.hasValOrVar()) || (element is KtProperty && !element.isLocal)) { - result = KotlinFieldBreakpointType::class.java + result = if ((element is KtParameter && element.hasValOrVar()) || (element is KtProperty && !element.isLocal)) { + KotlinFieldBreakpointType::class.java } else { - result = KotlinLineBreakpointType::class.java + KotlinLineBreakpointType::class.java } return false } diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeValInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeValInspection.kt index bf4fb20cfb3..0f309365b51 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeValInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeValInspection.kt @@ -76,11 +76,11 @@ class CanBeValInspection : AbstractKotlinInspection() { return false } - if (hasInitializerOrDelegate) { + return if (hasInitializerOrDelegate) { val hasWriteUsages = ReferencesSearch.search(declaration, declaration.useScope).any { (it as? KtSimpleNameReference)?.element?.readWriteAccess(useResolveForReadWrite = true)?.isWrite == true } - return !hasWriteUsages + !hasWriteUsages } else { val bindingContext = declaration.analyze(BodyResolveMode.FULL) @@ -90,7 +90,7 @@ class CanBeValInspection : AbstractKotlinInspection() { val writeInstructions = pseudocode.collectWriteInstructions(descriptor) if (writeInstructions.isEmpty()) return false // incorrect code - do not report - return writeInstructions.none { it.owner !== pseudocode || canReach(it, writeInstructions) } + writeInstructions.none { it.owner !== pseudocode || canReach(it, writeInstructions) } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt index 5b66d870098..8f350392a52 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt @@ -114,12 +114,12 @@ class ConflictingExtensionPropertyInspection : AbstractKotlinInspection(), Clean } private fun checkGetterBodyIsGetMethodCall(getter: KtPropertyAccessor, getMethod: FunctionDescriptor): Boolean { - if (getter.hasBlockBody()) { + return if (getter.hasBlockBody()) { val statement = (getter.bodyExpression as? KtBlockExpression)?.statements?.singleOrNull() ?: return false - return (statement as? KtReturnExpression)?.returnedExpression.isGetMethodCall(getMethod) + (statement as? KtReturnExpression)?.returnedExpression.isGetMethodCall(getMethod) } else { - return getter.bodyExpression.isGetMethodCall(getMethod) + getter.bodyExpression.isGetMethodCall(getMethod) } } @@ -134,20 +134,18 @@ class ConflictingExtensionPropertyInspection : AbstractKotlinInspection(), Clean } } - private fun KtExpression?.isGetMethodCall(getMethod: FunctionDescriptor): Boolean { - when (this) { - is KtCallExpression -> { - val resolvedCall = getResolvedCall(analyze()) - return resolvedCall != null && resolvedCall.isReallySuccess() && resolvedCall.resultingDescriptor.original == getMethod.original - } - - is KtQualifiedExpression -> { - val receiver = receiverExpression - return receiver is KtThisExpression && receiver.labelQualifier == null && selectorExpression.isGetMethodCall(getMethod) - } - - else -> return false + private fun KtExpression?.isGetMethodCall(getMethod: FunctionDescriptor): Boolean = when (this) { + is KtCallExpression -> { + val resolvedCall = getResolvedCall(analyze()) + resolvedCall != null && resolvedCall.isReallySuccess() && resolvedCall.resultingDescriptor.original == getMethod.original } + + is KtQualifiedExpression -> { + val receiver = receiverExpression + receiver is KtThisExpression && receiver.labelQualifier == null && selectorExpression.isGetMethodCall(getMethod) + } + + else -> false } private fun KtExpression?.isSetMethodCall(setMethod: FunctionDescriptor, valueParameterName: Name): Boolean { @@ -242,15 +240,15 @@ class ConflictingExtensionPropertyInspection : AbstractKotlinInspection(), Clean //TODO: move into PSI? private fun KtNamedDeclaration.addAnnotationWithLineBreak(annotationEntry: KtAnnotationEntry): KtAnnotationEntry { val newLine = KtPsiFactory(this).createNewLine() - if (modifierList != null) { + return if (modifierList != null) { val result = addAnnotationEntry(annotationEntry) modifierList!!.addAfter(newLine, result) - return result + result } else { val result = addAnnotationEntry(annotationEntry) addAfter(newLine, modifierList) - return result + result } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt index f53a7499f86..9d99829341b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt @@ -28,18 +28,18 @@ class AddBracesIntention : SelfTargetingIntention(KtElement::class.ja if (expression is KtBlockExpression) return false val parent = expression.parent - when (parent) { + return when (parent) { is KtContainerNode -> { val description = parent.description()!! text = "Add braces to '$description' statement" - return true + true } is KtWhenEntry -> { text = "Add braces to 'when' entry" - return true + true } else -> { - return false + false } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertBinaryExpressionWithDemorgansLawIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertBinaryExpressionWithDemorgansLawIntention.kt index 5e75ba96815..813601d682b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertBinaryExpressionWithDemorgansLawIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertBinaryExpressionWithDemorgansLawIntention.kt @@ -26,9 +26,9 @@ class ConvertBinaryExpressionWithDemorgansLawIntention : SelfTargetingOffsetInde override fun isApplicableTo(element: KtBinaryExpression): Boolean { val expr = element.parentsWithSelf.takeWhile { it is KtBinaryExpression }.last() as KtBinaryExpression - when (expr.operationToken) { - KtTokens.ANDAND -> text = "Replace '&&' with '||'" - KtTokens.OROR -> text = "Replace '||' with '&&'" + text = when (expr.operationToken) { + KtTokens.ANDAND -> "Replace '&&' with '||'" + KtTokens.OROR -> "Replace '||' with '&&'" else -> return false } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt index fc9d4df2418..2d23ea5342c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt @@ -28,10 +28,10 @@ class ConvertPropertyInitializerToGetterIntention : SelfTargetingRangeIntention< override fun applicabilityRange(element: KtProperty): TextRange? { val initializer = element.initializer - if (initializer != null && element.getter == null && !element.isExtensionDeclaration() && !element.isLocal) - return initializer.textRange + return if (initializer != null && element.getter == null && !element.isExtensionDeclaration() && !element.isLocal) + initializer.textRange else - return null + null } override fun allowCaretInsideElement(element: PsiElement): Boolean { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt index 1af13f92f91..bcd5b25c916 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt @@ -65,13 +65,13 @@ open class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentInte private fun fold(left: KtExpression?, right: String, factory: KtPsiFactory): KtStringTemplateExpression { val forceBraces = !right.isEmpty() && right.first() != '$' && right.first().isJavaIdentifierPart() - if (left is KtBinaryExpression && isApplicableToNoParentCheck(left)) { + return if (left is KtBinaryExpression && isApplicableToNoParentCheck(left)) { val leftRight = buildText(left.right, forceBraces) - return fold(left.left, leftRight + right, factory) + fold(left.left, leftRight + right, factory) } else { val leftText = buildText(left, forceBraces) - return factory.createExpression("\"$leftText$right\"") as KtStringTemplateExpression + factory.createExpression("\"$leftText$right\"") as KtStringTemplateExpression } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/branchedTransformationUtils.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/branchedTransformationUtils.kt index 51bd8296de9..6f6683c43d8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/branchedTransformationUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/branchedTransformationUtils.kt @@ -24,19 +24,19 @@ import org.jetbrains.kotlin.psi.* fun KtWhenCondition.toExpression(subject: KtExpression?): KtExpression { val factory = KtPsiFactory(this) - when (this) { + return when (this) { is KtWhenConditionIsPattern -> { val op = if (isNegated) "!is" else "is" - return factory.createExpressionByPattern("$0 $op $1", subject ?: "_", typeReference ?: "") + factory.createExpressionByPattern("$0 $op $1", subject ?: "_", typeReference ?: "") } is KtWhenConditionInRange -> { val op = operationReference.text - return factory.createExpressionByPattern("$0 $op $1", subject ?: "_", rangeExpression ?: "") + factory.createExpressionByPattern("$0 $op $1", subject ?: "_", rangeExpression ?: "") } is KtWhenConditionWithExpression -> { - return if (subject != null) { + if (subject != null) { factory.createExpressionByPattern("$0 == $1", subject, expression ?: "") } else { @@ -165,14 +165,10 @@ private fun BuilderByPattern.appendConditionWithSubjectRemoved(con } } -fun KtPsiFactory.combineWhenConditions(conditions: Array, subject: KtExpression?): KtExpression? { - when (conditions.size) { - 0 -> return null - 1 -> return conditions[0].toExpression(subject) - else -> { - return buildExpression { - appendExpressions(conditions.map { it.toExpression(subject) }, separator = "||") - } - } +fun KtPsiFactory.combineWhenConditions(conditions: Array, subject: KtExpression?) = when (conditions.size) { + 0 -> null + 1 -> conditions[0].toExpression(subject) + else -> buildExpression { + appendExpressions(conditions.map { it.toExpression(subject) }, separator = "||") } } \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/baseTransformations.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/baseTransformations.kt index 577b372ce80..6aed059b9fb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/baseTransformations.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/baseTransformations.kt @@ -58,7 +58,7 @@ abstract class AssignToVariableResultTransformation( override fun generateExpressionToReplaceLoopAndCheckErrors(resultCallChain: KtExpression): KtExpression { val psiFactory = KtPsiFactory(resultCallChain) val initializationStatement = initialization.initializationStatement - if (initializationStatement is KtVariableDeclaration) { + return if (initializationStatement is KtVariableDeclaration) { val resolutionScope = loop.getResolutionScope() fun isUniqueName(name: String): Boolean { @@ -73,10 +73,10 @@ abstract class AssignToVariableResultTransformation( val copy = initializationStatement.copied() copy.initializer!!.replace(resultCallChain) copy.setName(uniqueName) - return copy + copy } else { - return psiFactory.createExpressionByPattern("$0 = $1", initialization.variable.nameAsSafeName, resultCallChain) + psiFactory.createExpressionByPattern("$0 = $1", initialization.variable.nameAsSafeName, resultCallChain) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/commonUtils.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/commonUtils.kt index 93235ecd331..39b35f6579b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/commonUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/commonUtils.kt @@ -135,12 +135,12 @@ fun KtCallableDeclaration.hasDifferentSetsOfUsages(elements1: Collection() + return if (label == null) { + parents.firstIsInstance() } else { //TODO: does PARTIAL always work here? - return analyze(BodyResolveMode.PARTIAL)[BindingContext.LABEL_TARGET, label] as? KtLoopExpression + analyze(BodyResolveMode.PARTIAL)[BindingContext.LABEL_TARGET, label] as? KtLoopExpression } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/AddToCollectionTransformation.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/AddToCollectionTransformation.kt index afaf78568ce..e73d634350e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/AddToCollectionTransformation.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/AddToCollectionTransformation.kt @@ -105,12 +105,12 @@ class AddToCollectionTransformation( ?.let { return it } } - if (state.indexVariable == null && argumentValue.isVariableReference(state.inputVariable)) { - return TransformationMatch.Result(AddToCollectionTransformation(state.outerLoop, targetCollection)) + return if (state.indexVariable == null && argumentValue.isVariableReference(state.inputVariable)) { + TransformationMatch.Result(AddToCollectionTransformation(state.outerLoop, targetCollection)) } else { //TODO: recognize "?: continue" in the argument - return TransformationMatch.Result(MapToTransformation.create( + TransformationMatch.Result(MapToTransformation.create( state.outerLoop, state.inputVariable, state.indexVariable, targetCollection, argumentValue, mapNotNull = false)) } } @@ -127,19 +127,19 @@ class AddToCollectionTransformation( CollectionKind.LIST -> { when { canChangeInitializerType(collectionInitialization, KotlinBuiltIns.FQ_NAMES.list, state.outerLoop) -> { - if (argumentIsInputVariable) { + return if (argumentIsInputVariable) { val assignToList = AssignToListTransformation(state.outerLoop, collectionInitialization, state.lazySequence) - return TransformationMatch.Result(assignToList) + TransformationMatch.Result(assignToList) } else { val mapTransformation = MapTransformation(state.outerLoop, state.inputVariable, null, addOperationArgument, mapNotNull = false) if (state.lazySequence) { val assignToList = AssignToListTransformation(state.outerLoop, collectionInitialization, lazySequence = true) - return TransformationMatch.Result(assignToList, mapTransformation) + TransformationMatch.Result(assignToList, mapTransformation) } else { val assignSequence = AssignSequenceResultTransformation(mapTransformation, collectionInitialization) - return TransformationMatch.Result(assignSequence) + TransformationMatch.Result(assignSequence) } } } @@ -166,12 +166,12 @@ class AddToCollectionTransformation( else -> return null } - if (argumentIsInputVariable) { - return TransformationMatch.Result(assignToSetTransformation) + return if (argumentIsInputVariable) { + TransformationMatch.Result(assignToSetTransformation) } else { val mapTransformation = MapTransformation(state.outerLoop, state.inputVariable, null, addOperationArgument, mapNotNull = false) - return TransformationMatch.Result(assignToSetTransformation, mapTransformation) + TransformationMatch.Result(assignToSetTransformation, mapTransformation) } } } @@ -236,12 +236,12 @@ class FilterToTransformation private constructor( isFilterNot: Boolean ): ResultTransformation { val initialization = targetCollection.findVariableInitializationBeforeLoop(loop, checkNoOtherUsagesInLoop = true) - if (initialization != null && initialization.initializer.hasNoSideEffect()) { + return if (initialization != null && initialization.initializer.hasNoSideEffect()) { val transformation = FilterToTransformation(loop, inputVariable, indexVariable, initialization.initializer, condition, isFilterNot) - return AssignToVariableResultTransformation.createDelegated(transformation, initialization) + AssignToVariableResultTransformation.createDelegated(transformation, initialization) } else { - return FilterToTransformation(loop, inputVariable, indexVariable, targetCollection, condition, isFilterNot) + FilterToTransformation(loop, inputVariable, indexVariable, targetCollection, condition, isFilterNot) } } } @@ -265,12 +265,12 @@ class FilterNotNullToTransformation private constructor( targetCollection: KtExpression ): ResultTransformation { val initialization = targetCollection.findVariableInitializationBeforeLoop(loop, checkNoOtherUsagesInLoop = true) - if (initialization != null && initialization.initializer.hasNoSideEffect()) { + return if (initialization != null && initialization.initializer.hasNoSideEffect()) { val transformation = FilterNotNullToTransformation(loop, initialization.initializer) - return AssignToVariableResultTransformation.createDelegated(transformation, initialization) + AssignToVariableResultTransformation.createDelegated(transformation, initialization) } else { - return FilterNotNullToTransformation(loop, targetCollection) + FilterNotNullToTransformation(loop, targetCollection) } } } @@ -308,12 +308,12 @@ class MapToTransformation private constructor( mapNotNull: Boolean ): ResultTransformation { val initialization = targetCollection.findVariableInitializationBeforeLoop(loop, checkNoOtherUsagesInLoop = true) - if (initialization != null && initialization.initializer.hasNoSideEffect()) { + return if (initialization != null && initialization.initializer.hasNoSideEffect()) { val transformation = MapToTransformation(loop, inputVariable, indexVariable, initialization.initializer, mapping, mapNotNull) - return AssignToVariableResultTransformation.createDelegated(transformation, initialization) + AssignToVariableResultTransformation.createDelegated(transformation, initialization) } else { - return MapToTransformation(loop, inputVariable, indexVariable, targetCollection, mapping, mapNotNull) + MapToTransformation(loop, inputVariable, indexVariable, targetCollection, mapping, mapNotNull) } } } @@ -347,12 +347,12 @@ class FlatMapToTransformation private constructor( transform: KtExpression ): ResultTransformation { val initialization = targetCollection.findVariableInitializationBeforeLoop(loop, checkNoOtherUsagesInLoop = true) - if (initialization != null && initialization.initializer.hasNoSideEffect()) { + return if (initialization != null && initialization.initializer.hasNoSideEffect()) { val transformation = FlatMapToTransformation(loop, inputVariable, initialization.initializer, transform) - return AssignToVariableResultTransformation.createDelegated(transformation, initialization) + AssignToVariableResultTransformation.createDelegated(transformation, initialization) } else { - return FlatMapToTransformation(loop, inputVariable, targetCollection, transform) + FlatMapToTransformation(loop, inputVariable, targetCollection, transform) } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/CountTransformation.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/CountTransformation.kt index a26069259dc..f5c77413172 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/CountTransformation.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/CountTransformation.kt @@ -52,11 +52,11 @@ class CountTransformation( chainedCallGenerator.generate("count()") } - 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/quickfix/AddFunctionToSupertypeFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionToSupertypeFix.kt index 0934a8b3a06..7e1daf0bb28 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionToSupertypeFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionToSupertypeFix.kt @@ -139,7 +139,7 @@ class AddFunctionToSupertypeFix private constructor( var sourceCode = IdeDescriptorRenderers.SOURCE_CODE.render(functionDescriptor) if (classDescriptor.kind != ClassKind.INTERFACE && functionDescriptor.modality != Modality.ABSTRACT) { val returnType = functionDescriptor.returnType - if (returnType == null || !KotlinBuiltIns.isUnit(returnType)) { + sourceCode += if (returnType == null || !KotlinBuiltIns.isUnit(returnType)) { val bodyText = getFunctionBodyTextFromTemplate( project, TemplateKind.FUNCTION, @@ -147,10 +147,10 @@ class AddFunctionToSupertypeFix private constructor( functionDescriptor.returnType?.let { IdeDescriptorRenderers.SOURCE_CODE.renderType(it) } ?: "Unit", classDescriptor.importableFqName ) - sourceCode += "{ $bodyText }" + "{ $bodyText }" } else { - sourceCode += "{}" + "{}" } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeCallableReturnTypeFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeCallableReturnTypeFix.kt index 1b1b2f779d2..1cc3e5dc95c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeCallableReturnTypeFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeCallableReturnTypeFix.kt @@ -61,12 +61,12 @@ abstract class ChangeCallableReturnTypeFix( private val isUnitType = type.isUnit() init { - if (element is KtFunctionLiteral) { + changeFunctionLiteralReturnTypeFix = if (element is KtFunctionLiteral) { val functionLiteralExpression = PsiTreeUtil.getParentOfType(element, KtLambdaExpression::class.java) ?: error("FunctionLiteral outside any FunctionLiteralExpression: " + element.getElementTextWithContext()) - changeFunctionLiteralReturnTypeFix = ChangeFunctionLiteralReturnTypeFix(functionLiteralExpression, type) + ChangeFunctionLiteralReturnTypeFix(functionLiteralExpression, type) } else { - changeFunctionLiteralReturnTypeFix = null + null } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionSignatureFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionSignatureFix.kt index 57104e9e5ae..45b6975c602 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionSignatureFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionSignatureFix.kt @@ -63,15 +63,15 @@ abstract class ChangeFunctionSignatureFix( val argumentName = argument.getArgumentName() val expression = argument.getArgumentExpression() - if (argumentName != null) { - return KotlinNameSuggester.suggestNameByName(argumentName.asName.asString(), validator) + return if (argumentName != null) { + KotlinNameSuggester.suggestNameByName(argumentName.asName.asString(), validator) } else if (expression != null) { val bindingContext = expression.analyze(BodyResolveMode.PARTIAL) - return KotlinNameSuggester.suggestNamesByExpressionAndType(expression, null, bindingContext, validator, "param").first() + KotlinNameSuggester.suggestNamesByExpressionAndType(expression, null, bindingContext, validator, "param").first() } else { - return KotlinNameSuggester.suggestNameByName("param", validator) + KotlinNameSuggester.suggestNameByName("param", validator) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeMemberFunctionSignatureFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeMemberFunctionSignatureFix.kt index 4a7cc63cfe0..bc188e0d499 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeMemberFunctionSignatureFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeMemberFunctionSignatureFix.kt @@ -260,11 +260,11 @@ class ChangeMemberFunctionSignatureFix private constructor( object MatchTypes : ParameterChooser { override fun choose(parameter: ValueParameterDescriptor, superParameter: ValueParameterDescriptor): ValueParameterDescriptor? { // TODO: support for generic functions - if (KotlinTypeChecker.DEFAULT.equalTypes(parameter.type, superParameter.type)) { - return superParameter.copy(parameter.containingDeclaration, parameter.name, parameter.index) + return if (KotlinTypeChecker.DEFAULT.equalTypes(parameter.type, superParameter.type)) { + superParameter.copy(parameter.containingDeclaration, parameter.name, parameter.index) } else { - return null + null } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableTypeFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableTypeFix.kt index f33f605d757..ae8839fd186 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableTypeFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableTypeFix.kt @@ -48,13 +48,13 @@ open class ChangeVariableTypeFix(element: KtVariableDeclaration, type: KotlinTyp open fun variablePresentation(): String? { val element = element!! val name = element.name - if (name != null) { + return if (name != null) { val container = element.resolveToDescriptor().containingDeclaration as? ClassDescriptor val containerName = container?.name?.takeUnless { it.isSpecial }?.asString() - return if (containerName != null) "'$containerName.$name'" else "'$name'" + if (containerName != null) "'$containerName.$name'" else "'$name'" } else { - return null + null } } @@ -62,11 +62,11 @@ open class ChangeVariableTypeFix(element: KtVariableDeclaration, type: KotlinTyp if (element == null) return "" val variablePresentation = variablePresentation() - if (variablePresentation != null) { - return "Change type of $variablePresentation to '$typePresentation'" + return if (variablePresentation != null) { + "Change type of $variablePresentation to '$typePresentation'" } else { - return "Change type to '$typePresentation'" + "Change type to '$typePresentation'" } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt index 58892db63ed..a7941ceb295 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt @@ -254,15 +254,15 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { NavigationUtil.activateFileWithPsiElement(containingElement) } - if (containingElement is KtElement) { + dialogWithEditor = if (containingElement is KtElement) { jetFileToEdit = containingElement.containingKtFile - if (jetFileToEdit != config.currentFile) { - containingFileEditor = FileEditorManager.getInstance(project).selectedTextEditor!! + containingFileEditor = if (jetFileToEdit != config.currentFile) { + FileEditorManager.getInstance(project).selectedTextEditor!! } else { - containingFileEditor = config.currentEditor!! + config.currentEditor!! } - dialogWithEditor = null + null } else { val dialog = object: DialogWithEditor(project, "Create from usage", "") { override fun doOKAction() { @@ -279,7 +279,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { } jetFileToEdit = PsiDocumentManager.getInstance(project).getPsiFile(containingFileEditor.document) as KtFile jetFileToEdit.analysisContext = config.currentFile - dialogWithEditor = dialog + dialog } val scope = getDeclarationScope() @@ -645,15 +645,14 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { if (candidates.isEmpty()) return null val elementToReplace: KtElement? - val expression: TypeExpression - when (declaration) { + val expression: TypeExpression = when (declaration) { is KtCallableDeclaration -> { elementToReplace = declaration.typeReference - expression = TypeExpression.ForTypeReference(candidates) + TypeExpression.ForTypeReference(candidates) } is KtClassOrObject -> { elementToReplace = declaration.superTypeListEntries.firstOrNull() - expression = TypeExpression.ForDelegationSpecifier(candidates) + TypeExpression.ForDelegationSpecifier(candidates) } else -> throw AssertionError("Unexpected declaration kind: ${declaration.text}") } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createTypeParameter/CreateTypeParameterFromUsageFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createTypeParameter/CreateTypeParameterFromUsageFix.kt index cf25c8545a7..5fecbf9dae8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createTypeParameter/CreateTypeParameterFromUsageFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createTypeParameter/CreateTypeParameterFromUsageFix.kt @@ -139,7 +139,7 @@ class CreateTypeParameterFromUsageFix( callsToExplicateArguments.forEach { val typeArgumentList = it.typeArgumentList - if (typeArgumentList == null) { + elementsToShorten += if (typeArgumentList == null) { InsertExplicitTypeArgumentsIntention.applyTo(it, shortenReferences = false) val newTypeArgument = it.typeArguments.lastOrNull() @@ -147,10 +147,10 @@ class CreateTypeParameterFromUsageFix( newTypeArgument.replaced(anonymizedUpperBoundAsTypeArg) } - elementsToShorten += it.typeArgumentList + it.typeArgumentList } else { - elementsToShorten += typeArgumentList.addArgument(anonymizedUpperBoundAsTypeArg) + typeArgumentList.addArgument(anonymizedUpperBoundAsTypeArg) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/CallableRefactoring.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/CallableRefactoring.kt index f4c7119430e..efa2f406d3b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/CallableRefactoring.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/CallableRefactoring.kt @@ -121,11 +121,11 @@ abstract class CallableRefactoring( } fun buildDialogOptions(isSingleFunctionSelected: Boolean): List { - if (isSingleFunctionSelected) { - return arrayListOf(Messages.YES_BUTTON, Messages.NO_BUTTON, Messages.CANCEL_BUTTON) + return if (isSingleFunctionSelected) { + arrayListOf(Messages.YES_BUTTON, Messages.NO_BUTTON, Messages.CANCEL_BUTTON) } else { - return arrayListOf(Messages.OK_BUTTON, Messages.CANCEL_BUTTON) + arrayListOf(Messages.OK_BUTTON, Messages.CANCEL_BUTTON) } } @@ -185,14 +185,14 @@ fun getAffectedCallables(project: Project, descriptorsForChange: Collection containingDescriptor.scopeForInitializerResolution is PackageFragmentDescriptor -> LexicalScope.Base(containingDescriptor.getMemberScope().memberScopeAsImportingScope(), this) else -> null diff --git a/j2k/src/org/jetbrains/kotlin/j2k/AnnotationConverter.kt b/j2k/src/org/jetbrains/kotlin/j2k/AnnotationConverter.kt index eeebf82a0c4..92f888b6a41 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/AnnotationConverter.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/AnnotationConverter.kt @@ -129,18 +129,17 @@ class AnnotationConverter(private val converter: Converter) { } if (qualifiedName == CommonClassNames.JAVA_LANG_ANNOTATION_TARGET) { val attributes = annotation.parameterList.attributes - val arguments: Set - if (attributes.isEmpty()) { - arguments = setOf() + val arguments: Set = if (attributes.isEmpty()) { + setOf() } else { val value = attributes[0].value - arguments = when (value) { + when (value) { is PsiArrayInitializerMemberValue -> value.initializers.filterIsInstance() .flatMap { mapTargetByName(it) } .toSet() is PsiReferenceExpression -> mapTargetByName(value) - else -> setOf() + else -> setOf() } } val deferredExpressionList = arguments.map { diff --git a/j2k/src/org/jetbrains/kotlin/j2k/ClassBodyConverter.kt b/j2k/src/org/jetbrains/kotlin/j2k/ClassBodyConverter.kt index c45ec06b4aa..def3cb485b0 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/ClassBodyConverter.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/ClassBodyConverter.kt @@ -184,11 +184,11 @@ class ClassBodyConverter(private val psiClass: PsiClass, val members = convertedMembers.keys.filter { !it.isConstructor() } val companionObjectMembers = members.filter { it !is PsiClass && it !is PsiEnumConstant && it.hasModifierProperty(PsiModifier.STATIC) } val nestedClasses = members.filterIsInstance().filter { it.hasModifierProperty(PsiModifier.STATIC) } - if (companionObjectMembers.all { it is PsiMethod && it.hasModifierProperty(PsiModifier.PRIVATE) }) { - return nestedClasses.any { nestedClass -> companionObjectMembers.any { converter.referenceSearcher.findMethodCalls(it as PsiMethod, nestedClass).isNotEmpty() } } + return if (companionObjectMembers.all { it is PsiMethod && it.hasModifierProperty(PsiModifier.PRIVATE) }) { + nestedClasses.any { nestedClass -> companionObjectMembers.any { converter.referenceSearcher.findMethodCalls(it as PsiMethod, nestedClass).isNotEmpty() } } } else { - return true + true } } } diff --git a/j2k/src/org/jetbrains/kotlin/j2k/CodeBuilder.kt b/j2k/src/org/jetbrains/kotlin/j2k/CodeBuilder.kt index 7c44d99e7e6..d61b871ebad 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/CodeBuilder.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/CodeBuilder.kt @@ -340,16 +340,16 @@ class CodeBuilder(private val topElement: PsiElement?, private var docConverter: private companion object { operator fun List.plus(other: List): List { - when { - isEmpty() -> return other + return when { + isEmpty() -> other - other.isEmpty() -> return this + other.isEmpty() -> this else -> { val result = ArrayList(size + other.size) result.addAll(this) result.addAll(other) - return result + result } } } diff --git a/j2k/src/org/jetbrains/kotlin/j2k/ConstructorConverter.kt b/j2k/src/org/jetbrains/kotlin/j2k/ConstructorConverter.kt index 69962635e26..e75dd1cd413 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/ConstructorConverter.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/ConstructorConverter.kt @@ -178,13 +178,13 @@ class ConstructorConverter( val statement = primaryConstructor.body?.statements?.firstOrNull() val methodCall = (statement as? PsiExpressionStatement)?.expression as? PsiMethodCallExpression - if (methodCall != null && methodCall.isSuperConstructorCall()) { - baseClassParams = methodCall.argumentList.expressions.map { + baseClassParams = if (methodCall != null && methodCall.isSuperConstructorCall()) { + methodCall.argumentList.expressions.map { converter.deferredElement { codeConverter -> codeConverter.correct().convertExpression(it) } } } else { - baseClassParams = emptyList() + emptyList() } val parameterList = converter.convertParameterList( diff --git a/j2k/src/org/jetbrains/kotlin/j2k/Converter.kt b/j2k/src/org/jetbrains/kotlin/j2k/Converter.kt index a628fc7f87f..41b5180e64c 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/Converter.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/Converter.kt @@ -365,10 +365,10 @@ class Converter private constructor( if (propertyInfo.needExplicitGetter) { if (getMethod != null) { val method = convertMethod(getMethod, null, null, null, classKind)!! - if (method.modifiers.contains(Modifier.EXTERNAL)) - getter = PropertyAccessor(AccessorKind.GETTER, method.annotations, Modifiers(listOf(Modifier.EXTERNAL)).assignNoPrototype(), null, null) + getter = if (method.modifiers.contains(Modifier.EXTERNAL)) + PropertyAccessor(AccessorKind.GETTER, method.annotations, Modifiers(listOf(Modifier.EXTERNAL)).assignNoPrototype(), null, null) else - getter = PropertyAccessor(AccessorKind.GETTER, method.annotations, Modifiers.Empty, method.parameterList, method.body) + PropertyAccessor(AccessorKind.GETTER, method.annotations, Modifiers.Empty, method.parameterList, method.body) getter.assignPrototype(getMethod, CommentsAndSpacesInheritance.NO_SPACES) } else if (propertyInfo.modifiers.contains(Modifier.OVERRIDE) && !(propertyInfo.superInfo?.isAbstract() ?: false)) { @@ -391,8 +391,8 @@ class Converter private constructor( val accessorModifiers = Modifiers(listOfNotNull(propertyInfo.specialSetterAccess)).assignNoPrototype() if (setMethod != null && !propertyInfo.isSetMethodBodyFieldAccess) { val method = convertMethod(setMethod, null, null, null, classKind)!! - if (method.modifiers.contains(Modifier.EXTERNAL)) - setter = PropertyAccessor(AccessorKind.SETTER, method.annotations, accessorModifiers.with(Modifier.EXTERNAL), null, null) + setter = if (method.modifiers.contains(Modifier.EXTERNAL)) + PropertyAccessor(AccessorKind.SETTER, method.annotations, accessorModifiers.with(Modifier.EXTERNAL), null, null) else { val convertedParameter = method.parameterList!!.parameters.single() as FunctionParameter val parameterAnnotations = convertedParameter.annotations @@ -404,7 +404,7 @@ class Converter private constructor( else { null } - setter = PropertyAccessor(AccessorKind.SETTER, method.annotations, accessorModifiers, parameterList, method.body) + PropertyAccessor(AccessorKind.SETTER, method.annotations, accessorModifiers, parameterList, method.body) } setter.assignPrototype(setMethod, CommentsAndSpacesInheritance.NO_SPACES) } @@ -648,13 +648,13 @@ class Converter private constructor( private fun needOpenModifier(method: PsiMethod, isInOpenClass: Boolean, modifiers: Modifiers): Boolean { if (!isInOpenClass) return false if (modifiers.contains(Modifier.OVERRIDE) || modifiers.contains(Modifier.ABSTRACT)) return false - if (settings.openByDefault) { - return !method.hasModifierProperty(PsiModifier.FINAL) - && !method.hasModifierProperty(PsiModifier.PRIVATE) - && !method.hasModifierProperty(PsiModifier.STATIC) + return if (settings.openByDefault) { + !method.hasModifierProperty(PsiModifier.FINAL) + && !method.hasModifierProperty(PsiModifier.PRIVATE) + && !method.hasModifierProperty(PsiModifier.STATIC) } else { - return referenceSearcher.hasOverrides(method) + referenceSearcher.hasOverrides(method) } } @@ -667,7 +667,7 @@ class Converter private constructor( ?.let { return ReferenceElement(it, typeArgs).assignNoPrototype() } } - if (element.isQualified) { + return if (element.isQualified) { var result = Identifier.toKotlin(element.referenceName!!) var qualifier = element.qualifier while (qualifier != null) { @@ -675,7 +675,7 @@ class Converter private constructor( result = Identifier.toKotlin(codeRefElement.referenceName!!) + "." + result qualifier = codeRefElement.qualifier } - return ReferenceElement(Identifier.withNoPrototype(result), typeArgs).assignPrototype(element, CommentsAndSpacesInheritance.NO_SPACES) + ReferenceElement(Identifier.withNoPrototype(result), typeArgs).assignPrototype(element, CommentsAndSpacesInheritance.NO_SPACES) } else { if (!hasExternalQualifier) { @@ -688,7 +688,7 @@ class Converter private constructor( } } - return ReferenceElement(Identifier.withNoPrototype(element.referenceName!!), typeArgs).assignPrototype(element, CommentsAndSpacesInheritance.NO_SPACES) + ReferenceElement(Identifier.withNoPrototype(element.referenceName!!), typeArgs).assignPrototype(element, CommentsAndSpacesInheritance.NO_SPACES) } } diff --git a/j2k/src/org/jetbrains/kotlin/j2k/usageProcessing/AccessorToPropertyProcessing.kt b/j2k/src/org/jetbrains/kotlin/j2k/usageProcessing/AccessorToPropertyProcessing.kt index 39be60e8c9d..cf28bd773ff 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/usageProcessing/AccessorToPropertyProcessing.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/usageProcessing/AccessorToPropertyProcessing.kt @@ -80,16 +80,16 @@ class AccessorToPropertyProcessing(val accessorMethod: PsiMethod, val accessorKi assignment.right!!.replace(value) val qualifiedExpression = callExpr.parent as? KtQualifiedExpression - if (qualifiedExpression != null && qualifiedExpression.selectorExpression == callExpr) { + return if (qualifiedExpression != null && qualifiedExpression.selectorExpression == callExpr) { callExpr.replace(propertyNameExpr) assignment.left!!.replace(qualifiedExpression) assignment = qualifiedExpression.replace(assignment) as KtBinaryExpression - return (assignment.left as KtQualifiedExpression).selectorExpression!!.references + (assignment.left as KtQualifiedExpression).selectorExpression!!.references } else { assignment.left!!.replace(propertyNameExpr) assignment = callExpr.replace(assignment) as KtBinaryExpression - return assignment.left!!.references + assignment.left!!.references } } diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/descriptorUtils/descriptorUtils.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/descriptorUtils/descriptorUtils.kt index 59693f96a05..256c578d794 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/descriptorUtils/descriptorUtils.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/descriptorUtils/descriptorUtils.kt @@ -36,15 +36,13 @@ fun KotlinType.getJetTypeFqName(printTypeArguments: Boolean): String { } val typeArguments = arguments - val typeArgumentsAsString: String - - if (printTypeArguments && !typeArguments.isEmpty()) { + val typeArgumentsAsString = if (printTypeArguments && !typeArguments.isEmpty()) { val joinedTypeArguments = StringUtil.join(typeArguments, { projection -> projection.type.getJetTypeFqName(false) }, ", ") - typeArgumentsAsString = "<$joinedTypeArguments>" + "<$joinedTypeArguments>" } else { - typeArgumentsAsString = "" + "" } return DescriptorUtils.getFqName(declaration).asString() + typeArgumentsAsString diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallInfo.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallInfo.kt index 368c0f3324f..fa72d6e3ad7 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallInfo.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallInfo.kt @@ -175,12 +175,12 @@ private fun TranslationContext.createCallInfo( val notNullConditionalForSafeCall: JsConditional? = notNullConditional override fun constructSafeCallIfNeeded(result: JsExpression): JsExpression { - if (notNullConditionalForSafeCall == null) { - return result + return if (notNullConditionalForSafeCall == null) { + result } else { notNullConditionalForSafeCall.thenExpression = result - return notNullConditionalForSafeCall + notNullConditionalForSafeCall } } } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallInfoExtensions.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallInfoExtensions.kt index 07a2de58c9a..646b0abc47c 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallInfoExtensions.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallInfoExtensions.kt @@ -67,13 +67,13 @@ fun VariableAccessInfo.getAccessDescriptor(): PropertyAccessorDescriptor { } fun VariableAccessInfo.getAccessDescriptorIfNeeded(): CallableDescriptor { - if (variableDescriptor is PropertyDescriptor && - (variableDescriptor.isExtension || TranslationUtils.shouldAccessViaFunctions(variableDescriptor)) - ) { - return getAccessDescriptor() + return if (variableDescriptor is PropertyDescriptor && + (variableDescriptor.isExtension || TranslationUtils.shouldAccessViaFunctions(variableDescriptor)) + ) { + getAccessDescriptor() } else { - return variableDescriptor + variableDescriptor } } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallTranslator.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallTranslator.kt index ed5defd6724..0259fa5ea4c 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallTranslator.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallTranslator.kt @@ -73,11 +73,11 @@ object CallTranslator { val functionName = context.getNameForDescriptor(functionDescriptor) val isNative = AnnotationsUtils.isNativeObject(functionDescriptor) val hasSpreadOperator = false - if (dispatchReceiver != null) { - return DefaultFunctionCallCase.buildDefaultCallWithDispatchReceiver(argumentsInfo, dispatchReceiver, functionName, isNative, - hasSpreadOperator) + return if (dispatchReceiver != null) { + DefaultFunctionCallCase.buildDefaultCallWithDispatchReceiver(argumentsInfo, dispatchReceiver, functionName, isNative, + hasSpreadOperator) } else { - return DefaultFunctionCallCase.buildDefaultCallWithoutReceiver(context, argumentsInfo, functionDescriptor, isNative, hasSpreadOperator) + DefaultFunctionCallCase.buildDefaultCallWithoutReceiver(context, argumentsInfo, functionDescriptor, isNative, hasSpreadOperator) } } } @@ -240,10 +240,10 @@ interface DelegateIntrinsic { null } - if (result != null) { - return callInfo.constructSafeCallIfNeeded(result) + return if (result != null) { + callInfo.constructSafeCallIfNeeded(result) } else { - return null + null } } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.kt index 96733b85f75..78fbb43e19b 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.kt @@ -66,11 +66,11 @@ object ArrayFIF : CompositeFIF() { fun castOrCreatePrimitiveArray(ctx: TranslationContext, type: PrimitiveType?, arg: JsArrayLiteral): JsExpression { if (type == null || !typedArraysEnabled(ctx.config)) return arg - if (type in TYPED_ARRAY_MAP) { - return createTypedArray(type, arg) + return if (type in TYPED_ARRAY_MAP) { + createTypedArray(type, arg) } else { - return JsAstUtils.invokeKotlinFunction(type.lowerCaseName + "ArrayOf", *arg.expressions.toTypedArray()) + JsAstUtils.invokeKotlinFunction(type.lowerCaseName + "ArrayOf", *arg.expressions.toTypedArray()) } } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallArgumentTranslator.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallArgumentTranslator.kt index 355c9b4ea35..0c6668096c6 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallArgumentTranslator.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallArgumentTranslator.kt @@ -325,18 +325,18 @@ class CallArgumentTranslator private constructor( ): JsExpression { assert(concatArguments.isNotEmpty()) { "concatArguments.size should not be 0" } - if (concatArguments.size > 1) { + return if (concatArguments.size > 1) { if (varargPrimitiveType != null) { val method = if (isMixed) "arrayConcat" else "primitiveArrayConcat" - return JsAstUtils.invokeKotlinFunction(method, concatArguments[0], - *concatArguments.subList(1, concatArguments.size).toTypedArray()) + JsAstUtils.invokeKotlinFunction(method, concatArguments[0], + *concatArguments.subList(1, concatArguments.size).toTypedArray()) } else { - return JsInvocation(JsNameRef("concat", concatArguments[0]), concatArguments.subList(1, concatArguments.size)) + JsInvocation(JsNameRef("concat", concatArguments[0]), concatArguments.subList(1, concatArguments.size)) } } else { - return concatArguments[0] + concatArguments[0] } } } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/astUtils.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/astUtils.kt index 73a0c28a396..d95028a21b3 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/astUtils.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/astUtils.kt @@ -65,16 +65,16 @@ fun JsExpression.toInvocationWith( fun padArguments(arguments: List) = arguments + (1..(parameterCount - arguments.size)) .map { Namer.getUndefinedExpression() } - when (this) { + return when (this) { is JsNew -> { qualifier = Namer.getFunctionCallRef(constructorExpression) // `new A(a, b, c)` -> `A.call($this, a, b, c)` - return JsInvocation(qualifier, listOf(thisExpr) + leadingExtraArgs + arguments).source(source) + JsInvocation(qualifier, listOf(thisExpr) + leadingExtraArgs + arguments).source(source) } is JsInvocation -> { qualifier = getQualifier() // `A(a, b, c)` -> `A(a, b, c, $this)` - return JsInvocation(qualifier, leadingExtraArgs + padArguments(arguments) + thisExpr).source(source) + JsInvocation(qualifier, leadingExtraArgs + padArguments(arguments) + thisExpr).source(source) } else -> throw IllegalStateException("Unexpected node type: " + this::class.java) }