<commit_before>package pl.touk.nussknacker.engine.spel

import cats.data.Validated
import org.springframework.expression.Expression
import org.springframework.expression.spel.ast._
import org.springframework.expression.spel.{SpelNode, standard}
import pl.touk.nussknacker.engine.compile.{ValidatedSyntax, ValidationContext}
import pl.touk.nussknacker.engine.compiledgraph.expression
import pl.touk.nussknacker.engine.compiledgraph.expression.ExpressionParseError
import pl.touk.nussknacker.engine.definition.DefinitionExtractor.ClazzRef

class SpelExpressionValidator(expr: Expression, ctx: ValidationContext) {
  import SpelExpressionValidator._
  import cats.instances.list._

  private val syntax = ValidatedSyntax[ExpressionParseError]
  import syntax._

  private val ignoredTypes: Set[ClazzRef] = Set(
    classOf[java.util.Map[_, _]],
    classOf[scala.collection.convert.Wrappers.MapWrapper[_, _]],
    classOf[Any]
  ).map(ClazzRef.apply)

  def validate(): Validated[ExpressionParseError, Expression] = {
    val ast = expr.asInstanceOf[standard.SpelExpression].getAST
    resolveReferences(ast).andThen { _ =>
      findAllPropertyAccess(ast, None, None).andThen { propertyAccesses =>
        propertyAccesses.flatMap(validatePropertyAccess).headOption match {
          case Some(error) => Validated.invalid(error)
          case None => Validated.valid(expr)
        }
      }
    }
  }

  private def resolveReferences(node: SpelNode): Validated[ExpressionParseError, Expression] = {
    val references = findAllVariableReferences(node)
    val notResolved = references.filterNot(ctx.contains)
    if (notResolved.isEmpty) Validated.valid(expr)
    else Validated.Invalid(ExpressionParseError(s"Unresolved references ${notResolved.mkString(", ")}"))
  }
<commit_msg>ignoring object and anyref during validation<commit_after>package pl.touk.nussknacker.engine.spel

import cats.data.Validated
import org.springframework.expression.Expression
import org.springframework.expression.spel.ast._
import org.springframework.expression.spel.{SpelNode, standard}
import pl.touk.nussknacker.engine.compile.{ValidatedSyntax, ValidationContext}
import pl.touk.nussknacker.engine.compiledgraph.expression
import pl.touk.nussknacker.engine.compiledgraph.expression.ExpressionParseError
import pl.touk.nussknacker.engine.definition.DefinitionExtractor.ClazzRef

class SpelExpressionValidator(expr: Expression, ctx: ValidationContext) {
  import SpelExpressionValidator._
  import cats.instances.list._

  private val syntax = ValidatedSyntax[ExpressionParseError]
  import syntax._

  private val ignoredTypes: Set[ClazzRef] = Set(
    classOf[java.util.Map[_, _]],
    classOf[scala.collection.convert.Wrappers.MapWrapper[_, _]],
    classOf[Any],
    classOf[Object],
    classOf[AnyRef]
  ).map(ClazzRef.apply)

  def validate(): Validated[ExpressionParseError, Expression] = {
    val ast = expr.asInstanceOf[standard.SpelExpression].getAST
    resolveReferences(ast).andThen { _ =>
      findAllPropertyAccess(ast, None, None).andThen { propertyAccesses =>
        propertyAccesses.flatMap(validatePropertyAccess).headOption match {
          case Some(error) => Validated.invalid(error)
          case None => Validated.valid(expr)
        }
      }
    }
  }

  private def resolveReferences(node: SpelNode): Validated[ExpressionParseError, Expression] = {
    val references = findAllVariableReferences(node)
    val notResolved = references.filterNot(ctx.contains)
    if (notResolved.isEmpty) Validated.valid(expr)
    else Validated.Invalid(ExpressionParseError(s"Unresolved references ${notResolved.mkString(", ")}"))
  }

{'fraction_non_alphanumeric': 0.10184420589044867, 'fraction_numerical': 0.0, 'mean_word_length': 5.076923076923077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5111874', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1038, 'n_words': 173}