(Class clas, String fieldName, boolean staticOnly)
| 303 | to change related signatures and code. |
| 304 | */ |
| 305 | protected static Field resolveExpectedJavaField(Class clas, String fieldName, boolean staticOnly) throws UtilEvalError, ReflectError { |
| 306 | Field field; |
| 307 | try { |
| 308 | if (Capabilities.haveAccessibility()) { |
| 309 | field = findAccessibleField(clas, fieldName); |
| 310 | } else { |
| 311 | // Class getField() finds only public fields |
| 312 | field = clas.getField(fieldName); |
| 313 | } |
| 314 | } catch (NoSuchFieldException e) { |
| 315 | throw new ReflectError("No such field: " + fieldName, e); |
| 316 | } catch (SecurityException e) { |
| 317 | throw new UtilTargetError("Security Exception while searching fields of: " + clas, e); |
| 318 | } |
| 319 | |
| 320 | if (staticOnly && !Modifier.isStatic(field.getModifiers())) { |
| 321 | throw new UtilEvalError("Can't reach instance field: " + fieldName + " from static context: " + clas.getName()); |
| 322 | } |
| 323 | |
| 324 | return field; |
| 325 | } |
| 326 | |
| 327 | |
| 328 | /** |
no test coverage detected