MCPcopy Create free account
hub / github.com/cinit/TMoe / getFirstNSFByType

Method getFirstNSFByType

app/src/main/java/cc/ioctl/tmoe/util/Reflex.java:1129–1156  ·  view source on GitHub ↗
(Object obj, Class<T> type)

Source from the content-addressed store, hash-verified

1127 */
1128 //@Deprecated
1129 public static <T> T getFirstNSFByType(Object obj, Class<T> type) {
1130 if (obj == null) {
1131 throw new NullPointerException("obj == null");
1132 }
1133 if (type == null) {
1134 throw new NullPointerException("type == null");
1135 }
1136 Class clz = obj.getClass();
1137 while (clz != null && !clz.equals(Object.class)) {
1138 for (Field f : clz.getDeclaredFields()) {
1139 if (!f.getType().equals(type)) {
1140 continue;
1141 }
1142 int m = f.getModifiers();
1143 if (Modifier.isStatic(m) || Modifier.isFinal(m)) {
1144 continue;
1145 }
1146 f.setAccessible(true);
1147 try {
1148 return (T) f.get(obj);
1149 } catch (IllegalAccessException ignored) {
1150 //should not happen
1151 }
1152 }
1153 clz = clz.getSuperclass();
1154 }
1155 return null;
1156 }
1157
1158 /**
1159 * NSF: Neither Static nor Final

Callers

nothing calls this directly

Calls 2

equalsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected