mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Refactor: Clean up Type_ classes
This commit is contained in:
@@ -216,7 +216,7 @@ class Scrib_lua_rsp_bldr {
|
||||
else if (Object_.Eq(v_type, Double_.Cls_ref_type)) Bld_double(bfr, Double_.cast(v));
|
||||
else if (Object_.Eq(v_type, Keyval[].class)) Bld_kv_ary(bfr, (Keyval[])v);
|
||||
else if (Object_.Eq(v_type, Scrib_lua_proc.class)) Bld_fnc(bfr, (Scrib_lua_proc)v);
|
||||
else throw Err_.new_unhandled(Type_adp_.NameOf_obj(v));
|
||||
else throw Err_.new_unhandled(Type_.Name_by_obj(v));
|
||||
}
|
||||
private void Bld_bool(Bry_bfr bfr, boolean v) {bfr.Add_str_a7("b:").Add_int_fixed(v ? 1 : 0, 1).Add_byte(Byte_ascii.Semic);}
|
||||
private void Bld_int(Bry_bfr bfr, int v) {bfr.Add_str_a7("i:").Add_int_variable(v).Add_byte(Byte_ascii.Semic);}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class Scrib_lua_mod {
|
||||
String prc_key = prc_kv.Key();
|
||||
Object prc_val = prc_kv.Val();
|
||||
Scrib_lua_proc fnc = null;
|
||||
if (Type_adp_.ClassOf_obj(prc_val) == Scrib_lua_proc.class)
|
||||
if (Type_.Type_by_obj(prc_val) == Scrib_lua_proc.class)
|
||||
fnc = (Scrib_lua_proc)prc_val;
|
||||
else
|
||||
fnc = new Scrib_lua_proc(prc_key, -1);
|
||||
|
||||
@@ -20,6 +20,6 @@ public class Scrib_lua_proc {
|
||||
public int Id() {return id;} private int id;
|
||||
@Override public String toString() {return key + ":" + id;}
|
||||
public static Scrib_lua_proc cast_or_null_(Object o) { // NOTE: maxStringLength and maxPatternLength return d:INF; ignore these
|
||||
return Type_adp_.ClassOf_obj(o) == Scrib_lua_proc.class ? (Scrib_lua_proc)o : null;
|
||||
return Type_.Type_by_obj(o) == Scrib_lua_proc.class ? (Scrib_lua_proc)o : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ class Luaj_value_ {
|
||||
}
|
||||
public static LuaValue Obj_to_lua_val(Luaj_server server, Object o) {
|
||||
if (o == null) return LuaValue.NIL;
|
||||
Class<?> c = Type_adp_.ClassOf_obj(o);
|
||||
Class<?> c = Type_.Type_by_obj(o);
|
||||
if (Object_.Eq(c, Bool_.Cls_ref_type)) return LuaValue.valueOf((Boolean)o);
|
||||
else if (Object_.Eq(c, Byte_.Cls_ref_type)) return LuaValue.valueOf((Byte)o);
|
||||
else if (Object_.Eq(c, Int_.Cls_ref_type)) return LuaValue.valueOf((Integer)o);
|
||||
@@ -139,11 +139,11 @@ class Luaj_value_ {
|
||||
Keyval itm = ary[i];
|
||||
LuaValue itm_val = Obj_to_lua_val(server, itm.Val());
|
||||
switch (itm.Key_tid()) {
|
||||
case Type_adp_.Tid__int:
|
||||
case Type_ids_.Id__int:
|
||||
rv.set(Int_.cast(itm.Key_as_obj()), itm_val);
|
||||
break;
|
||||
case Type_adp_.Tid__str:
|
||||
case Type_adp_.Tid__obj:
|
||||
case Type_ids_.Id__str:
|
||||
case Type_ids_.Id__obj:
|
||||
rv.set(itm.Key(), itm_val);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class Process_send_wtr {
|
||||
}
|
||||
public boolean Encode_obj(Bry_bfr bfr, Object o) {
|
||||
if (o == null) {bfr.Add(CONST_nil); return true;}
|
||||
Class<?> c = Type_adp_.ClassOf_obj(o);
|
||||
Class<?> c = Type_.Type_by_obj(o);
|
||||
if (Object_.Eq(c, Bool_.Cls_ref_type)) Encode_bool(bfr, Bool_.Cast(o));
|
||||
else if (Object_.Eq(c, Int_.Cls_ref_type)) Encode_int(bfr, Int_.cast(o));
|
||||
else if (Object_.Eq(c, Long_.Cls_ref_type)) bfr.Add_long_variable(Long_.cast(o));
|
||||
@@ -89,7 +89,7 @@ public class Process_send_wtr {
|
||||
else if (Object_.Eq(c, Scrib_lua_proc.class)) {if (!Encode_prc(bfr, (Scrib_lua_proc)o)) return false;}
|
||||
else if (Object_.Eq(c, Keyval.class)) {if (!Encode_kv(bfr, (Keyval)o)) return false;}
|
||||
else if (Object_.Eq(c, Keyval[].class)) {if (!Encode_ary(bfr, (Keyval[])o)) return false;}
|
||||
else {throw Scrib_xtn_mgr.err_("Object cannot be serialized: ~{0}", Type_adp_.NameOf_obj(o));}
|
||||
else {throw Scrib_xtn_mgr.err_("Object cannot be serialized: ~{0}", Type_.Name_by_obj(o));}
|
||||
return true;
|
||||
}
|
||||
private static final byte[] CONST_nil = Bry_.new_a7("nil"), CONST_bool_true = Bry_.new_a7("true"), CONST_bool_false = Bry_.new_a7("false"), CONST_escape_000 = Bry_.new_a7("\\000");
|
||||
|
||||
@@ -69,10 +69,10 @@ class Process_server_mock_rcvd_val implements Process_server_mock_rcvd {
|
||||
continue;
|
||||
}
|
||||
Class<?> kv_val_type = kv_val.getClass();
|
||||
boolean kv_val_is_array = Type_adp_.Eq(kv_val_type, Keyval[].class);
|
||||
boolean kv_val_is_array = Type_.Eq(kv_val_type, Keyval[].class);
|
||||
if (print_key && !kv_val_is_array)
|
||||
bfr.Add_str_u8(kv.Key()).Add_byte(Byte_ascii.Colon);
|
||||
if (Type_adp_.Eq(kv_val_type, Bool_.Cls_ref_type))
|
||||
if (Type_.Eq(kv_val_type, Bool_.Cls_ref_type))
|
||||
bfr.Add(Bool_.Cast(kv_val) ? gplx.langs.jsons.Json_itm_.Bry__true : gplx.langs.jsons.Json_itm_.Bry__false);
|
||||
else if (kv_val_is_array) {
|
||||
Keyval[] sub = (Keyval[])kv_val;
|
||||
|
||||
@@ -38,11 +38,11 @@ class Kv_ary_utl {
|
||||
private static void Ary_to_str__itm(Json_wtr wtr, int indent, Keyval itm) {
|
||||
Object val = itm.Val();
|
||||
Class<?> val_type = val.getClass();
|
||||
int type_tid = Type_adp_.To_tid_type(val_type);
|
||||
if (type_tid == Type_adp_.Tid__obj) {
|
||||
if (Type_adp_.Eq(val_type, Keyval[].class))
|
||||
int type_tid = Type_ids_.To_id_by_type(val_type);
|
||||
if (type_tid == Type_ids_.Id__obj) {
|
||||
if (Type_.Eq(val_type, Keyval[].class))
|
||||
Ary_to_str__nde(wtr, indent, itm.Key(), (Keyval[])itm.Val());
|
||||
else if (Type_adp_.Is_array(val_type))
|
||||
else if (Type_.Is_array(val_type))
|
||||
Ary_to_str__ary(wtr, indent, itm.Key(), Array_.cast(val));
|
||||
else
|
||||
throw Err_.new_unhandled(type_tid);
|
||||
@@ -65,11 +65,11 @@ class Kv_ary_utl {
|
||||
for (int j = 0; j < len; ++j) {
|
||||
Object itm = Array_.Get_at(array, j);
|
||||
Class<?> itm_type = itm.getClass();
|
||||
int itm_type_tid = Type_adp_.To_tid_type(itm_type);
|
||||
if (itm_type_tid == Type_adp_.Tid__obj) {
|
||||
if (Type_adp_.Eq(itm_type, Keyval.class))
|
||||
int itm_type_tid = Type_ids_.To_id_by_type(itm_type);
|
||||
if (itm_type_tid == Type_ids_.Id__obj) {
|
||||
if (Type_.Eq(itm_type, Keyval.class))
|
||||
Ary_to_str__itm(wtr, indent + 1, (Keyval)itm);
|
||||
else if (Type_adp_.Is_array(itm_type))
|
||||
else if (Type_.Is_array(itm_type))
|
||||
Ary_to_str__ary_itms(wtr, indent + 1, Array_.cast(itm));
|
||||
else
|
||||
throw Err_.new_unhandled(itm_type);
|
||||
|
||||
@@ -304,7 +304,7 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
}
|
||||
return (Keyval[])rv.To_ary(Keyval.class);
|
||||
}
|
||||
private static boolean Is_kv_ary(Keyval kv) {return Type_adp_.Eq_typeSafe(kv.Val(), Keyval[].class);}
|
||||
private static boolean Is_kv_ary(Keyval kv) {return Type_.Eq_by_obj(kv.Val(), Keyval[].class);}
|
||||
public boolean ExpandTemplate(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
String ttl_str = args.Pull_str(1);
|
||||
byte[] ttl_bry = Bry_.new_u8(ttl_str);
|
||||
@@ -357,7 +357,7 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
Xot_invk frame = Scrib_frame_.Get_frame(core, frame_id);
|
||||
Object ttl_obj = args.Cast_obj_or_null(1); // NOTE: callers must pass named title else title will be false; EX: frame:newChild{'current', 'title0'} -> false; frame:newChild{'current', title='title0'} -> 'title0'; DATE:2014-05-20
|
||||
Xoa_ttl ttl = null;
|
||||
if (Type_adp_.ClassOf_obj(ttl_obj) != String.class) { // title = false
|
||||
if (Type_.Type_by_obj(ttl_obj) != String.class) { // title = false
|
||||
byte[] ttl_bry = frame.Frame_ttl();
|
||||
ttl = Xoa_ttl.Parse(core.Wiki(), ttl_bry);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class Scrib_lib_text implements Scrib_lib {
|
||||
Keyval[] itm_as_nde = null;
|
||||
Object itm_as_ary = null;
|
||||
Class<?> itm_type = itm.getClass();
|
||||
boolean itm_is_nde = Type_adp_.Eq(itm_type, Keyval[].class);
|
||||
boolean itm_is_nde = Type_.Eq(itm_type, Keyval[].class);
|
||||
|
||||
// additional logic to classify "[]" as ary, not nde; note that this is done by checking len of itm_as_nde
|
||||
if (itm_is_nde) {
|
||||
|
||||
@@ -28,13 +28,13 @@ class Scrib_lib_text__json_util {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Keyval kv = kv_ary[i];
|
||||
Object kv_val = kv.Val();
|
||||
if (kv_val != null && Type_adp_.Eq(kv_val.getClass(), Keyval[].class)) {
|
||||
if (kv_val != null && Type_.Eq(kv_val.getClass(), Keyval[].class)) {
|
||||
Reindex_arrays(rv, (Keyval[])kv_val, is_encoding);
|
||||
if (!rv.Rv_is_kvy())
|
||||
kv.Val_(rv.Rv_as_ary());
|
||||
}
|
||||
if (is_sequence) {
|
||||
if (kv.Key_tid() == Type_adp_.Tid__int) {
|
||||
if (kv.Key_tid() == Type_ids_.Id__int) {
|
||||
int kv_key_as_int = Int_.cast(kv.Key_as_obj());
|
||||
is_sequence = next++ == kv_key_as_int;
|
||||
}
|
||||
@@ -161,22 +161,22 @@ class Scrib_lib_text__json_util {
|
||||
}
|
||||
private void Encode_kv(Keyval kv) {
|
||||
Object kv_val = kv.Val();
|
||||
Class<?> type = Type_adp_.ClassOf_obj(kv_val);
|
||||
if (Type_adp_.Eq(type, Keyval[].class)) {
|
||||
Class<?> type = Type_.Type_by_obj(kv_val);
|
||||
if (Type_.Eq(type, Keyval[].class)) {
|
||||
wtr.Nde_bgn(kv.Key());
|
||||
Encode_kv_ary((Keyval[])kv_val);
|
||||
wtr.Nde_end();
|
||||
}
|
||||
else if (Type_adp_.Is_array(type)) { // encode as array
|
||||
else if (Type_.Is_array(type)) { // encode as array
|
||||
wtr.Ary_bgn(kv.Key());
|
||||
Encode_ary(kv_val);
|
||||
wtr.Ary_end();
|
||||
}
|
||||
else if (Type_adp_.Eq(type, Int_.Cls_ref_type)) wtr.Kv_int(kv.Key(), Int_.cast(kv_val));
|
||||
else if (Type_adp_.Eq(type, Long_.Cls_ref_type)) wtr.Kv_long(kv.Key(), Long_.cast(kv_val));
|
||||
else if (Type_adp_.Eq(type, Float_.Cls_ref_type)) wtr.Kv_float(kv.Key(), Float_.cast(kv_val));
|
||||
else if (Type_adp_.Eq(type, Double_.Cls_ref_type)) wtr.Kv_double(kv.Key(), Double_.cast(kv_val));
|
||||
else if (Type_adp_.Eq(type, Bool_.Cls_ref_type)) wtr.Kv_bool(kv.Key(), Bool_.Cast(kv_val));
|
||||
else if (Type_.Eq(type, Int_.Cls_ref_type)) wtr.Kv_int(kv.Key(), Int_.cast(kv_val));
|
||||
else if (Type_.Eq(type, Long_.Cls_ref_type)) wtr.Kv_long(kv.Key(), Long_.cast(kv_val));
|
||||
else if (Type_.Eq(type, Float_.Cls_ref_type)) wtr.Kv_float(kv.Key(), Float_.cast(kv_val));
|
||||
else if (Type_.Eq(type, Double_.Cls_ref_type)) wtr.Kv_double(kv.Key(), Double_.cast(kv_val));
|
||||
else if (Type_.Eq(type, Bool_.Cls_ref_type)) wtr.Kv_bool(kv.Key(), Bool_.Cast(kv_val));
|
||||
else wtr.Kv_str(kv.Key(), Object_.Xto_str_strict_or_null(kv_val));
|
||||
}
|
||||
private void Encode_ary(Object ary) {
|
||||
|
||||
@@ -251,8 +251,8 @@ class Scrib_lib_json_fxt {
|
||||
private String To_str(Object o) {
|
||||
if (o == null) return "<< NULL >>";
|
||||
Class<?> type = o.getClass();
|
||||
if (Type_adp_.Eq(type, Keyval[].class)) return Kv_ary_utl.Ary_to_str(wtr, (Keyval[])o);
|
||||
else if (Type_adp_.Is_array(type)) return Array_.To_str_nested_obj(o);
|
||||
if (Type_.Eq(type, Keyval[].class)) return Kv_ary_utl.Ary_to_str(wtr, (Keyval[])o);
|
||||
else if (Type_.Is_array(type)) return Array_.To_str_nested_obj(o);
|
||||
else return Object_.Xto_str_strict_or_null(o);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
// private static final byte[] Proto_relative = Bry_.new_a7("relative");
|
||||
// private static final Hash_adp_bry proto_hash = Hash_adp_bry.ci_a7().Add_str_obj("http", Bry_.new_a7("http://")).Add_str_obj("https", Bry_.new_a7("https://")).Add_str_obj("relative", Bry_.new_a7("//")).Add_str_obj("canonical", Bry_.new_a7("1"));
|
||||
private byte[] Parse_ns(Xowe_wiki wiki, Object ns_obj) {
|
||||
if (Type_adp_.Eq_typeSafe(ns_obj, String.class))
|
||||
if (Type_.Eq_by_obj(ns_obj, String.class))
|
||||
return Bry_.new_u8(String_.cast(ns_obj));
|
||||
else {
|
||||
int ns_id = Int_.cast(ns_obj);
|
||||
|
||||
@@ -243,7 +243,7 @@ class Scrib_lib_ustring_gsub_mgr {
|
||||
tmp_repl_tid = Repl_tid_string;
|
||||
tmp_repl_bry = Bry_.new_u8(Double_.To_str(Double_.cast(repl_obj)));
|
||||
}
|
||||
else throw Err_.new_unhandled(Type_adp_.NameOf_type(repl_type));
|
||||
else throw Err_.new_unhandled(Type_.Name(repl_type));
|
||||
}
|
||||
private String Exec_repl(byte repl_tid, byte[] repl_bry, String text, String regx, int limit) {
|
||||
Regx_adp regx_mgr = Scrib_lib_ustring.RegxAdp_new_(core.Ctx(), regx);
|
||||
|
||||
@@ -479,8 +479,8 @@ class Scrib_lib_wikibase_srl_fxt {
|
||||
Object kv_val = kv.Val();
|
||||
if (kv_val == null) {bfr.Add_str_a7("null").Add_byte_nl(); return;}
|
||||
Class<?> kv_val_cls = kv_val.getClass();
|
||||
if (Type_adp_.Eq(kv_val_cls, Keyval[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (Keyval[])kv_val, depth + 1);}
|
||||
else if (Type_adp_.Eq(kv_val_cls, Keyval[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (Keyval)kv_val, depth + 1);}
|
||||
if (Type_.Eq(kv_val_cls, Keyval[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (Keyval[])kv_val, depth + 1);}
|
||||
else if (Type_.Eq(kv_val_cls, Keyval[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (Keyval)kv_val, depth + 1);}
|
||||
else bfr.Add_byte(Byte_ascii.Apos).Add_str_u8(Object_.Xto_str_strict_or_empty(kv_val)).Add_byte(Byte_ascii.Apos).Add_byte_nl();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,8 +87,8 @@ public class Scrib_proc_args {
|
||||
if (kv == null) continue;
|
||||
|
||||
// get integer-key; needed to handle gaps
|
||||
if ( kv.Key_tid() == Type_adp_.Tid__int // luaj will be int
|
||||
|| kv.Key_tid() == Type_adp_.Tid__obj) { // lua will be obj; note that luaj will also have other non-key objects
|
||||
if ( kv.Key_tid() == Type_ids_.Id__int // luaj will be int
|
||||
|| kv.Key_tid() == Type_ids_.Id__obj) { // lua will be obj; note that luaj will also have other non-key objects
|
||||
Object key_obj = kv.Key_as_obj();
|
||||
if (key_obj.getClass() == Int_.Cls_ref_type) { // key is int; cast it
|
||||
int expd_key = i + List_adp_.Base1; // EX: i=1; expd_key=2
|
||||
@@ -127,7 +127,7 @@ public class Scrib_proc_args {
|
||||
public byte[][] Cast_params_as_bry_ary_or_rest_of_ary(int params_idx) { // PAGE:ru.w:Ленин,_Владимир_Ильич; DATE:2014-07-01 MW:LanguageLibrary.php|ConvertPlural: if (is_array($args[0])) $args = $args[0]; $forms = array_values(array_map('strval', $args));
|
||||
if (params_idx < 0 || params_idx >= ary_len) return Bry_.Ary_empty;
|
||||
Object o = ary[params_idx].Val();
|
||||
if (Type_adp_.Eq_typeSafe(o, Keyval[].class)) {
|
||||
if (Type_.Eq_by_obj(o, Keyval[].class)) {
|
||||
Keyval[] tbl = (Keyval[])o;
|
||||
int rv_len = tbl.length;
|
||||
byte[][] rv = new byte[rv_len][];
|
||||
@@ -152,7 +152,7 @@ public class Scrib_proc_args {
|
||||
public byte[] Extract_qry_args(Xowe_wiki wiki, int idx) {
|
||||
Object qry_args_obj = Cast_obj_or_null(idx);
|
||||
if (qry_args_obj == null) return Bry_.Empty;
|
||||
Class<?> qry_args_cls = Type_adp_.ClassOf_obj(qry_args_obj);
|
||||
Class<?> qry_args_cls = Type_.Type_by_obj(qry_args_obj);
|
||||
if (qry_args_cls == String.class)
|
||||
return Bry_.new_u8((String)qry_args_obj);
|
||||
else if (qry_args_cls == Keyval[].class) {
|
||||
@@ -169,7 +169,7 @@ public class Scrib_proc_args {
|
||||
return bfr.To_bry_and_rls();
|
||||
}
|
||||
else {
|
||||
wiki.Appe().Usr_dlg().Warn_many("", "", "unknown type for GetUrl query args: ~{0}", Type_adp_.NameOf_type(qry_args_cls));
|
||||
wiki.Appe().Usr_dlg().Warn_many("", "", "unknown type for GetUrl query args: ~{0}", Type_.Name(qry_args_cls));
|
||||
return Bry_.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user