Minor changes after code review

This commit is contained in:
Valentin Kipyatkov
2015-02-12 19:47:25 +03:00
parent dd0664939c
commit d579e4906b
2 changed files with 23 additions and 16 deletions
@@ -137,24 +137,28 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Kotlin
val fqName = descriptor.importableFqName ?: continue val fqName = descriptor.importableFqName ?: continue
if (!descriptor.canBeReferencedViaImport()) continue if (!descriptor.canBeReferencedViaImport()) continue
val kind = when (descriptor.getImportableDescriptor()) { val kind = referenceDataKind(descriptor) ?: continue
is ClassDescriptor ->
KotlinReferenceData.Kind.CLASS
is PackageViewDescriptor ->
KotlinReferenceData.Kind.PACKAGE
is CallableDescriptor ->
if (descriptor.isExtension) KotlinReferenceData.Kind.EXTENSION_CALLABLE else KotlinReferenceData.Kind.NON_EXTENSION_CALLABLE
else ->
continue
}
collectedData.add(KotlinReferenceData(element.range.start - startOffset, element.range.end - startOffset, fqName.asString(), kind)) collectedData.add(KotlinReferenceData(element.range.start - startOffset, element.range.end - startOffset, fqName.asString(), kind))
} }
return collectedData return collectedData
} }
private fun referenceDataKind(descriptor: DeclarationDescriptor): KotlinReferenceData.Kind? {
return when (descriptor.getImportableDescriptor()) {
is ClassDescriptor ->
KotlinReferenceData.Kind.CLASS
is PackageViewDescriptor ->
KotlinReferenceData.Kind.PACKAGE
is CallableDescriptor ->
if (descriptor.isExtension) KotlinReferenceData.Kind.EXTENSION_CALLABLE else KotlinReferenceData.Kind.NON_EXTENSION_CALLABLE
else ->
null
}
}
private data class ReferenceToRestoreData( private data class ReferenceToRestoreData(
val reference: JetReference, val reference: JetReference,
val refData: KotlinReferenceData val refData: KotlinReferenceData
@@ -232,10 +236,13 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Kotlin
LOG.error("Failed to analyze reference (${element.getText()}) after copy paste", e) LOG.error("Failed to analyze reference (${element.getText()}) after copy paste", e)
return null return null
} }
val referencedFqNames = referencedDescriptors.filterNot { ErrorUtils.isError(it) }.map { it.importableFqName }.filterNotNull() val referencedFqNames = referencedDescriptors
.filterNot { ErrorUtils.isError(it) }
.map { it.importableFqName }
.filterNotNull()
val originalFqName = FqName(refData.fqName) val originalFqName = FqName(refData.fqName)
val referencesSame = referencedFqNames.any { it == originalFqName } val referencesSame = referencedFqNames.any { it == originalFqName }
val conflict = referencedFqNames.any { it != originalFqName && it.shortName() == originalFqName.shortName() } val conflict = referencedFqNames.any { it != originalFqName }
if (referencesSame && !conflict) return null if (referencesSame && !conflict) return null
return ReferenceToRestoreData(reference, refData) return ReferenceToRestoreData(reference, refData)
} }
@@ -259,6 +266,7 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Kotlin
bindingRequests.add(BindingRequest(pointer, fqName)) bindingRequests.add(BindingRequest(pointer, fqName))
} }
//TODO: this may sometimes cause insertion of redundant imports (see 3 ignored tests)
if (refData.kind == KotlinReferenceData.Kind.NON_EXTENSION_CALLABLE || refData.kind == KotlinReferenceData.Kind.EXTENSION_CALLABLE) { if (refData.kind == KotlinReferenceData.Kind.NON_EXTENSION_CALLABLE || refData.kind == KotlinReferenceData.Kind.EXTENSION_CALLABLE) {
descriptorsToImport.addIfNotNull(findCallableToImport(fqName, file)) descriptorsToImport.addIfNotNull(findCallableToImport(fqName, file))
} }
@@ -1,6 +1,5 @@
package a package a
//NOTE: this case can be improved by using shorten reference after importing
class a { class a {
class object { class object {
} }