Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

56
LINES

< > BotCompany Repo | #1003386 // getOptIgnoreCase

JavaX fragment (include)

static Object getOptIgnoreCase(O o, S field) {
  if (o instanceof S) o = getBot((S) o);
  if (o == null) ret null;
  if (o instanceof Class) return getOptIgnoreCase((Class) o, field);
  
  if (o.getClass().getName().equals("main$DynamicObject"))
    fail("not implemented");
  
  if (o instanceof Map) ret lookupIgnoreCase((Map) o, field);
  
  ret getOptIgnoreCase_raw(o, field);
}

static Object getOptIgnoreCase_raw(Object o, String field) {
  try {
    Field f = getOptIgnoreCase_findField(o.getClass(), field);
    if (f == null) ret null;
    f.setAccessible(true);
    return f.get(o);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

static Object getOptIgnoreCase(Class c, String field) {
  try {
    Field f = getOptIgnoreCase_findStaticField(c, field);
    if (f == null) ret null;
    f.setAccessible(true);
    return f.get(null);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

static Field getOptIgnoreCase_findStaticField(Class<?> c, String field) {
  Class _c = c;
  do {
    for (Field f : _c.getDeclaredFields())
      if (eqic(f.getName(), field) && (f.getModifiers() & Modifier.STATIC) != 0)
        return f;
    _c = _c.getSuperclass();
  } while (_c != null);
  ret null;
}

static Field getOptIgnoreCase_findField(Class<?> c, String field) {
  Class _c = c;
  do {
    for (Field f : _c.getDeclaredFields())
      if (eqic(f.getName(), field))
        return f;
    _c = _c.getSuperclass();
  } while (_c != null);
  ret null;
}

Author comment

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: 534 / 528
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)