Used more specific API
This commit is contained in:
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.idea.intentions
|
|||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.analyzer.analyzeInContext
|
import org.jetbrains.kotlin.analyzer.computeTypeInContext
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
@@ -97,8 +97,8 @@ public class ConvertToExpressionBodyIntention : JetSelfTargetingOffsetIndependen
|
|||||||
|
|
||||||
val declaredType = (declaration.resolveToDescriptor() as? CallableDescriptor)?.getReturnType() ?: return false
|
val declaredType = (declaration.resolveToDescriptor() as? CallableDescriptor)?.getReturnType() ?: return false
|
||||||
val scope = scopeExpression.analyze()[BindingContext.RESOLUTION_SCOPE, scopeExpression] ?: return false
|
val scope = scopeExpression.analyze()[BindingContext.RESOLUTION_SCOPE, scopeExpression] ?: return false
|
||||||
val expressionType = expression.analyzeInContext(scope).getType(expression) ?: return false
|
val expressionType = expression.computeTypeInContext(scope)
|
||||||
return expressionType.isSubtypeOf(declaredType)
|
return !expressionType.isError && expressionType.isSubtypeOf(declaredType)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calcValue(declaration: JetDeclarationWithBody): JetExpression? {
|
private fun calcValue(declaration: JetDeclarationWithBody): JetExpression? {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import com.intellij.openapi.project.Project
|
|||||||
import com.intellij.openapi.util.Key
|
import com.intellij.openapi.util.Key
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import org.jetbrains.kotlin.analyzer.analyzeInContext
|
import org.jetbrains.kotlin.analyzer.computeTypeInContext
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
@@ -679,11 +679,11 @@ public abstract class DeprecatedSymbolUsageFixBase(
|
|||||||
if (usages.isNotEmpty()) {
|
if (usages.isNotEmpty()) {
|
||||||
var explicitType: JetType? = null
|
var explicitType: JetType? = null
|
||||||
if (valueType != null && !ErrorUtils.containsErrorType(valueType)) {
|
if (valueType != null && !ErrorUtils.containsErrorType(valueType)) {
|
||||||
val valueTypeWithoutExpectedType = value.analyzeInContext(
|
val valueTypeWithoutExpectedType = value.computeTypeInContext(
|
||||||
resolutionScope!!,
|
resolutionScope!!,
|
||||||
dataFlowInfo = bindingContext.getDataFlowInfo(expressionToBeReplaced)
|
dataFlowInfo = bindingContext.getDataFlowInfo(expressionToBeReplaced)
|
||||||
).getType(value)
|
)
|
||||||
if (valueTypeWithoutExpectedType == null || ErrorUtils.containsErrorType(valueTypeWithoutExpectedType)) {
|
if (ErrorUtils.containsErrorType(valueTypeWithoutExpectedType)) {
|
||||||
explicitType = valueType
|
explicitType = valueType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user