| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | @SuppressWarnings({"unchecked", "rawtypes"}) |
| 197 | public void writeMap(EntryWriter ew) throws IOException { |
| 198 | // Direct forEach(ew::putNoEx) does not work: attributes is declared Map<String, String> but |
| 199 | // the PluginInfo(String, Map<String, Object>) constructor assigns it via raw types, so values |
| 200 | // may not be Strings. The bridge method generated for forEach would CCE on non-String values. |
| 201 | new NamedList<>(attributes).writeMap(ew); |
| 202 | if (initArgs != null) { |
| 203 | initArgs.asMap(3).forEach((k, v) -> ew.putNoEx((String) k, v)); |
| 204 | } |
| 205 | if (children == null || children.isEmpty()) { |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | Map<String, Object> childrenGrouped = new LinkedHashMap<>(); |
| 210 | for (PluginInfo child : children) { |
| 211 | Object old = childrenGrouped.get(child.name); |
| 212 | if (old == null) { |
| 213 | childrenGrouped.put(child.name, child); |
| 214 | } else if (old instanceof List list) { |
| 215 | list.add(child); |
| 216 | } else { |
| 217 | List<Object> l = new ArrayList<>(); |
| 218 | l.add(old); |
| 219 | l.add(child); |
| 220 | childrenGrouped.put(child.name, l); |
| 221 | } |
| 222 | } |
| 223 | for (Map.Entry<String, Object> entry : childrenGrouped.entrySet()) { |
| 224 | ew.put(entry.getKey(), entry.getValue()); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Filter children by type |