From 73da45779819ad38069d1c3333c3b3d74721d4f9 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 2 Sep 2015 19:29:33 +0300 Subject: [PATCH] Changes on code reivew --- core/builtins/src/kotlin/Annotations.kt | 2 +- .../ConflictingExtensionProperty.html | 2 +- .../ConflictingExtensionPropertyInspection.kt | 31 +++++++++++-------- .../replaceWith/DeprecatedSymbolUsageFix.kt | 2 +- .../DeprecatedSymbolUsageFixBase.kt | 4 +-- .../replaceWith/UsageReplacementStrategy.kt | 4 +-- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/core/builtins/src/kotlin/Annotations.kt b/core/builtins/src/kotlin/Annotations.kt index 72df6e172b7..ab30d0de2eb 100644 --- a/core/builtins/src/kotlin/Annotations.kt +++ b/core/builtins/src/kotlin/Annotations.kt @@ -48,7 +48,7 @@ public annotation(mustBeDocumented = true) class deprecated(val value: String, v * For function calls, the replacement expression may contain argument names of the deprecated function, * which will be substituted with actual parameters used in the call being updated. The imports used in the file * containing the deprecated function or property are NOT accessible; if the replacement expression refers - * on any of those imports, they need to be specified explicitly in the [imports] parmeter. + * on any of those imports, they need to be specified explicitly in the [imports] parameter. * @property imports the qualified names that need to be imported in order for the references in the * replacement expression to be resolved correctly. */ diff --git a/idea/resources/inspectionDescriptions/ConflictingExtensionProperty.html b/idea/resources/inspectionDescriptions/ConflictingExtensionProperty.html index 1cb77ded0a8..e5e87745dd3 100644 --- a/idea/resources/inspectionDescriptions/ConflictingExtensionProperty.html +++ b/idea/resources/inspectionDescriptions/ConflictingExtensionProperty.html @@ -1,5 +1,5 @@ -This inspection reports extension properties that conflict with synthetic ones automatically produced from Java get/set-methods and that should be either removed or renamed to avoid breaking code by future changes in the compiler. +This inspection reports extension properties that conflict with synthetic ones automatically produced from Java get/set-methods. Those properties should be either removed or renamed to avoid breaking code by future changes in the compiler. diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt index 11813866ae2..4a4cb58003c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt @@ -70,22 +70,11 @@ public class ConflictingExtensionPropertyInspection : AbstractKotlinInspection() // don't report on hidden declarations if (propertyDescriptor.isAnnotatedAsHidden()) return - val fixes = if (isSameAsSynthetic(property, conflictingExtension)) { - val fix1 = IntentionWrapper(DeleteRedundantExtensionAction(property), file) - // don't add the second fix when on the fly to allow code cleanup - val fix2 = if (isOnTheFly) - object : IntentionWrapper(MarkHiddenAndDeprecatedAction(property), file), LowPriorityAction {} - else - null - listOf(fix1, fix2).filterNotNull().toTypedArray() - } - else { - emptyArray() - } + val fixes = createFixes(property, conflictingExtension, isOnTheFly) val problemDescriptor = holder.manager.createProblemDescriptor( nameElement, - "This property conflicts with synthetic extension and should be removed to avoid breaking code by future changes in the compiler", + "This property conflicts with synthetic extension and should be removed or renamed to avoid breaking code by future changes in the compiler", true, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING @@ -171,6 +160,22 @@ public class ConflictingExtensionPropertyInspection : AbstractKotlinInspection() } } + private fun createFixes(property: JetProperty, conflictingExtension: SyntheticJavaPropertyDescriptor, isOnTheFly: Boolean): Array { + val fixes = if (isSameAsSynthetic(property, conflictingExtension)) { + val fix1 = IntentionWrapper(DeleteRedundantExtensionAction(property), property.containingFile) + // don't add the second fix when on the fly to allow code cleanup + val fix2 = if (isOnTheFly) + object : IntentionWrapper(MarkHiddenAndDeprecatedAction(property), property.containingFile), LowPriorityAction {} + else + null + listOf(fix1, fix2).filterNotNull().toTypedArray() + } + else { + emptyArray() + } + return fixes + } + private class DeleteRedundantExtensionAction(property: JetProperty) : JetIntentionAction(property) { private val LOG = Logger.getInstance(DeleteRedundantExtensionAction::class.java); diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFix.kt index 1ffa557fd46..95ccada09aa 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFix.kt @@ -65,7 +65,7 @@ public class DeprecatedSymbolUsageFix( public fun isImportToBeRemoved(import: JetImportDirective): Boolean { return !import.isAllUnder - && import.targetDescriptors().all { DeprecatedSymbolUsageFixBase.replaceWithPattern(it, import.project) != null } + && import.targetDescriptors().all { DeprecatedSymbolUsageFixBase.fetchReplaceWithPattern(it, import.project) != null } } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt index 000564ff962..1ca64eea049 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt @@ -59,7 +59,7 @@ public abstract class DeprecatedSymbolUsageFixBase( editor: Editor?) companion object { - fun replaceWithPattern(descriptor: DeclarationDescriptor, project: Project): ReplaceWith? { + fun fetchReplaceWithPattern(descriptor: DeclarationDescriptor, project: Project): ReplaceWith? { val annotationClass = descriptor.builtIns.deprecatedAnnotation val annotation = descriptor.annotations.findAnnotation(DescriptorUtils.getFqNameSafe(annotationClass)) ?: return null val replaceWithValue = annotation.argumentValue(kotlin.deprecated::replaceWith.name) as? AnnotationDescriptor ?: return null @@ -101,7 +101,7 @@ public abstract class DeprecatedSymbolUsageFixBase( null) ?: return null val descriptor = Errors.DEPRECATED_SYMBOL_WITH_MESSAGE.cast(deprecatedDiagnostic).a - val replacement = DeprecatedSymbolUsageFixBase.replaceWithPattern(descriptor, nameExpression.project) ?: return null + val replacement = DeprecatedSymbolUsageFixBase.fetchReplaceWithPattern(descriptor, nameExpression.project) ?: return null return Data(nameExpression, replacement, descriptor) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/UsageReplacementStrategy.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/UsageReplacementStrategy.kt index c354cd57a7f..b037a09c805 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/UsageReplacementStrategy.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/UsageReplacementStrategy.kt @@ -35,10 +35,10 @@ interface UsageReplacementStrategy { val bindingContext = resolutionFacade.analyze(element, BodyResolveMode.PARTIAL) var target = element.mainReference.resolveToDescriptors(bindingContext).singleOrNull() ?: return null - var replacePatternFromSymbol = DeprecatedSymbolUsageFixBase.replaceWithPattern(target, resolutionFacade.project) + var replacePatternFromSymbol = DeprecatedSymbolUsageFixBase.fetchReplaceWithPattern(target, resolutionFacade.project) if (replacePatternFromSymbol == null && target is ConstructorDescriptor) { target = target.containingDeclaration - replacePatternFromSymbol = DeprecatedSymbolUsageFixBase.replaceWithPattern(target, resolutionFacade.project) + replacePatternFromSymbol = DeprecatedSymbolUsageFixBase.fetchReplaceWithPattern(target, resolutionFacade.project) } // check that ReplaceWith hasn't changed