1 | static Object getOptIgnoreCase(O o, S field) { |
2 | if (o instanceof S) o = getBot((S) o); |
3 | if (o == null) ret null; |
4 | if (o instanceof Class) return getOptIgnoreCase((Class) o, field); |
5 | |
6 | if (o.getClass().getName().equals("main$DynamicObject")) |
7 | fail("not implemented"); |
8 | |
9 | if (o instanceof Map) ret lookupIgnoreCase((Map) o, field); |
10 | |
11 | ret getOptIgnoreCase_raw(o, field); |
12 | } |
13 | |
14 | static Object getOptIgnoreCase_raw(Object o, String field) { |
15 | try { |
16 | Field f = getOptIgnoreCase_findField(o.getClass(), field); |
17 | if (f == null) ret null; |
18 | f.setAccessible(true); |
19 | return f.get(o); |
20 | } catch (Exception e) { |
21 | throw new RuntimeException(e); |
22 | } |
23 | } |
24 | |
25 | static Object getOptIgnoreCase(Class c, String field) { |
26 | try { |
27 | Field f = getOptIgnoreCase_findStaticField(c, field); |
28 | if (f == null) ret null; |
29 | f.setAccessible(true); |
30 | return f.get(null); |
31 | } catch (Exception e) { |
32 | throw new RuntimeException(e); |
33 | } |
34 | } |
35 | |
36 | static Field getOptIgnoreCase_findStaticField(Class<?> c, String field) { |
37 | Class _c = c; |
38 | do { |
39 | for (Field f : _c.getDeclaredFields()) |
40 | if (eqic(f.getName(), field) && (f.getModifiers() & Modifier.STATIC) != 0) |
41 | return f; |
42 | _c = _c.getSuperclass(); |
43 | } while (_c != null); |
44 | ret null; |
45 | } |
46 | |
47 | static Field getOptIgnoreCase_findField(Class<?> c, String field) { |
48 | Class _c = c; |
49 | do { |
50 | for (Field f : _c.getDeclaredFields()) |
51 | if (eqic(f.getName(), field)) |
52 | return f; |
53 | _c = _c.getSuperclass(); |
54 | } while (_c != null); |
55 | ret null; |
56 | } |
Began life as a copy of #1001101
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1003386 |
Snippet name: | getOptIgnoreCase |
Eternal ID of this version: | #1003386/1 |
Text MD5: | 0f42cf731267e78fd22fb3374409712b |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-06-28 22:45:12 |
Source code size: | 1547 bytes / 56 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 533 / 527 |
Referenced in: | [show references] |