use short names in Show Expression Type
#KT-11310 Fixed
This commit is contained in:
@@ -23,10 +23,15 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.RenderingFormat
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
||||
|
||||
class KotlinExpressionTypeProvider : ExpressionTypeProvider<KtExpression>() {
|
||||
private val typeRenderer = DescriptorRenderer.COMPACT_WITH_SHORT_TYPES.withOptions {
|
||||
textFormat = RenderingFormat.HTML
|
||||
}
|
||||
|
||||
override fun getExpressionsAt(elementAt: PsiElement): List<KtExpression> =
|
||||
elementAt.parentsWithSelf.filterIsInstance<KtExpression>().filter { it.shouldShowType() }.toList()
|
||||
|
||||
@@ -47,12 +52,12 @@ class KotlinExpressionTypeProvider : ExpressionTypeProvider<KtExpression>() {
|
||||
if (element is KtCallableDeclaration) {
|
||||
val descriptor = bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, element] as? CallableDescriptor
|
||||
if (descriptor != null) {
|
||||
return descriptor.returnType?.let { DescriptorRenderer.HTML.renderType(it) } ?: "Type is unknown"
|
||||
return descriptor.returnType?.let { typeRenderer.renderType(it) } ?: "Type is unknown"
|
||||
}
|
||||
}
|
||||
|
||||
val expressionType = element.getType(bindingContext) ?: return "Type is unknown"
|
||||
val result = DescriptorRenderer.HTML.renderType(expressionType)
|
||||
val result = typeRenderer.renderType(expressionType)
|
||||
val smartCast = bindingContext[BindingContext.SMARTCAST, element]
|
||||
if (smartCast != null) {
|
||||
return result + " (smart cast)"
|
||||
|
||||
@@ -2,4 +2,4 @@ fun foo() {
|
||||
val <caret>x = 1
|
||||
}
|
||||
|
||||
// TYPE: val x = 1 -> <html>kotlin.Int</html>
|
||||
// TYPE: val x = 1 -> <html>Int</html>
|
||||
|
||||
@@ -4,4 +4,4 @@ fun f(x: IntStringPair) {
|
||||
val (fir<caret>st, second) = x
|
||||
}
|
||||
|
||||
// TYPE: first -> <html>kotlin.Int</html>
|
||||
// TYPE: first -> <html>Int</html>
|
||||
|
||||
+3
-3
@@ -4,6 +4,6 @@ fun foo(x: Any) {
|
||||
}
|
||||
}
|
||||
|
||||
// TYPE: if (x is String) { x.length } -> <html>kotlin.Unit</html>
|
||||
// TYPE: x -> <html>kotlin.String (smart cast)</html>
|
||||
// TYPE: x.length -> <html>kotlin.Int</html>
|
||||
// TYPE: if (x is String) { x.length } -> <html>Unit</html>
|
||||
// TYPE: x -> <html>String (smart cast)</html>
|
||||
// TYPE: x.length -> <html>Int</html>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
val <caret>x = 1
|
||||
|
||||
// TYPE: val x = 1 -> <html>kotlin.Int</html>
|
||||
// TYPE: val x = 1 -> <html>Int</html>
|
||||
|
||||
Reference in New Issue
Block a user