<commit_before>package echo.macro;
#if macro
import echo.macro.Macro.*;
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Printer;
import haxe.macro.Type.ClassField;

using haxe.macro.Context;
using echo.macro.Macro;
using StringTools;
using Lambda;

/**
 * ...
 * @author octocake1
 */
@:noCompletion
@:final
@:dce
class MacroBuilder {


	static var EXCLUDEMETA = ['skip'];
	static var COMPONENTMETA = ['component', 'c'];
	static var VIEWMETA = ['view', 'v'];
	static var ONADD_META = ['onadd'];
	static var ONREMOVE_META = ['onremove', 'onrem'];


	static public var componentIndex:Int = 0;
	static public var componentHoldersMap:Map<String, String> = new Map();


	static function hasMeta(field:Field, metas:Array<String>) {
		for (m in field.meta) for (meta in metas) if (m.name == meta) return true;
		return false;
	}

	static function getMeta(field:Field, metas:Array<String>) {
		for (m in field.meta) for (meta in metas) if (m.name == meta) return m;
		return null;
	}

	static function getClsNameID(clsname:String) {
		#if debug
			return clsname.replace('.', '_');
		#else
			return 'C' + haxe.crypto.Md5.encode(clsname).toUpperCase();
		#end
	}

	static function getClsNameSuffixByComponents(components:Array<{ name:String, cls:ComplexType }>) {
		components.map(function(c) {
			return c.name + '_' + c.cls.fullname();
		}).sort(function(a, b) {
			a = a.toLowerCase();
			b = b.toLowerCase();
			if (a < b) return -1;
			if (a > b) return 1;
			return 0;
		});
		return components.join('_');
	}


	static public function getComponentHolder(componentClsName:String):String {
		var componentCls = Context.getType(componentClsName).toComplexType();

		var componentHolderClsName = getClsNameID('ComponentHolder_' + componentCls.fullname());
		componentHoldersMap.set(componentCls.fullname(), componentHolderClsName);

		try {<commit_msg>Fix generic class names<commit_after>package echo.macro;
#if macro
import echo.macro.Macro.*;
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Printer;
import haxe.macro.Type.ClassField;

using haxe.macro.Context;
using echo.macro.Macro;
using StringTools;
using Lambda;

/**
 * ...
 * @author octocake1
 */
@:noCompletion
@:final
@:dce
class MacroBuilder {


	static var EXCLUDEMETA = ['skip'];
	static var COMPONENTMETA = ['component', 'c'];
	static var VIEWMETA = ['view', 'v'];
	static var ONADD_META = ['onadd'];
	static var ONREMOVE_META = ['onremove', 'onrem'];


	static public var componentIndex:Int = 0;
	static public var componentHoldersMap:Map<String, String> = new Map();

	static var shortenMap:Map<String, String> = new Map();


	static function hasMeta(field:Field, metas:Array<String>) {
		for (m in field.meta) for (meta in metas) if (m.name == meta) return true;
		return false;
	}

	static function getMeta(field:Field, metas:Array<String>) {
		for (m in field.meta) for (meta in metas) if (m.name == meta) return m;
		return null;
	}

	static function getClsNameID(clsname:String) {
		#if debug
			return clsname.replace('.', '_');
		#else
			var hash = haxe.crypto.Md5.encode(clsname).toUpperCase();
			if (!shortenMap.exists(hash)) shortenMap.set(hash, 'EC' + shortenMap.count());
			return shortenMap.get(hash);
		#end
	}

	static function getClsNameSuffixByComponents(components:Array<{ name:String, cls:ComplexType }>) {
		var suf = components.map(function(c) return c.name + '_' + c.cls.fullname());
		suf.sort(function(a, b) {
			a = a.toLowerCase();
			b = b.toLowerCase();
			if (a < b) return -1;
			if (a > b) return 1;
			return 0;
		});
		return suf.join('_');
	}


	static public function getComponentHolder(componentClsName:String):String {
		var componentCls = Context.getType(componentClsName).toComplexType();

		var componentHolderClsName = getClsNameID('ComponentHolder_' + componentCls.fullname());
		componentHoldersMap.set(componentCls.fullname(), componentHolderClsName);

		try {
{'fraction_non_alphanumeric': 0.1436238180424227, 'fraction_numerical': 0.003066700741119346, 'mean_word_length': 4.65606936416185, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '3078772', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1348, 'n_words': 332}