(@NotNull Class<T> type, @NotNull ArrAPI api, @NotNull JSONObject val, boolean silent)
| 49 | } |
| 50 | |
| 51 | private static <T extends APIObject> @Nullable T build(@NotNull Class<T> type, @NotNull ArrAPI api, @NotNull JSONObject val, boolean silent) { |
| 52 | Constructor<?> c = constructors.computeIfAbsent(type, k -> { |
| 53 | try { |
| 54 | return type.getConstructor(ArrAPI.class, JSONObject.class); |
| 55 | } catch (NoSuchMethodException ex) { |
| 56 | if (!silent) { |
| 57 | LOGGER.error("Could not find API constructor for class {}", type.getName(), ex); |
| 58 | } |
| 59 | } |
| 60 | return null; |
| 61 | }); |
| 62 | |
| 63 | if (c == null) { |
| 64 | return null; |
| 65 | } |
| 66 | |
| 67 | try { |
| 68 | return type.cast(c.newInstance(api, val)); |
| 69 | } catch (InvocationTargetException | InstantiationException | IllegalAccessException | IllegalArgumentException ex) { |
| 70 | if (!silent) { |
| 71 | LOGGER.error("Could not create new instance of class {}", type.getName(), ex); |
| 72 | } |
| 73 | } |
| 74 | return null; |
| 75 | } |
| 76 | |
| 77 | private ObjectParser() { } |
| 78 | } |
no outgoing calls
no test coverage detected