More informative presentation of synthetic properties in completion

This commit is contained in:
Valentin Kipyatkov
2015-07-14 22:10:16 +03:00
parent d743924be9
commit 0cea5fc9b2
6 changed files with 37 additions and 27 deletions
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.psi.psiUtil.parents
import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.synthetic.SyntheticJavaBeansPropertyDescriptor
import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.TypeUtils
@@ -216,27 +217,36 @@ public class LookupElementFactory(
} }
if (descriptor is CallableDescriptor) { if (descriptor is CallableDescriptor) {
if (descriptor.getExtensionReceiverParameter() != null) { when {
val originalReceiver = descriptor.getOriginal().getExtensionReceiverParameter()!! descriptor is SyntheticJavaBeansPropertyDescriptor -> {
val receiverPresentation = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(originalReceiver.getType()) var from = descriptor.getMethod.getName().asString() + "()"
element = element.appendTailText(" for $receiverPresentation", true) descriptor.setMethod?.let { from += "/" + it.getName().asString() + "()" }
element = element.appendTailText(" (from $from)", true)
val container = descriptor.getContainingDeclaration()
val containerPresentation = if (container is ClassDescriptor)
DescriptorUtils.getFqNameFromTopLevelClass(container).toString()
else if (container is PackageFragmentDescriptor)
container.fqName.toString()
else
null
if (containerPresentation != null) {
element = element.appendTailText(" in $containerPresentation", true)
} }
}
else { descriptor.getExtensionReceiverParameter() != null -> {
val container = descriptor.getContainingDeclaration() val originalReceiver = descriptor.getOriginal().getExtensionReceiverParameter()!!
if (container is PackageFragmentDescriptor) { // we show container only for global functions and properties val receiverPresentation = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(originalReceiver.getType())
//TODO: it would be probably better to show it also for static declarations which are not from the current class (imported) element = element.appendTailText(" for $receiverPresentation", true)
element = element.appendTailText(" (${container.fqName})", true)
val container = descriptor.getContainingDeclaration()
val containerPresentation = if (container is ClassDescriptor)
DescriptorUtils.getFqNameFromTopLevelClass(container).toString()
else if (container is PackageFragmentDescriptor)
container.fqName.toString()
else
null
if (containerPresentation != null) {
element = element.appendTailText(" in $containerPresentation", true)
}
}
else -> {
val container = descriptor.getContainingDeclaration()
if (container is PackageFragmentDescriptor) { // we show container only for global functions and properties
//TODO: it would be probably better to show it also for static declarations which are not from the current class (imported)
element = element.appendTailText(" (${container.fqName})", true)
}
} }
} }
} }
@@ -3,6 +3,6 @@ fun foo(thread: Thread) {
} }
// INVOCATION_COUNT: 2 // INVOCATION_COUNT: 2
// EXIST_JAVA_ONLY: { lookupString: "priority", itemText: "priority", tailText: " for Thread", typeText: "Int" } // EXIST_JAVA_ONLY: { lookupString: "priority", itemText: "priority", tailText: " (from getPriority()/setPriority())", typeText: "Int" }
// EXIST_JAVA_ONLY: getPriority // EXIST_JAVA_ONLY: getPriority
// EXIST_JAVA_ONLY: setPriority // EXIST_JAVA_ONLY: setPriority
@@ -4,5 +4,5 @@ fun foo(file: File) {
file.<caret> file.<caret>
} }
// EXIST_JAVA_ONLY: { lookupString: "absolutePath", itemText: "absolutePath", tailText: " for File", typeText: "String!" } // EXIST_JAVA_ONLY: { lookupString: "absolutePath", itemText: "absolutePath", tailText: " (from getAbsolutePath())", typeText: "String!" }
// ABSENT: getAbsolutePath // ABSENT: getAbsolutePath
@@ -4,9 +4,9 @@ fun Thread.foo(urlConnection: java.net.URLConnection) {
} }
} }
// EXIST_JAVA_ONLY: { lookupString: "priority", itemText: "priority", tailText: " for Thread", typeText: "Int" } // EXIST_JAVA_ONLY: { lookupString: "priority", itemText: "priority", tailText: " (from getPriority()/setPriority())", typeText: "Int" }
// EXIST_JAVA_ONLY: { lookupString: "daemon", itemText: "daemon", tailText: " for Thread", typeText: "Boolean" } // EXIST_JAVA_ONLY: { lookupString: "daemon", itemText: "daemon", tailText: " (from isDaemon()/setDaemon())", typeText: "Boolean" }
// EXIST_JAVA_ONLY: { lookupString: "URL", itemText: "URL", tailText: " for URLConnection", typeText: "URL!" } // EXIST_JAVA_ONLY: { lookupString: "URL", itemText: "URL", tailText: " (from getURL())", typeText: "URL!" }
// ABSENT: getPriority // ABSENT: getPriority
// ABSENT: setPriority // ABSENT: setPriority
// ABSENT: isDaemon // ABSENT: isDaemon
@@ -4,5 +4,5 @@ fun foo(file: File?) {
file?.<caret> file?.<caret>
} }
// EXIST_JAVA_ONLY: { lookupString: "absolutePath", itemText: "absolutePath", tailText: " for File", typeText: "String!" } // EXIST_JAVA_ONLY: { lookupString: "absolutePath", itemText: "absolutePath", tailText: " (from getAbsolutePath())", typeText: "String!" }
// ABSENT: getAbsolutePath // ABSENT: getAbsolutePath
@@ -2,4 +2,4 @@ fun foo(javaClass: JavaClass<String>) {
javaClass.<caret> javaClass.<caret>
} }
// EXIST: { lookupString: "something", itemText: "something", tailText: " for JavaClass<String>", typeText: "String!" } // EXIST: { lookupString: "something", itemText: "something", tailText: " (from getSomething()/setSomething())", typeText: "String!" }