Youssef Shoaib [MOD]
03/21/2025, 4:29 PMimpure
! I'm writing an IntelliJ plugin, and impure
is a perfect fit for the Visitor pattern.Youssef Shoaib [MOD]
03/21/2025, 4:31 PMoverride fun visitSimpleNameExpression(expression: KtSimpleNameExpression) = impure {
super.visitSimpleNameExpression(expression)
ensure(expression.parent !is KtThisExpression && expression.parent !is KtSuperExpression && expression !is KtLabelReferenceExpression)
analyze(expression) {
val reference = expression.mainReference.resolveToSymbol()
ensure(reference is KaAnnotated)
val annotation = reference.annotations[PRETTY].singleOrNull().bind()
val name = annotation.findConstantArgument(PRETTY_NAME)
ensure(name is String)
add(PrettyFoldingDescriptor(expression, name))
}
}
CLOVIS
03/25/2025, 9:23 AMCLOVIS
03/25/2025, 9:23 AMnullable {
ignoreErrors {
}
}
?Youssef Shoaib [MOD]
03/25/2025, 12:18 PMnullable
but always returns Unit
, so both the error side and success side are Unit
CLOVIS
03/25/2025, 12:23 PMCLOVIS
03/25/2025, 12:23 PMCLOVIS
03/25/2025, 12:23 PMYoussef Shoaib [MOD]
03/25/2025, 12:24 PMreturn
a whole bunch of times, but ensure
and bind
are cleanerCLOVIS
03/25/2025, 12:29 PM