Refactoring: extracted several functions to make kotlin compile

This commit is contained in:
Svetlana Isakova
2015-01-26 14:39:00 +03:00
parent 279f09ee45
commit 0f370a7cf6
@@ -338,35 +338,38 @@ public object Renderers {
}.toString() }.toString()
} }
public val RENDER_COLLECTION_OF_TYPES: Renderer<Collection<JetType>> = Renderer { private fun renderTypes(types: Collection<JetType>) = StringUtil.join(types, { RENDER_TYPE.render(it) }, ", ")
types -> StringUtil.join(types, { RENDER_TYPE.render(it) }, ", ")
}
public val RENDER_CONSTRAINT_SYSTEM: Renderer<ConstraintSystem> = Renderer { public val RENDER_COLLECTION_OF_TYPES: Renderer<Collection<JetType>> = Renderer { renderTypes(it) }
(constraintSystem) ->
private fun renderConstraintSystem(constraintSystem: ConstraintSystem): String {
val typeVariables = constraintSystem.getTypeVariables() val typeVariables = constraintSystem.getTypeVariables()
val typeBounds = Sets.newLinkedHashSet<TypeBounds>() val typeBounds = Sets.newLinkedHashSet<TypeBounds>()
for (variable in typeVariables) { for (variable in typeVariables) {
typeBounds.add(constraintSystem.getTypeBounds(variable)) typeBounds.add(constraintSystem.getTypeBounds(variable))
} }
"type parameter bounds:\n" + StringUtil.join(typeBounds, { RENDER_TYPE_BOUNDS.render(it) }, "\n") + "\n" + "status:\n" + return "type parameter bounds:\n" +
ConstraintsUtil.getDebugMessageForStatus(constraintSystem.getStatus()) StringUtil.join(typeBounds, { RENDER_TYPE_BOUNDS.render(it) }, "\n") + "\n" + "status:\n" +
ConstraintsUtil.getDebugMessageForStatus(constraintSystem.getStatus())
} }
public val RENDER_TYPE_BOUNDS: Renderer<TypeBounds> = Renderer { public val RENDER_CONSTRAINT_SYSTEM: Renderer<ConstraintSystem> = Renderer { renderConstraintSystem(it) }
typeBounds ->
private fun renderTypeBounds(typeBounds: TypeBounds): String {
val renderBound = { (bound: Bound) -> val renderBound = { (bound: Bound) ->
val arrow = if (bound.kind == LOWER_BOUND) ">: " else if (bound.kind == UPPER_BOUND) "<: " else ":= " val arrow = if (bound.kind == LOWER_BOUND) ">: " else if (bound.kind == UPPER_BOUND) "<: " else ":= "
arrow + RENDER_TYPE.render(bound.constrainingType) + '(' + bound.position + ')' arrow + RENDER_TYPE.render(bound.constrainingType) + '(' + bound.position + ')'
} }
val typeVariableName = typeBounds.typeVariable.getName() val typeVariableName = typeBounds.typeVariable.getName()
if (typeBounds.isEmpty()) { return if (typeBounds.isEmpty()) {
typeVariableName.asString() typeVariableName.asString()
} }
else else
"$typeVariableName ${StringUtil.join(typeBounds.bounds, renderBound, ", ")}" "$typeVariableName ${StringUtil.join(typeBounds.bounds, renderBound, ", ")}"
} }
public val RENDER_TYPE_BOUNDS: Renderer<TypeBounds> = Renderer { renderTypeBounds(it) }
private fun renderDebugMessage(message: String, inferenceErrorData: InferenceErrorData) = StringBuilder { private fun renderDebugMessage(message: String, inferenceErrorData: InferenceErrorData) = StringBuilder {
append(message) append(message)
append("\nConstraint system: \n") append("\nConstraint system: \n")
@@ -384,6 +387,6 @@ public object Renderers {
if (inferenceErrorData.receiverArgumentType != null) { if (inferenceErrorData.receiverArgumentType != null) {
append(RENDER_TYPE.render(inferenceErrorData.receiverArgumentType)).append(".") append(RENDER_TYPE.render(inferenceErrorData.receiverArgumentType)).append(".")
} }
append("(").append(StringUtil.join(inferenceErrorData.valueArgumentsTypes, { RENDER_TYPE.render(it) }, ", ")).append(")") append("(").append(renderTypes(inferenceErrorData.valueArgumentsTypes)).append(")")
}.toString() }.toString()
} }