Changes on code reivew

This commit is contained in:
Valentin Kipyatkov
2015-09-02 19:29:33 +03:00
parent 6575fb8535
commit 73da457798
6 changed files with 25 additions and 20 deletions
+1 -1
View File
@@ -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.
*/
@@ -1,5 +1,5 @@
<html>
<body>
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.
</body>
</html>
@@ -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<IntentionWrapper> {
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<JetProperty>(property) {
private val LOG = Logger.getInstance(DeleteRedundantExtensionAction::class.java);
@@ -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 }
}
}
}
@@ -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)
}
}
@@ -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