Better visualisation.

This commit is contained in:
Jan Lahoda 2025-10-09 17:35:21 +02:00
parent d35773cb99
commit 38089d183f
3 changed files with 33 additions and 12 deletions

View File

@ -709,7 +709,9 @@ public class Flow {
if (exhaustivenessResult.notExhaustiveDetails().isEmpty()) {
log.error(tree, Errors.NotExhaustiveStatement);
} else {
log.error(tree, Errors.NotExhaustiveStatementDetails(exhaustivenessResult.notExhaustiveDetails().stream().collect(Collectors.joining("\n"))));
List<JCDiagnostic> details =
convertNotExhaustiveDetails(exhaustivenessResult);
log.error(tree, Errors.NotExhaustiveStatementDetails(details));
}
}
}
@ -756,7 +758,9 @@ public class Flow {
if (exhaustivenessResult.notExhaustiveDetails().isEmpty()) {
log.error(tree, Errors.NotExhaustive);
} else {
log.error(tree, Errors.NotExhaustiveDetails(exhaustivenessResult.notExhaustiveDetails().stream().collect(Collectors.joining("\n"))));
List<JCDiagnostic> details =
convertNotExhaustiveDetails(exhaustivenessResult);
log.error(tree, Errors.NotExhaustiveDetails(details));
}
}
}
@ -765,6 +769,14 @@ public class Flow {
alive = alive.or(resolveYields(tree, prevPendingExits));
}
private List<JCDiagnostic> convertNotExhaustiveDetails(ExhaustivenessResult exhaustivenessResult) {
return exhaustivenessResult.notExhaustiveDetails()
.stream()
.sorted()
.map(detail -> diags.fragment(Fragments.NotExhaustiveDetail(detail)))
.collect(List.collector());
}
public void visitTry(JCTry tree) {
ListBuffer<PendingExit> prevPendingExits = pendingExits;
pendingExits = new ListBuffer<>();

View File

@ -1473,16 +1473,20 @@ compiler.err.not.exhaustive=\
compiler.err.not.exhaustive.statement=\
the switch statement does not cover all possible input values
# 0: string
# 0: list of diagnostic
compiler.err.not.exhaustive.details=\
the switch expression does not cover all possible input values\n\
missing patterns: {0}
# 0: string
# 0: list of diagnostic
compiler.err.not.exhaustive.statement.details=\
the switch statement does not cover all possible input values\n\
missing patterns: {0}
# 0: string
compiler.misc.not.exhaustive.detail=\
\n{0}
compiler.err.initializer.must.be.able.to.complete.normally=\
initializer must be able to complete normally

View File

@ -35,10 +35,12 @@
import com.sun.tools.javac.api.ClientCodeWrapper.DiagnosticSourceUnwrapper;
import com.sun.tools.javac.util.JCDiagnostic;
import com.sun.tools.javac.util.JCDiagnostic.Fragment;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -365,13 +367,13 @@ public class ExhaustivenessConvenientErrors extends TestRunner {
case Triple(B _, _, _) -> 0;
case Triple(_, A _, _) -> 0;
case Triple(_, _, A _) -> 0;
// case Triple(A p, C(Nested _, NestedBaseA _), _) -> 0;
case Triple(A p, C(Nested _, NestedBaseB _), C(Nested _, NestedBaseA _)) -> 0;
case Triple(A p, C(Nested _, NestedBaseB _), C(Nested _, NestedBaseB _)) -> 0;
case Triple(A p, C(Nested _, NestedBaseB _), C(Nested _, NestedBaseC _)) -> 0;
case Triple(A p, C(Nested _, NestedBaseC _), C(Nested _, NestedBaseA _)) -> 0;
case Triple(A p, C(Nested _, NestedBaseC _), C(Nested _, NestedBaseB _)) -> 0;
// case Path(A p, C(Nested _, NestedBaseC _), C(Nested _, NestedBaseC _)) -> 0;
// case Triple(A _, C(Nested _, NestedBaseA _), _) -> 0;
case Triple(A _, C(Nested _, NestedBaseB _), C(Nested _, NestedBaseA _)) -> 0;
case Triple(A _, C(Nested _, NestedBaseB _), C(Nested _, NestedBaseB _)) -> 0;
case Triple(A _, C(Nested _, NestedBaseB _), C(Nested _, NestedBaseC _)) -> 0;
case Triple(A _, C(Nested _, NestedBaseC _), C(Nested _, NestedBaseA _)) -> 0;
case Triple(A _, C(Nested _, NestedBaseC _), C(Nested _, NestedBaseB _)) -> 0;
// case Path(A _, C(Nested _, NestedBaseC _), C(Nested _, NestedBaseC _)) -> 0;
};
}
record Triple(Base c1, Base c2, Base c3) {}
@ -517,7 +519,10 @@ public class ExhaustivenessConvenientErrors extends TestRunner {
d = uw.d;
}
if (d instanceof JCDiagnostic diag) {
missingPatterns.addAll(List.of(((String) diag.getArgs()[0]).split("\n")));
((Collection<JCDiagnostic>) diag.getArgs()[0])
.stream()
.map(fragment -> (String) fragment.getArgs()[0])
.forEach(missingPatterns::add);
}
}
})