More informative presentation of synthetic properties in completion
This commit is contained in:
+30
-20
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaBeansPropertyDescriptor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
|
||||
@@ -216,27 +217,36 @@ public class LookupElementFactory(
|
||||
}
|
||||
|
||||
if (descriptor is CallableDescriptor) {
|
||||
if (descriptor.getExtensionReceiverParameter() != null) {
|
||||
val originalReceiver = descriptor.getOriginal().getExtensionReceiverParameter()!!
|
||||
val receiverPresentation = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(originalReceiver.getType())
|
||||
element = element.appendTailText(" for $receiverPresentation", 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)
|
||||
when {
|
||||
descriptor is SyntheticJavaBeansPropertyDescriptor -> {
|
||||
var from = descriptor.getMethod.getName().asString() + "()"
|
||||
descriptor.setMethod?.let { from += "/" + it.getName().asString() + "()" }
|
||||
element = element.appendTailText(" (from $from)", 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)
|
||||
|
||||
descriptor.getExtensionReceiverParameter() != null -> {
|
||||
val originalReceiver = descriptor.getOriginal().getExtensionReceiverParameter()!!
|
||||
val receiverPresentation = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(originalReceiver.getType())
|
||||
element = element.appendTailText(" for $receiverPresentation", 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,6 +3,6 @@ fun foo(thread: Thread) {
|
||||
}
|
||||
|
||||
// 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: setPriority
|
||||
|
||||
+1
-1
@@ -4,5 +4,5 @@ fun foo(file: File) {
|
||||
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
|
||||
|
||||
+3
-3
@@ -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: "daemon", itemText: "daemon", tailText: " for Thread", typeText: "Boolean" }
|
||||
// EXIST_JAVA_ONLY: { lookupString: "URL", itemText: "URL", tailText: " for URLConnection", typeText: "URL!" }
|
||||
// EXIST_JAVA_ONLY: { lookupString: "priority", itemText: "priority", tailText: " (from getPriority()/setPriority())", typeText: "Int" }
|
||||
// EXIST_JAVA_ONLY: { lookupString: "daemon", itemText: "daemon", tailText: " (from isDaemon()/setDaemon())", typeText: "Boolean" }
|
||||
// EXIST_JAVA_ONLY: { lookupString: "URL", itemText: "URL", tailText: " (from getURL())", typeText: "URL!" }
|
||||
// ABSENT: getPriority
|
||||
// ABSENT: setPriority
|
||||
// ABSENT: isDaemon
|
||||
|
||||
+1
-1
@@ -4,5 +4,5 @@ fun foo(file: File?) {
|
||||
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
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@ fun foo(javaClass: JavaClass<String>) {
|
||||
javaClass.<caret>
|
||||
}
|
||||
|
||||
// EXIST: { lookupString: "something", itemText: "something", tailText: " for JavaClass<String>", typeText: "String!" }
|
||||
// EXIST: { lookupString: "something", itemText: "something", tailText: " (from getSomething()/setSomething())", typeText: "String!" }
|
||||
|
||||
Reference in New Issue
Block a user