refactor(core): убрать @SuppressWarnings("unchecked") в DrawingPreRenderer
PR checks / web (pull_request) Successful in 39s
PR checks / java (pull_request) Successful in 1m0s
Main: tests, deploy, autotests / web (push) Successful in 35s
Main: tests, deploy, autotests / java (push) Successful in 1m31s
Main: tests, deploy, autotests / images-web (push) Successful in 34s
Main: tests, deploy, autotests / images-app (push) Successful in 1m52s
Main: tests, deploy, autotests / deploy (push) Successful in 1m30s
Main: tests, deploy, autotests / autotests (push) Successful in 46s
Main: tests, deploy, autotests / rollback (push) Has been skipped
PR checks / web (pull_request) Successful in 39s
PR checks / java (pull_request) Successful in 1m0s
Main: tests, deploy, autotests / web (push) Successful in 35s
Main: tests, deploy, autotests / java (push) Successful in 1m31s
Main: tests, deploy, autotests / images-web (push) Successful in 34s
Main: tests, deploy, autotests / images-app (push) Successful in 1m52s
Main: tests, deploy, autotests / deploy (push) Successful in 1m30s
Main: tests, deploy, autotests / autotests (push) Successful in 46s
Main: tests, deploy, autotests / rollback (push) Has been skipped
Обход контента частей сузён до List<?> (он только читается; мутация идёт в gd.getAny()), хелпер cast удалён, invokeList возвращает List<?> через pattern matching — все три unchecked-подавления в main-коде больше не нужны.
This commit was merged in pull request #64.
This commit is contained in:
+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