Cleanup: apply "lift out..." inspection (+ some others)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
0c41ceea9d
commit
9c06739594
+9
-9
@@ -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)
|
||||
|
||||
@@ -61,13 +61,13 @@ open class BasicReplStageHistory<T>(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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<PseudoValue, ValueParameterDescriptor>()).outputValue
|
||||
}
|
||||
else {
|
||||
writtenValue = initializer?.let { createSyntheticValue(entry, MagicKind.UNRESOLVED_CALL, it) }
|
||||
initializer?.let { createSyntheticValue(entry, MagicKind.UNRESOLVED_CALL, it) }
|
||||
}
|
||||
|
||||
if (generateWriteForEntries) {
|
||||
|
||||
+7
-10
@@ -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(
|
||||
|
||||
@@ -68,11 +68,7 @@ private object PsiChildRangeArgumentType : PsiElementPlaceholderArgumentType<Psi
|
||||
val project = placeholder.project
|
||||
val codeStyleManager = CodeStyleManager.getInstance(project)
|
||||
|
||||
if (argument.isEmpty) {
|
||||
placeholder.delete()
|
||||
return PsiChildRange.EMPTY
|
||||
}
|
||||
else {
|
||||
return if (!argument.isEmpty) {
|
||||
val first = placeholder.parent.addRangeBefore(argument.first!!, argument.last!!, placeholder)
|
||||
val last = placeholder.prevSibling
|
||||
placeholder.delete()
|
||||
@@ -81,7 +77,11 @@ private object PsiChildRangeArgumentType : PsiElementPlaceholderArgumentType<Psi
|
||||
if (last != first) {
|
||||
codeStyleManager.reformatNewlyAddedElement(last.node.treeParent, last.node)
|
||||
}
|
||||
return PsiChildRange(first, last)
|
||||
PsiChildRange(first, last)
|
||||
}
|
||||
else {
|
||||
placeholder.delete()
|
||||
PsiChildRange.EMPTY
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,8 +155,8 @@ fun <TElement : KtElement> 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 <TElement : KtElement> 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
|
||||
|
||||
@@ -164,18 +164,17 @@ object CastDiagnosticsUtil {
|
||||
val variables = subtypeWithVariables.constructor.parameters
|
||||
val variableConstructors = variables.map { descriptor -> descriptor.typeConstructor }.toSet()
|
||||
|
||||
val substitution: MutableMap<TypeConstructor, TypeProjection>
|
||||
if (supertypeWithVariables != null) {
|
||||
val substitution: MutableMap<TypeConstructor, TypeProjection> = if (supertypeWithVariables != null) {
|
||||
// Now, let's try to unify Collection<T> and Collection<Foo> 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<TypeConstructor, TypeProjection>(variables.size)
|
||||
Maps.newHashMapWithExpectedSize<TypeConstructor, TypeProjection>(variables.size)
|
||||
}
|
||||
|
||||
// If some of the parameters are not determined by unification, it means that these parameters are lost,
|
||||
|
||||
+3
-3
@@ -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) {
|
||||
|
||||
+5
-5
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+3
-3
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ClassDescriptor>() ?: return emptyList()
|
||||
return classDescriptor.typeConstructor.supertypesWithAny().map { ReceiverType(it, 0) }
|
||||
classDescriptor.typeConstructor.supertypesWithAny().map { ReceiverType(it, 0) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-21
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -59,11 +59,11 @@ tailrec fun <T : Any> LookupElement.putUserDataDeep(key: Key<T>, value: T?) {
|
||||
}
|
||||
|
||||
tailrec fun <T : Any> LookupElement.getUserDataDeep(key: Key<T>): 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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-19
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,18 +28,18 @@ class AddBracesIntention : SelfTargetingIntention<KtElement>(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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-13
@@ -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<KtExpression>.appendConditionWithSubjectRemoved(con
|
||||
}
|
||||
}
|
||||
|
||||
fun KtPsiFactory.combineWhenConditions(conditions: Array<KtWhenCondition>, 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<KtWhenCondition>, subject: KtExpression?) = when (conditions.size) {
|
||||
0 -> null
|
||||
1 -> conditions[0].toExpression(subject)
|
||||
else -> buildExpression {
|
||||
appendExpressions(conditions.map { it.toExpression(subject) }, separator = "||")
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -135,12 +135,12 @@ fun KtCallableDeclaration.hasDifferentSetsOfUsages(elements1: Collection<KtEleme
|
||||
|
||||
fun KtExpressionWithLabel.targetLoop(): KtLoopExpression? {
|
||||
val label = getTargetLabel()
|
||||
if (label == null) {
|
||||
return parents.firstIsInstance<KtLoopExpression>()
|
||||
return if (label == null) {
|
||||
parents.firstIsInstance<KtLoopExpression>()
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+22
-22
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 += "{}"
|
||||
"{}"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-10
@@ -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}")
|
||||
}
|
||||
|
||||
+3
-3
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,11 +121,11 @@ abstract class CallableRefactoring<out T: CallableDescriptor>(
|
||||
}
|
||||
|
||||
fun buildDialogOptions(isSingleFunctionSelected: Boolean): List<String> {
|
||||
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<Call
|
||||
fun DeclarationDescriptor.getContainingScope(): LexicalScope? {
|
||||
val declaration = DescriptorToSourceUtils.descriptorToDeclaration(this)
|
||||
val block = declaration?.parent as? KtBlockExpression
|
||||
if (block != null) {
|
||||
return if (block != null) {
|
||||
val lastStatement = block.statements.last()
|
||||
val bindingContext = lastStatement.analyze()
|
||||
return lastStatement.getResolutionScope(bindingContext, lastStatement.getResolutionFacade())
|
||||
lastStatement.getResolutionScope(bindingContext, lastStatement.getResolutionFacade())
|
||||
}
|
||||
else {
|
||||
val containingDescriptor = containingDeclaration ?: return null
|
||||
return when (containingDescriptor) {
|
||||
when (containingDescriptor) {
|
||||
is ClassDescriptorWithResolutionScopes -> containingDescriptor.scopeForInitializerResolution
|
||||
is PackageFragmentDescriptor -> LexicalScope.Base(containingDescriptor.getMemberScope().memberScopeAsImportingScope(), this)
|
||||
else -> null
|
||||
|
||||
@@ -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<KotlinTarget>
|
||||
if (attributes.isEmpty()) {
|
||||
arguments = setOf<KotlinTarget>()
|
||||
val arguments: Set<KotlinTarget> = if (attributes.isEmpty()) {
|
||||
setOf()
|
||||
}
|
||||
else {
|
||||
val value = attributes[0].value
|
||||
arguments = when (value) {
|
||||
when (value) {
|
||||
is PsiArrayInitializerMemberValue -> value.initializers.filterIsInstance<PsiReferenceExpression>()
|
||||
.flatMap { mapTargetByName(it) }
|
||||
.toSet()
|
||||
is PsiReferenceExpression -> mapTargetByName(value)
|
||||
else -> setOf<KotlinTarget>()
|
||||
else -> setOf()
|
||||
}
|
||||
}
|
||||
val deferredExpressionList = arguments.map {
|
||||
|
||||
@@ -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<PsiClass>().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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,16 +340,16 @@ class CodeBuilder(private val topElement: PsiElement?, private var docConverter:
|
||||
|
||||
private companion object {
|
||||
operator fun <T> List<T>.plus(other: List<T>): List<T> {
|
||||
when {
|
||||
isEmpty() -> return other
|
||||
return when {
|
||||
isEmpty() -> other
|
||||
|
||||
other.isEmpty() -> return this
|
||||
other.isEmpty() -> this
|
||||
|
||||
else -> {
|
||||
val result = ArrayList<T>(size + other.size)
|
||||
result.addAll(this)
|
||||
result.addAll(other)
|
||||
return result
|
||||
result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -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<in I : CallInfo> {
|
||||
null
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
return callInfo.constructSafeCallIfNeeded(result)
|
||||
return if (result != null) {
|
||||
callInfo.constructSafeCallIfNeeded(result)
|
||||
} else {
|
||||
return null
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -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]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,16 +65,16 @@ fun JsExpression.toInvocationWith(
|
||||
fun padArguments(arguments: List<JsExpression>) = 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user