Fix warning about incompatible types.

This commit is contained in:
Ilya Gorbunov
2015-11-26 21:13:02 +03:00
parent 0ffce06356
commit e5dd719eec
12 changed files with 25 additions and 25 deletions
@@ -60,7 +60,7 @@ object BuiltinSpecialProperties {
}
private fun CallableMemberDescriptor.hasBuiltinSpecialPropertyFqNameImpl(): Boolean {
if (FQ_NAMES.containsRaw(fqNameOrNull())) return true
if (fqNameOrNull() in FQ_NAMES) return true
if (!isFromBuiltins()) return false
return overriddenDescriptors.any { hasBuiltinSpecialPropertyFqName(it) }
@@ -108,7 +108,7 @@ object BuiltinMethodsWithSpecialGenericSignature {
ERASED_VALUE_PARAMETERS_FQ_NAMES.map { it.shortName() }.toSet()
private val CallableMemberDescriptor.hasErasedValueParametersInJava: Boolean
get() = ERASED_VALUE_PARAMETERS_FQ_NAMES.containsRaw(fqNameOrNull())
get() = fqNameOrNull() in ERASED_VALUE_PARAMETERS_FQ_NAMES
@JvmStatic
fun getOverriddenBuiltinFunctionWithErasedValueParametersInJava(
@@ -122,7 +122,7 @@ object BuiltinMethodsWithSpecialGenericSignature {
fun getDefaultValueForOverriddenBuiltinFunction(functionDescriptor: FunctionDescriptor): DefaultValue? {
if (functionDescriptor.name !in ERASED_VALUE_PARAMETERS_SHORT_NAMES) return null
return functionDescriptor.firstOverridden {
GENERIC_PARAMETERS_METHODS_TO_DEFAULT_VALUES_MAP.keys.containsRaw(it.fqNameOrNull())
it.fqNameOrNull() in GENERIC_PARAMETERS_METHODS_TO_DEFAULT_VALUES_MAP.keys
}?.let { GENERIC_PARAMETERS_METHODS_TO_DEFAULT_VALUES_MAP[it.fqNameSafe] }
}
@@ -68,8 +68,8 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Kotlin
private val LOG = Logger.getInstance(javaClass<KotlinCopyPasteReferenceProcessor>())
private val IGNORE_REFERENCES_INSIDE: Array<Class<out KtElement>> = arrayOf(
javaClass<KtImportList>(),
javaClass<KtPackageDirective>()
KtImportList::class.java,
KtPackageDirective::class.java
)
override fun extractTransferableData(content: Transferable): List<KotlinReferenceTransferableData> {
@@ -139,7 +139,7 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Kotlin
) {
if (PsiTreeUtil.getNonStrictParentOfType(element, *IGNORE_REFERENCES_INSIDE) != null) return
element.forEachDescendantOfType<KtElement>(canGoInside = { it.javaClass !in IGNORE_REFERENCES_INSIDE }) { element ->
element.forEachDescendantOfType<KtElement>(canGoInside = { it.javaClass as Class<*> !in IGNORE_REFERENCES_INSIDE }) { element ->
val reference = element.mainReference ?: return@forEachDescendantOfType
val descriptors = reference.resolveToDescriptors(element.analyze()) //TODO: we could use partial body resolve for all references together
@@ -116,10 +116,10 @@ class KotlinEditorTextProvider : EditorTextProvider {
}
private val NOT_ACCEPTED_AS_CONTEXT_TYPES =
arrayOf(javaClass<KtUserType>(), javaClass<KtImportDirective>(), javaClass<KtPackageDirective>())
arrayOf(KtUserType::class.java, KtImportDirective::class.java, KtPackageDirective::class.java)
fun isAcceptedAsCodeFragmentContext(element: PsiElement): Boolean {
return element.javaClass !in NOT_ACCEPTED_AS_CONTEXT_TYPES &&
return element.javaClass as Class<*> !in NOT_ACCEPTED_AS_CONTEXT_TYPES &&
PsiTreeUtil.getParentOfType(element, *NOT_ACCEPTED_AS_CONTEXT_TYPES) == null
}
}
@@ -420,7 +420,7 @@ public class KotlinPositionManager(private val myDebugProcess: DebugProcess) : M
KtAnonymousInitializer::class.java)
private fun getElementToCalculateClassName(notPositionedElement: PsiElement?): KtElement? {
if (notPositionedElement?.javaClass in TYPES_TO_CALCULATE_CLASSNAME ) return notPositionedElement as KtElement
if (notPositionedElement?.javaClass as Class<*> in TYPES_TO_CALCULATE_CLASSNAME) return notPositionedElement as KtElement
return PsiTreeUtil.getParentOfType(notPositionedElement, *TYPES_TO_CALCULATE_CLASSNAME)
}
@@ -132,7 +132,7 @@ public class ConvertFunctionToPropertyIntention : SelfTargetingIntention<KtNamed
if (callable is PsiMethod) {
callable.getContainingClass()
?.findMethodsByName(getterName, true)
?.firstOrNull { it.getParameterList().getParametersCount() == 0 && it.namedUnwrappedElement !in callables }
?.firstOrNull { it.getParameterList().getParametersCount() == 0 && it.namedUnwrappedElement as PsiElement? !in callables }
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
}
@@ -110,7 +110,7 @@ public class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtPrope
else if (callable is PsiMethod) {
callable.getContainingClass()
?.findMethodsByName(propertyName, true)
?.firstOrNull { it.getParameterList().getParametersCount() == 0 && it.namedUnwrappedElement !in callables }
?.firstOrNull { it.getParameterList().getParametersCount() == 0 && it.namedUnwrappedElement as PsiElement? !in callables }
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
}
@@ -191,8 +191,8 @@ internal class AutoImportFix(expression: KtSimpleNameExpression) : AutoImportFix
if (conventionName != null) {
if (element is KtOperationReferenceExpression) {
val elementType = element.firstChild.node.elementType
if (OperatorConventions.ASSIGNMENT_OPERATIONS.containsKeyRaw(elementType)) {
val counterpart = OperatorConventions.ASSIGNMENT_OPERATION_COUNTERPARTS.getRaw(elementType)
if (elementType in OperatorConventions.ASSIGNMENT_OPERATIONS) {
val counterpart = OperatorConventions.ASSIGNMENT_OPERATION_COUNTERPARTS[elementType]
val counterpartName = OperatorConventions.BINARY_OPERATION_NAMES.get(counterpart)
if (counterpartName != null) {
return@run listOf(conventionName, counterpartName)
@@ -154,8 +154,8 @@ class KotlinFunctionCallUsage(
private fun needSeparateVariable(element: PsiElement): Boolean {
return when {
element is KtConstantExpression, element is KtThisExpression, element is KtSimpleNameExpression -> false
element is KtBinaryExpression && OperatorConventions.ASSIGNMENT_OPERATIONS.containsKeyRaw(element.operationToken) -> true
element is KtUnaryExpression && OperatorConventions.INCREMENT_OPERATIONS.containsRaw(element.operationToken) -> true
element is KtBinaryExpression && OperatorConventions.ASSIGNMENT_OPERATIONS.contains(element.operationToken) -> true
element is KtUnaryExpression && OperatorConventions.INCREMENT_OPERATIONS.contains(element.operationToken) -> true
element is KtCallExpression -> element.getResolvedCall(context)?.resultingDescriptor is ConstructorDescriptor
else -> element.children.any { needSeparateVariable(it) }
}
@@ -210,7 +210,7 @@ class KotlinFunctionCallUsage(
}
}
var expressionToReplace: KtExpression = nameCounterpartMap.getRaw(ref.element) ?: continue
var expressionToReplace: KtExpression = nameCounterpartMap[ref.element] ?: continue
val parent = expressionToReplace.parent
if (parent is KtThisExpression) {
@@ -305,9 +305,9 @@ private fun ExtractionData.analyzeControlFlow(
}
val outParameters =
parameters.filter { it.mirrorVarName != null && modifiedVarDescriptors.getRaw(it.originalDescriptor) != null }.sortedBy { it.nameForRef }
parameters.filter { it.mirrorVarName != null && modifiedVarDescriptors[it.originalDescriptor] != null }.sortedBy { it.nameForRef }
val outDeclarations =
declarationsToCopy.filter { modifiedVarDescriptors.getRaw(bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, it]) != null }
declarationsToCopy.filter { modifiedVarDescriptors[bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, it]] != null }
val modifiedValueCount = outParameters.size + outDeclarations.size
val outputValues = ArrayList<OutputValue>()
@@ -339,7 +339,7 @@ private fun ExtractionData.analyzeControlFlow(
val descriptor = bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, it] as? CallableDescriptor
Initializer(it as KtProperty, descriptor?.returnType ?: module.builtIns.defaultParameterType)
}
outParameters.mapTo(outputValues) { ParameterUpdate(it, modifiedVarDescriptors.getRaw(it.originalDescriptor)!!) }
outParameters.mapTo(outputValues) { ParameterUpdate(it, modifiedVarDescriptors[it.originalDescriptor]!!) }
if (outputValues.isNotEmpty()) {
if (jumpExits.isNotEmpty()) return outputAndExitsError
@@ -459,7 +459,7 @@ fun ExtractionGeneratorConfiguration.generateDeclaration(
val counterpartMap = createNameCounterpartMap(currentResultExpression, expressionToUnifyWith ?: newResultExpression)
counterpartMap.entries.forEach {
val (cmOriginalExpr, cmNewExpr) = it
nameByOffset.entrySet().find { it.value.containsRaw(cmOriginalExpr) }?.let {
nameByOffset.entrySet().find { cmOriginalExpr in it.value }?.let {
nameByOffset.remove(it.key, cmOriginalExpr)
nameByOffset.putValue(it.key, cmNewExpr)
}
@@ -512,7 +512,7 @@ fun ExtractionGeneratorConfiguration.generateDeclaration(
val jumpValue = descriptor.controlFlow.jumpOutputValue
if (jumpValue != null) {
replacingReturn = psiFactory.createExpression(if (jumpValue.conditional) "return true" else "return")
returnsForLabelRemoval.removeAllRaw(jumpValue.elementsToReplace)
returnsForLabelRemoval.removeAll(jumpValue.elementsToReplace)
expressionsToReplaceWithReturn = getCounterparts(jumpValue.elementsToReplace, body, bodyOffset, file)
}
else {
@@ -101,7 +101,7 @@ internal fun ExtractionData.inferParametersInfo(
if (currentName == null) {
currentName = KotlinNameSuggester.suggestNamesByType(getParameterType(options.allowSpecialClassNames), varNameValidator, "p").first()
}
mirrorVarName = if (modifiedVarDescriptors.containsRaw(descriptorToExtract)) KotlinNameSuggester.suggestNameByName(name, varNameValidator) else null
mirrorVarName = if (descriptorToExtract in modifiedVarDescriptors) KotlinNameSuggester.suggestNameByName(name, varNameValidator) else null
info.parameters.add(this)
}
}
@@ -164,10 +164,10 @@ private fun KotlinPullUpData.checkVisibility(
val childrenToCheck = member.allChildren.toArrayList()
if (memberInfo.isToAbstract && member is KtCallableDeclaration) {
when (member) {
is KtNamedFunction -> childrenToCheck.remove(member.bodyExpression)
is KtNamedFunction -> childrenToCheck.remove(member.bodyExpression as PsiElement?)
is KtProperty -> {
childrenToCheck.remove(member.initializer)
childrenToCheck.remove(member.delegateExpression)
childrenToCheck.remove(member.initializer as PsiElement?)
childrenToCheck.remove(member.delegateExpression as PsiElement?)
childrenToCheck.removeAll(member.accessors)
}
}