<commit_before>package thx.core.error;

import haxe.PosInfos;

class NullArgument extends thx.core.Error {
  public function new(message : String, ?posInfo : PosInfos)
    super(message, posInfo);

  macro public static function throwIfNull<T>(expr : ExprOf<Null<T>>) {
    var name = switch expr.expr {
      case EMeta({name:':this'},{expr:EConst(CIdent(s))}): s;
      case EConst(CIdent(s)): s;
      case _: haxe.macro.Context.error("argument must be an identifier", expr.pos);
    };

    return macro if(null == $e{expr}) throw new thx.core.error.NullArgument('argument "$name" cannot be null');
  }

  macro public static function throwIfEmpty(expr : haxe.macro.Expr) {
    var name = switch expr.expr {
      case EMeta({name:':this'},{expr:EConst(CIdent(s))}): s;
      case EConst(CIdent(s)): s;
      case _: haxe.macro.Context.error("argument must be an identifier", expr.pos);
    };

    switch haxe.macro.Context.typeof(expr) {
      case TInst(c, _) if(c.toString() == "Array"):
        return macro
          if(null == $e{expr})
            throw new thx.core.error.NullArgument('Array argument "$name" cannot be null')
          else if($e{expr}.length == 0)
            throw new thx.core.error.NullArgument('Array argument "$name" cannot be empty');
      case TInst(c, _) if(c.toString() == "String"):
        return macro
          if(null == $e{expr})
            throw new thx.core.error.NullArgument('String argument "$name" cannot be null')
          else if($e{expr} == "")
            throw new thx.core.error.NullArgument('String argument "$name" cannot be empty');
      case TType(c, _) if(c.toString() == "Iterator"):
        return macro {
          var it = $e{expr};
          if(null == it)
            throw new thx.core.error.NullArgument('Iterator argument "$name" cannot be null')
          else if(!it.hasNext())
            throw new thx.core.error.NullArgument('Iterator argument "$name" cannot be empty');
        }
      case TType(c, _) if(c.toString() == "Iterable"):
        return macro {
          var it = $e{expr};
          if(null == it)
            throw new thx.core.error.NullArgument('Iterable argument "$name" cannot be null')
          else if(!it.iterator().hasNext())
            throw new thx.core.error.NullArgument('Iterable argument "$name" cannot be empty');
        }
      case _:
        return haxe.macro.Context.error("argument type must be a String, an Array, an Iterator or an Iterable", expr.pos);
    }
  }
}<commit_msg>simplified implementation of NullArgument<commit_after>package thx.core.error;

import haxe.PosInfos;

class NullArgument extends thx.core.Error {
  public function new(message : String, ?posInfo : PosInfos)
    super(message, posInfo);

  macro public static function throwIfNull<T>(expr : ExprOf<Null<T>>) {
    var name = switch expr.expr {
      case EMeta({name:':this'},{expr:EConst(CIdent(s))}): s;
      case EConst(CIdent(s)): s;
      case _: haxe.macro.Context.error("argument must be an identifier", expr.pos);
    };

    return macro if(null == $e{expr}) throw new thx.core.error.NullArgument('argument "$name" cannot be null');
  }

  macro public static function throwIfEmpty(expr : haxe.macro.Expr) {
    var name = switch expr.expr {
      case EMeta({name:':this'},{expr:EConst(CIdent(s))}): s;
      case EConst(CIdent(s)): s;
      case _: haxe.macro.Context.error("argument must be an identifier", expr.pos);
    };

    switch haxe.macro.Context.typeof(expr) {
      case TInst(_.toString() => "Array", _):
        return macro
          if(null == $e{expr})
            throw new thx.core.error.NullArgument('Array argument "$name" cannot be null')
          else if($e{expr}.length == 0)
            throw new thx.core.error.NullArgument('Array argument "$name" cannot be empty');
      case TInst(_.toString() => "String", _):
        return macro
          if(null == $e{expr})
            throw new thx.core.error.NullArgument('String argument "$name" cannot be null')
          else if($e{expr} == "")
            throw new thx.core.error.NullArgument('String argument "$name" cannot be empty');
      case TType(_.toString() => "Iterator", _):
        return macro {
          var it = $e{expr};
          if(null == it)
            throw new thx.core.error.NullArgument('Iterator argument "$name" cannot be null')
          else if(!it.hasNext())
            throw new thx.core.error.NullArgument('Iterator argument "$name" cannot be empty');
        }
      case TType(_.toString() => "Iterable", _):
        return macro {
          var it = $e{expr};
          if(null == it)
            throw new thx.core.error.NullArgument('Iterable argument "$name" cannot be null')
          else if(!it.iterator().hasNext())
            throw new thx.core.error.NullArgument('Iterable argument "$name" cannot be empty');
        }
      case _:
        return haxe.macro.Context.error("argument type must be a String, an Array, an Iterator or an Iterable", expr.pos);
    }
  }
}
{'fraction_non_alphanumeric': 0.1432, 'fraction_numerical': 0.0004, 'mean_word_length': 2.7376681614349776, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '1865117', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1498, 'n_words': 421}