KT-8574 'Convert to block body' inserts spurious < token

#KT-8574 Fixed
This commit is contained in:
Valentin Kipyatkov
2015-07-24 21:21:52 +03:00
parent e09fadae51
commit 977bf593e0
11 changed files with 88 additions and 5 deletions
@@ -16,17 +16,34 @@
package org.jetbrains.kotlin.idea.util
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier
import org.jetbrains.kotlin.renderer.NameShortness
import org.jetbrains.kotlin.renderer.OverrideRenderingPolicy
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.isDynamic
public object IdeDescriptorRenderers {
public val APPROXIMATE_FLEXIBLE_TYPES: (JetType) -> JetType = { approximateFlexibleTypes(it, true) }
public val APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS: (JetType) -> JetType = { approximateFlexibleTypes(it, false) }
private fun unwrapAnonymousType(type: JetType): JetType {
if (type.isDynamic()) return type
val classifier = type.constructor.declarationDescriptor
if (classifier != null && !classifier.name.isSpecial) return type
type.constructor.supertypes.singleOrNull()?.let { return it }
val builtIns = KotlinBuiltIns.getInstance()
return if (type.isMarkedNullable)
builtIns.nullableAnyType
else
builtIns.anyType
}
private val BASE: DescriptorRenderer = DescriptorRenderer.withOptions {
normalizedVisibilities = true
withDefinedIn = false
@@ -38,16 +55,16 @@ public object IdeDescriptorRenderers {
public val SOURCE_CODE: DescriptorRenderer = BASE.withOptions {
nameShortness = NameShortness.SOURCE_CODE_QUALIFIED
typeNormalizer = APPROXIMATE_FLEXIBLE_TYPES
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES(unwrapAnonymousType(it)) }
}
public val SOURCE_CODE_FOR_TYPE_ARGUMENTS: DescriptorRenderer = BASE.withOptions {
nameShortness = NameShortness.SOURCE_CODE_QUALIFIED
typeNormalizer = APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS(unwrapAnonymousType(it)) }
}
public val SOURCE_CODE_SHORT_NAMES_IN_TYPES: DescriptorRenderer = BASE.withOptions {
nameShortness = NameShortness.SHORT
typeNormalizer = APPROXIMATE_FLEXIBLE_TYPES
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES(unwrapAnonymousType(it)) }
}
}