refactor(core): убрать @SuppressWarnings("unchecked") в DrawingPreRenderer #64
+8
-15
@@ -107,7 +107,7 @@ public final class DrawingPreRenderer {
|
||||
if (!handled.add(p)) {
|
||||
continue;
|
||||
}
|
||||
List<Object> content = contentOf(p);
|
||||
List<?> content = contentOf(p);
|
||||
if (content.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public final class DrawingPreRenderer {
|
||||
}
|
||||
|
||||
/** Содержимое части, в котором могут лежать w:drawing. */
|
||||
private static List<Object> contentOf(Part part) {
|
||||
private static List<?> contentOf(Part part) {
|
||||
if (!(part instanceof JaxbXmlPart<?> jaxb)) {
|
||||
return List.of();
|
||||
}
|
||||
@@ -128,16 +128,15 @@ public final class DrawingPreRenderer {
|
||||
return doc.getBody() == null ? doc.getContent() : doc.getBody().getContent();
|
||||
}
|
||||
if (root instanceof org.docx4j.wml.CTFootnotes fn) {
|
||||
return cast(fn.getFootnote());
|
||||
return fn.getFootnote();
|
||||
}
|
||||
if (root instanceof org.docx4j.wml.CTEndnotes en) {
|
||||
return cast(en.getEndnote());
|
||||
return en.getEndnote();
|
||||
}
|
||||
return invokeList(root, "getContent");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void walk(Part part, List<Object> content, WordprocessingMLPackage pkg,
|
||||
private static void walk(Part part, List<?> content, WordprocessingMLPackage pkg,
|
||||
DrawMlColor colors, int[] idSeq, ConvertOptions options) {
|
||||
for (Object o : content) {
|
||||
Object v = o instanceof JAXBElement ? ((JAXBElement<?>) o).getValue() : o;
|
||||
@@ -145,24 +144,18 @@ public final class DrawingPreRenderer {
|
||||
replaceDrawing(part, drawing, pkg, colors, idSeq, options);
|
||||
continue;
|
||||
}
|
||||
List<Object> nested = invokeList(v, "getContent");
|
||||
List<?> nested = invokeList(v, "getContent");
|
||||
if (!nested.isEmpty() && nested != content) {
|
||||
walk(part, nested, pkg, colors, idSeq, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<Object> cast(List<?> l) {
|
||||
return (List<Object>) l;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<Object> invokeList(Object target, String getter) {
|
||||
private static List<?> invokeList(Object target, String getter) {
|
||||
try {
|
||||
Method m = target.getClass().getMethod(getter);
|
||||
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) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user