1 | // TODO: optimize (use getOpt_cache) |
2 | static void setOpt_raw(Object o, String field, Object value) ctex { |
3 | if (o == null) ret; |
4 | if (o instanceof Class) setOpt_raw((Class) o, field, value); |
5 | else { |
6 | Field f = setOpt_raw_findField(o.getClass(), field); |
7 | if (f != null) { |
8 | makeAccessible(f); |
9 | smartSet(f, o, value); |
10 | } |
11 | } |
12 | } |
13 | |
14 | static void setOpt_raw(Class c, String field, Object value) ctex { |
15 | if (c == null) ret; |
16 | Field f = setOpt_raw_findStaticField(c, field); |
17 | if (f != null) { |
18 | makeAccessible(f); |
19 | smartSet(f, null, value); |
20 | } |
21 | } |
22 | |
23 | static Field setOpt_raw_findStaticField(Class<?> c, String field) { |
24 | Class _c = c; |
25 | do { |
26 | for (Field f : _c.getDeclaredFields()) |
27 | if (f.getName().equals(field) && (f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0) |
28 | return f; |
29 | _c = _c.getSuperclass(); |
30 | } while (_c != null); |
31 | ret null; |
32 | } |
33 | |
34 | static Field setOpt_raw_findField(Class<?> c, String field) { |
35 | Class _c = c; |
36 | do { |
37 | for (Field f : _c.getDeclaredFields()) |
38 | if (f.getName().equals(field)) |
39 | return f; |
40 | _c = _c.getSuperclass(); |
41 | } while (_c != null); |
42 | ret null; |
43 | } |
Began life as a copy of #1000891
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney
No comments. add comment
Snippet ID: | #1009441 |
Snippet name: | setOpt_raw function (set field by reflection, ignore if it's a Map) |
Eternal ID of this version: | #1009441/7 |
Text MD5: | 6b6e028568c249a30bc637a56829607a |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-03-03 17:54:04 |
Source code size: | 1175 bytes / 43 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 556 / 699 |
Version history: | 6 change(s) |
Referenced in: | [show references] |