From aeb5a559851bf07ff45f49e409f880991ee34141 Mon Sep 17 00:00:00 2001 From: Christopher Tubbs Date: Wed, 23 Nov 2022 10:55:45 -0500 Subject: [PATCH] Print problems when compilation fails This closes #61, #62 --- src/main/java/net/revelc/code/impsort/ImpSort.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/revelc/code/impsort/ImpSort.java b/src/main/java/net/revelc/code/impsort/ImpSort.java index a4b3882..0b72c20 100644 --- a/src/main/java/net/revelc/code/impsort/ImpSort.java +++ b/src/main/java/net/revelc/code/impsort/ImpSort.java @@ -126,8 +126,10 @@ public Result parseFile(final Path path, final byte[] buf) throws IOException { List fileLines = readAllLines(file); ParseResult parseResult = new JavaParser(new ParserConfiguration().setLanguageLevel(languageLevel)).parse(file); - CompilationUnit unit = parseResult.getResult() - .orElseThrow(() -> new ImpSortException(path, Reason.UNABLE_TO_PARSE)); + CompilationUnit unit = parseResult.getResult().orElseThrow(() -> { + parseResult.getProblems().forEach(System.out::println); + return new ImpSortException(path, Reason.UNABLE_TO_PARSE); + }); if (!parseResult.isSuccessful()) { parseResult.getProblems().forEach(System.out::println); throw new ImpSortException(path, Reason.PARTIAL_PARSE);