Strip type annotations from TypeRenderer and asTypeBlock() (#1039)

Resolves #1033
This commit is contained in:
Zac Sweers
2019-12-05 22:35:57 +01:00
committed by GitHub
parent 0dfea712bb
commit 32c5d48ab1
3 changed files with 22 additions and 1 deletions

View File

@@ -41,6 +41,9 @@ abstract class TypeRenderer {
abstract fun renderTypeVariable(typeVariable: TypeVariableName): CodeBlock
fun render(typeName: TypeName, forceBox: Boolean = false): CodeBlock {
if (typeName.annotations.isNotEmpty()) {
return render(typeName.copy(annotations = emptyList()), forceBox)
}
if (typeName.isNullable) {
return renderObjectType(typeName.copy(nullable = false))
}

View File

@@ -62,6 +62,9 @@ internal fun TypeName.defaultPrimitiveValue(): CodeBlock =
}
internal fun TypeName.asTypeBlock(): CodeBlock {
if (annotations.isNotEmpty()) {
return copy(annotations = emptyList()).asTypeBlock()
}
when (this) {
is ParameterizedTypeName -> {
return if (rawType == ARRAY) {
@@ -143,4 +146,4 @@ internal fun TypeName.stripTypeVarVariance(): TypeName {
return mapTypes<TypeVariableName> {
TypeVariableName(name = name, bounds = bounds.map { it.mapTypes(TypeVariableName::stripTypeVarVariance) }, variance = null)
}
}
}