DeprecatedSymbolUsageFix to not be available for functions with optional parameters and no sources
This commit is contained in:
@@ -68,7 +68,7 @@ public class DeprecatedSymbolUsageFix(
|
|||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
val nameExpression = diagnostic.getPsiElement() as? JetSimpleNameExpression ?: return null
|
val nameExpression = diagnostic.getPsiElement() as? JetSimpleNameExpression ?: return null
|
||||||
val descriptor = Errors.DEPRECATED_SYMBOL_WITH_MESSAGE.cast(diagnostic).getA()
|
val descriptor = Errors.DEPRECATED_SYMBOL_WITH_MESSAGE.cast(diagnostic).getA()
|
||||||
val replacement = DeprecatedSymbolUsageFixBase.replaceWithPattern(descriptor) ?: return null
|
val replacement = DeprecatedSymbolUsageFixBase.replaceWithPattern(descriptor, nameExpression.getProject()) ?: return null
|
||||||
return DeprecatedSymbolUsageFix(nameExpression, replacement)
|
return DeprecatedSymbolUsageFix(nameExpression, replacement)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public abstract class DeprecatedSymbolUsageFixBase(
|
|||||||
val resolvedCall = element.getResolvedCall(element.analyze()) ?: return false
|
val resolvedCall = element.getResolvedCall(element.analyze()) ?: return false
|
||||||
if (!resolvedCall.getStatus().isSuccess()) return false
|
if (!resolvedCall.getStatus().isSuccess()) return false
|
||||||
val descriptor = resolvedCall.getResultingDescriptor()
|
val descriptor = resolvedCall.getResultingDescriptor()
|
||||||
if (replaceWithPattern(descriptor) != replaceWith) return false
|
if (replaceWithPattern(descriptor, project) != replaceWith) return false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JetPsiFactory(project).createExpression(replaceWith.expression)
|
JetPsiFactory(project).createExpression(replaceWith.expression)
|
||||||
@@ -105,7 +105,7 @@ public abstract class DeprecatedSymbolUsageFixBase(
|
|||||||
editor: Editor?)
|
editor: Editor?)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
public fun replaceWithPattern(descriptor: DeclarationDescriptor): ReplaceWith? {
|
public fun replaceWithPattern(descriptor: DeclarationDescriptor, project: Project): ReplaceWith? {
|
||||||
val annotationClass = descriptor.builtIns.getDeprecatedAnnotation()
|
val annotationClass = descriptor.builtIns.getDeprecatedAnnotation()
|
||||||
val annotation = descriptor.getAnnotations().findAnnotation(DescriptorUtils.getFqNameSafe(annotationClass)) ?: return null
|
val annotation = descriptor.getAnnotations().findAnnotation(DescriptorUtils.getFqNameSafe(annotationClass)) ?: return null
|
||||||
//TODO: code duplication
|
//TODO: code duplication
|
||||||
@@ -118,6 +118,11 @@ public abstract class DeprecatedSymbolUsageFixBase(
|
|||||||
if (pattern.isEmpty()) return null
|
if (pattern.isEmpty()) return null
|
||||||
val argument = replaceWithValue.getAllValueArguments().entrySet().singleOrNull { it.key.getName().asString() == "imports"/*TODO*/ }?.value
|
val argument = replaceWithValue.getAllValueArguments().entrySet().singleOrNull { it.key.getName().asString() == "imports"/*TODO*/ }?.value
|
||||||
val imports = (argument?.getValue() as? List<CompileTimeConstant<String>>)?.map { it.getValue() } ?: emptyList()
|
val imports = (argument?.getValue() as? List<CompileTimeConstant<String>>)?.map { it.getValue() } ?: emptyList()
|
||||||
|
|
||||||
|
// should not be available for descriptors with optional parameters if we cannot fetch default values for them (currently for library with no sources)
|
||||||
|
if (descriptor is CallableDescriptor &&
|
||||||
|
descriptor.getValueParameters().any { it.hasDefaultValue() && OptionalParametersHelper.defaultParameterValue(it, project) == null }) return null
|
||||||
|
|
||||||
return ReplaceWith(pattern, *imports.toTypedArray())
|
return ReplaceWith(pattern, *imports.toTypedArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -164,7 +164,7 @@ public class DeprecatedSymbolUsageInWholeProjectFix(
|
|||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
val nameExpression = diagnostic.getPsiElement() as? JetSimpleNameExpression ?: return null
|
val nameExpression = diagnostic.getPsiElement() as? JetSimpleNameExpression ?: return null
|
||||||
val descriptor = Errors.DEPRECATED_SYMBOL_WITH_MESSAGE.cast(diagnostic).getA()
|
val descriptor = Errors.DEPRECATED_SYMBOL_WITH_MESSAGE.cast(diagnostic).getA()
|
||||||
val replacement = DeprecatedSymbolUsageFixBase.replaceWithPattern(descriptor) ?: return null
|
val replacement = DeprecatedSymbolUsageFixBase.replaceWithPattern(descriptor, nameExpression.getProject()) ?: return null
|
||||||
val descriptorName = RENDERER.render(descriptor)
|
val descriptorName = RENDERER.render(descriptor)
|
||||||
return DeprecatedSymbolUsageInWholeProjectFix(nameExpression, replacement, "Replace usages of '$descriptorName' in whole project")
|
return DeprecatedSymbolUsageInWholeProjectFix(nameExpression, replacement, "Replace usages of '$descriptorName' in whole project")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user