<commit_before>package org.velocity4s

import scala.collection.{GenMapLike, GenSeqLike}
import scala.collection.JavaConverters._

import java.lang.reflect.Method

import org.apache.velocity.util.introspection.{Info, UberspectImpl, VelMethod, VelPropertyGet}

object ScalaUberspect {
  private val GET_METHOD_NAME = "get"
}

class ScalaUberspect extends UberspectImpl {
  override def getIterator(obj: Object, i: Info): java.util.Iterator[_] =
    obj match {
      case option: Option[_] => option.iterator.asJava
      case mapLike: GenMapLike[_, _, _] => mapLike.values.iterator.asJava
      case iterable: Iterable[_] => iterable.iterator.asJava
      case iterator: Iterator[_] => iterator.asJava
      case _ => super.getIterator(obj, i)
    }

  override def getMethod(obj: AnyRef, methodName: String, args: Array[AnyRef], i: Info): VelMethod =
    (obj, methodName) match {
      case (_: GenSeqLike[_, _], ScalaUberspect.GET_METHOD_NAME) if args.size == 1 =>
        super.getMethod(obj, "apply", args, i)
      case (_: GenMapLike[_, _, _], ScalaUberspect.GET_METHOD_NAME) if args.size == 1 =>
        val method = introspector.getMethod(obj.getClass, methodName, args)
        new MapApplyVelMethod(method)
      case _ =>
        super.getMethod(obj, methodName, args, i)
    }

  override def getPropertyGet(obj: AnyRef, identifier: String, i: Info): VelPropertyGet = {
    Option(obj)
      .map {
        case map: GenMapLike[_, _, _] => new ScalaMapGetExecutor(log, obj.getClass, identifier)
        case _ => new ScalaPropertyExecutor(log, introspector, obj.getClass, identifier)
      }.map { executor =>
        if (executor.isAlive)
          new UberspectImpl.VelGetterImpl(executor)
        else
          super.getPropertyGet(obj, identifier, i)
      }.getOrElse(null)
  }<commit_msg>fix captured variable name<commit_after>package org.velocity4s

import scala.collection.{GenMapLike, GenSeqLike}
import scala.collection.JavaConverters._

import java.lang.reflect.Method

import org.apache.velocity.util.introspection.{Info, UberspectImpl, VelMethod, VelPropertyGet}

object ScalaUberspect {
  private val GET_METHOD_NAME = "get"
}

class ScalaUberspect extends UberspectImpl {
  override def getIterator(obj: Object, i: Info): java.util.Iterator[_] =
    obj match {
      case option: Option[_] => option.iterator.asJava
      case map: GenMapLike[_, _, _] => map.values.iterator.asJava
      case iterable: Iterable[_] => iterable.iterator.asJava
      case iterator: Iterator[_] => iterator.asJava
      case _ => super.getIterator(obj, i)
    }

  override def getMethod(obj: AnyRef, methodName: String, args: Array[AnyRef], i: Info): VelMethod =
    (obj, methodName) match {
      case (_: GenSeqLike[_, _], ScalaUberspect.GET_METHOD_NAME) if args.size == 1 =>
        super.getMethod(obj, "apply", args, i)
      case (_: GenMapLike[_, _, _], ScalaUberspect.GET_METHOD_NAME) if args.size == 1 =>
        val method = introspector.getMethod(obj.getClass, methodName, args)
        new MapApplyVelMethod(method)
      case _ =>
        super.getMethod(obj, methodName, args, i)
    }

  override def getPropertyGet(obj: AnyRef, identifier: String, i: Info): VelPropertyGet = {
    Option(obj)
      .map {
        case map: GenMapLike[_, _, _] => new ScalaMapGetExecutor(log, obj.getClass, identifier)
        case _ => new ScalaPropertyExecutor(log, introspector, obj.getClass, identifier)
      }.map { executor =>
        if (executor.isAlive)
          new UberspectImpl.VelGetterImpl(executor)
        else
          super.getPropertyGet(obj, identifier, i)
      }.getOrElse(null)
  }
{'fraction_non_alphanumeric': 0.11329096435479415, 'fraction_numerical': 0.0016579165515335729, 'mean_word_length': 3.536340852130326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '6438691', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1136, 'n_words': 261}