refactor(core): убрать @SuppressWarnings("unchecked") в DrawingPreRenderer #64

Merged
pjandro merged 1 commits from remove-suppresswarnings into main 2026-10-27 01:24:14 +03:00
Showing only changes of commit 86a2d761d7 - Show all commits
@@ -107,7 +107,7 @@ public final class DrawingPreRenderer {
if (!handled.add(p)) { if (!handled.add(p)) {
continue; continue;
} }
List<Object> content = contentOf(p); List<?> content = contentOf(p);
if (content.isEmpty()) { if (content.isEmpty()) {
continue; continue;
} }
@@ -116,7 +116,7 @@ public final class DrawingPreRenderer {
} }
/** Содержимое части, в котором могут лежать w:drawing. */ /** Содержимое части, в котором могут лежать w:drawing. */
private static List<Object> contentOf(Part part) { private static List<?> contentOf(Part part) {
if (!(part instanceof JaxbXmlPart<?> jaxb)) { if (!(part instanceof JaxbXmlPart<?> jaxb)) {
return List.of(); return List.of();
} }
@@ -128,16 +128,15 @@ public final class DrawingPreRenderer {
return doc.getBody() == null ? doc.getContent() : doc.getBody().getContent(); return doc.getBody() == null ? doc.getContent() : doc.getBody().getContent();
} }
if (root instanceof org.docx4j.wml.CTFootnotes fn) { if (root instanceof org.docx4j.wml.CTFootnotes fn) {
return cast(fn.getFootnote()); return fn.getFootnote();
} }
if (root instanceof org.docx4j.wml.CTEndnotes en) { if (root instanceof org.docx4j.wml.CTEndnotes en) {
return cast(en.getEndnote()); return en.getEndnote();
} }
return invokeList(root, "getContent"); return invokeList(root, "getContent");
} }
@SuppressWarnings("unchecked") private static void walk(Part part, List<?> content, WordprocessingMLPackage pkg,
private static void walk(Part part, List<Object> content, WordprocessingMLPackage pkg,
DrawMlColor colors, int[] idSeq, ConvertOptions options) { DrawMlColor colors, int[] idSeq, ConvertOptions options) {
for (Object o : content) { for (Object o : content) {
Object v = o instanceof JAXBElement ? ((JAXBElement<?>) o).getValue() : o; Object v = o instanceof JAXBElement ? ((JAXBElement<?>) o).getValue() : o;
@@ -145,24 +144,18 @@ public final class DrawingPreRenderer {
replaceDrawing(part, drawing, pkg, colors, idSeq, options); replaceDrawing(part, drawing, pkg, colors, idSeq, options);
continue; continue;
} }
List<Object> nested = invokeList(v, "getContent"); List<?> nested = invokeList(v, "getContent");
if (!nested.isEmpty() && nested != content) { if (!nested.isEmpty() && nested != content) {
walk(part, nested, pkg, colors, idSeq, options); walk(part, nested, pkg, colors, idSeq, options);
} }
} }
} }
@SuppressWarnings("unchecked") private static List<?> invokeList(Object target, String getter) {
private static List<Object> cast(List<?> l) {
return (List<Object>) l;
}
@SuppressWarnings("unchecked")
private static List<Object> invokeList(Object target, String getter) {
try { try {
Method m = target.getClass().getMethod(getter); Method m = target.getClass().getMethod(getter);
Object r = m.invoke(target); Object r = m.invoke(target);
return r instanceof List ? (List<Object>) r : List.of(); return r instanceof List<?> l ? l : List.of();
} catch (ReflectiveOperationException | RuntimeException e) { } catch (ReflectiveOperationException | RuntimeException e) {
return List.of(); return List.of();
} }