Reformat & cleanup: CreateCallableFromCallActionFactory
This commit is contained in:
+21
-12
@@ -49,8 +49,6 @@ import org.jetbrains.kotlin.types.KotlinType
|
|||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
||||||
import java.lang.AssertionError
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
sealed class CreateCallableFromCallActionFactory<E : KtExpression>(
|
sealed class CreateCallableFromCallActionFactory<E : KtExpression>(
|
||||||
extensionsEnabled: Boolean = true
|
extensionsEnabled: Boolean = true
|
||||||
@@ -68,7 +66,8 @@ sealed class CreateCallableFromCallActionFactory<E : KtExpression>(
|
|||||||
if (PsiTreeUtil.getParentOfType(
|
if (PsiTreeUtil.getParentOfType(
|
||||||
diagElement,
|
diagElement,
|
||||||
KtTypeReference::class.java, KtAnnotationEntry::class.java, KtImportDirective::class.java
|
KtTypeReference::class.java, KtAnnotationEntry::class.java, KtImportDirective::class.java
|
||||||
) != null) return null
|
) != null
|
||||||
|
) return null
|
||||||
|
|
||||||
return when (diagnostic.factory) {
|
return when (diagnostic.factory) {
|
||||||
in Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS, Errors.EXPRESSION_EXPECTED_PACKAGE_FOUND -> {
|
in Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS, Errors.EXPRESSION_EXPECTED_PACKAGE_FOUND -> {
|
||||||
@@ -107,8 +106,7 @@ sealed class CreateCallableFromCallActionFactory<E : KtExpression>(
|
|||||||
if (element is KtCallExpression) this else filter { it is KtClassBody || it is KtFile }
|
if (element is KtCallExpression) this else filter { it is KtClassBody || it is KtFile }
|
||||||
}
|
}
|
||||||
if (containers.isNotEmpty()) containers else return null
|
if (containers.isNotEmpty()) containers else return null
|
||||||
}
|
} else listOf()
|
||||||
else Collections.emptyList()
|
|
||||||
|
|
||||||
return doCreateCallableInfo(element, analysisResult, calleeExpr.getReferencedName(), receiverType, possibleContainers)
|
return doCreateCallableInfo(element, analysisResult, calleeExpr.getReferencedName(), receiverType, possibleContainers)
|
||||||
}
|
}
|
||||||
@@ -161,7 +159,8 @@ sealed class CreateCallableFromCallActionFactory<E : KtExpression>(
|
|||||||
return mainCallable.copy(
|
return mainCallable.copy(
|
||||||
receiverTypeInfo = receiverTypeInfo,
|
receiverTypeInfo = receiverTypeInfo,
|
||||||
possibleContainers = emptyList(),
|
possibleContainers = emptyList(),
|
||||||
modifierList = KtPsiFactory(originalExpression).createModifierList(KtTokens.ABSTRACT_KEYWORD))
|
modifierList = KtPsiFactory(originalExpression).createModifierList(KtTokens.ABSTRACT_KEYWORD)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun getCallableWithReceiverInsideExtension(
|
protected fun getCallableWithReceiverInsideExtension(
|
||||||
@@ -245,7 +244,12 @@ sealed class CreateCallableFromCallActionFactory<E : KtExpression>(
|
|||||||
receiverType: TypeInfo,
|
receiverType: TypeInfo,
|
||||||
possibleContainers: List<KtElement>
|
possibleContainers: List<KtElement>
|
||||||
) = super.doCreateCallableInfo(expression, analysisResult, name, receiverType, possibleContainers)?.let {
|
) = super.doCreateCallableInfo(expression, analysisResult, name, receiverType, possibleContainers)?.let {
|
||||||
ByImplicitExtensionReceiver.getCallableWithReceiverInsideExtension(it, expression, analysisResult.bindingContext, receiverType)
|
ByImplicitExtensionReceiver.getCallableWithReceiverInsideExtension(
|
||||||
|
it,
|
||||||
|
expression,
|
||||||
|
analysisResult.bindingContext,
|
||||||
|
receiverType
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -324,7 +328,8 @@ sealed class CreateCallableFromCallActionFactory<E : KtExpression>(
|
|||||||
val klass = classDescriptor?.source?.getPsi()
|
val klass = classDescriptor?.source?.getPsi()
|
||||||
if ((klass !is KtClass && klass !is PsiClass) || !klass.canRefactor()) return null
|
if ((klass !is KtClass && klass !is PsiClass) || !klass.canRefactor()) return null
|
||||||
|
|
||||||
val expectedType = analysisResult.bindingContext[BindingContext.EXPECTED_EXPRESSION_TYPE, expression.getQualifiedExpressionForSelectorOrThis()]
|
val expectedType =
|
||||||
|
analysisResult.bindingContext[BindingContext.EXPECTED_EXPRESSION_TYPE, expression.getQualifiedExpressionForSelectorOrThis()]
|
||||||
?: classDescriptor.builtIns.nullableAnyType
|
?: classDescriptor.builtIns.nullableAnyType
|
||||||
if (!classDescriptor.defaultType.isSubtypeOf(expectedType)) return null
|
if (!classDescriptor.defaultType.isSubtypeOf(expectedType)) return null
|
||||||
|
|
||||||
@@ -335,16 +340,20 @@ sealed class CreateCallableFromCallActionFactory<E : KtExpression>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val FUNCTIONS = arrayOf(Function.Default,
|
val FUNCTIONS = arrayOf(
|
||||||
|
Function.Default,
|
||||||
Function.Abstract,
|
Function.Abstract,
|
||||||
Function.ByImplicitExtensionReceiver,
|
Function.ByImplicitExtensionReceiver,
|
||||||
Constructor)
|
Constructor
|
||||||
val INSTANCES = arrayOf(Function.Default,
|
)
|
||||||
|
val INSTANCES = arrayOf(
|
||||||
|
Function.Default,
|
||||||
Function.Abstract,
|
Function.Abstract,
|
||||||
Function.ByImplicitExtensionReceiver,
|
Function.ByImplicitExtensionReceiver,
|
||||||
Constructor,
|
Constructor,
|
||||||
Property.Default,
|
Property.Default,
|
||||||
Property.Abstract,
|
Property.Abstract,
|
||||||
Property.ByImplicitExtensionReceiver)
|
Property.ByImplicitExtensionReceiver
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user