Does anyone know if there is a way within the comp...
# compiler
r
Does anyone know if there is a way within the compiler apis to evaluate a KtExpression that does not require instantiating and bringing in the script-utils with the ScriptEngineFactory?
s
there's certain
Copy code
ConstantExpressionEvaluator.getConstant(expression: KtExpression, bindingContext: BindingContext): CompileTimeConstant<*>?
I used it once when playing around with compile time strings, it not always works because of specifics of implementation šŸ˜…
Oh, I meant
Copy code
ConstantExpressionEvaluator.evaluateExpression(
        expression: KtExpression,
        trace: BindingTrace,
        expectedType: KotlinType?
)\: CompileTimeConstant<*>?
r
thanks!, tried that but couldn’t resolve symbols like ā€œā€.startsWith as it expects to be in the shape of a constant already and I’m trying to evaluate more complex expressions
s
That's what I meant when said it does not always work :)
šŸ‘ 1