Skip to content

Commit

Permalink
Complex condition moved into separate method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver-Loeffler committed Apr 10, 2024
1 parent 5847ac1 commit 19028d6
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ public void load(String fxmlText, FXOMDocumentSwitch ... switches) throws java.i
setSceneGraphRoot(fxmlLoader.load(is));
} catch (RuntimeException | IOException x) {
Throwable cause = x.getCause();
if (cause instanceof ClassNotFoundException missingTypeError &&
(Set.of(switches).contains(FXOMDocumentSwitch.PRESERVE_UNRESOLVED_IMPORTS)
|| document.hasUnresolvableImports())) {
String missingClassName = missingTypeError.getMessage();
if (handlingOfUnresolvedImportsIsEnabled(cause, switches)) {
String missingClassName = cause.getMessage();
String modifiedFxml = removeUnresolvableTypeFromFXML(fxmlText, missingClassName);
LOGGER.log(Level.WARNING, "Failed to resolve class from FXML imports. "
+ "Try loading FXML without {0}", missingClassName);
Expand All @@ -124,6 +122,14 @@ public void load(String fxmlText, FXOMDocumentSwitch ... switches) throws java.i
}
}

private boolean handlingOfUnresolvedImportsIsEnabled(Throwable cause, FXOMDocumentSwitch... switches) {
if (!(cause instanceof ClassNotFoundException)) {
return false;
}
return Set.of(switches).contains(FXOMDocumentSwitch.PRESERVE_UNRESOLVED_IMPORTS)
|| document.hasUnresolvableImports();
}

private String removeUnresolvableTypeFromFXML(String fxmlText, String unresolvableType) {
FXOMImportsRemover remover = new FXOMImportsRemover(document::addUnresolvableType);
return remover.removeImports(fxmlText, List.of(unresolvableType));
Expand Down

0 comments on commit 19028d6

Please sign in to comment.