public static boolean evaluateExpression(NavFrameOwner owner, CALExpression expression, StringBuilder result) {
// Check for old example format..
if (expression.getQualifiedExpressionText().equals("") && expression.getExpressionText().length()>0) {
// Expression has not been qualified
CompilerMessageLogger messageLogger = new MessageLogger();
CALExpression qualifiedExpression = qualifyExpression(owner, expression, messageLogger);
if ((qualifiedExpression == null) && (result != null)) {
result.append(messageLogger.getFirstError().getMessage());
return false;
}
}
String expressionText = expression.getQualifiedExpressionText();
CompilerMessageLogger messageLogger = new MessageLogger();
SourceModel.Expr expressionSourceModel = SourceModelUtilities.TextParsing.parseExprIntoSourceModel(expressionText, messageLogger);
if (messageLogger.getNErrors() > 0) {
// The expression could not be parsed.
result.append(messageLogger.getFirstError().getMessage());
return false;
}
Target expressionTarget = new Target.SimpleTarget(expressionSourceModel);
ModuleName expressionModule = expression.getModuleContext();
AdjunctSource expressionDef = expressionTarget.getTargetDef(null, owner.getTypeChecker().getTypeCheckInfo(expressionModule).getModuleTypeInfo());
TypeExpr resultType = owner.getTypeChecker().checkFunction(expressionDef, expressionModule, messageLogger);
if (resultType == null) {
// The type checker couldn't figure out the type.
result.append(messageLogger.getFirstError().getMessage());
return false;
}
try {
// Now create a target to be run by a value runner.