diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/EventLogController.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/EventLogController.java index 62c1d57e3f..9f8dd85fc5 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/EventLogController.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/EventLogController.java @@ -4,11 +4,17 @@ package net.sourceforge.pmd.util.fxdesigner; +import static net.sourceforge.pmd.util.fxdesigner.model.LogEntry.Category.PARSE_EXCEPTION; +import static net.sourceforge.pmd.util.fxdesigner.model.LogEntry.Category.PARSE_OK; +import static net.sourceforge.pmd.util.fxdesigner.model.LogEntry.Category.XPATH_EVALUATION_EXCEPTION; +import static net.sourceforge.pmd.util.fxdesigner.model.LogEntry.Category.XPATH_OK; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.time.Duration; import java.util.Collections; import java.util.Date; +import java.util.EnumSet; import java.util.List; import java.util.Objects; @@ -88,16 +94,21 @@ public class EventLogController extends AbstractController { }); EventStream onlyParseException = designerRoot.getLogger().getLog() - .filter(x -> x.getCategory() == Category.PARSE_EXCEPTION) - .successionEnds(PARSE_EXCEPTION_DELAY); + .filter(x -> x.getCategory() == PARSE_EXCEPTION || x.getCategory() == PARSE_OK) + .successionEnds(PARSE_EXCEPTION_DELAY) + // don't output anything when the last state recorded was OK + .filter(x -> x.getCategory() != PARSE_OK); EventStream onlyXPathException = designerRoot.getLogger().getLog() - .filter(x -> x.getCategory() == Category.XPATH_EVALUATION_EXCEPTION) - .successionEnds(PARSE_EXCEPTION_DELAY); + .filter(x -> x.getCategory() == XPATH_EVALUATION_EXCEPTION || x.getCategory() == XPATH_OK) + .successionEnds(PARSE_EXCEPTION_DELAY) + // don't output anything when the last state recorded was OK + .filter(x -> x.getCategory() != XPATH_OK); + + EnumSet otherExceptionSet = EnumSet.complementOf(EnumSet.of(PARSE_EXCEPTION, XPATH_EVALUATION_EXCEPTION, PARSE_OK, XPATH_OK)); EventStream otherExceptions = designerRoot.getLogger().getLog() - .filter(x -> x.getCategory() != Category.PARSE_EXCEPTION) - .filter(y -> y.getCategory() != Category.XPATH_EVALUATION_EXCEPTION); + .filter(x -> otherExceptionSet.contains(x.getCategory())); EventStreams.merge(onlyParseException, otherExceptions, onlyXPathException) .subscribe(t -> eventLogTableView.getItems().add(t)); diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java index 5aafaddeea..fdd40208da 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java @@ -256,6 +256,8 @@ public class XPathPanelController extends AbstractController { xpathResultListView.setItems(results.stream().map(parent::wrapNode).collect(Collectors.toCollection(LiveArrayList::new))); parent.highlightXPathResults(results); violationsTitledPane.setText("Matched nodes\t(" + results.size() + ")"); + // Notify that everything went OK so we can avoid logging very recent exceptions + designerRoot.getLogger().logEvent(new LogEntry(null, Category.XPATH_OK)); } catch (XPathEvaluationException e) { invalidateResults(true); designerRoot.getLogger().logEvent(new LogEntry(e, Category.XPATH_EVALUATION_EXCEPTION)); diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/ASTManager.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/ASTManager.java index 29718e156d..5c260dceca 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/ASTManager.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/ASTManager.java @@ -104,7 +104,7 @@ public class ASTManager { try { languageVersionHandler.getQualifiedNameResolutionFacade(classLoader).start(node); } catch (Exception e) { - designerRoot.getLogger().logEvent(new LogEntry(e, Category.QUALIFIED_NAME_RESOLUTION_EXCEPTION)); + designerRoot.getLogger().logEvent(new LogEntry(e, Category.QNAME_RESOLUTION_EXCEPTION)); } try { @@ -116,6 +116,10 @@ public class ASTManager { compilationUnit.setValue(node); lastValidSource = source; lastLanguageVersion = getLanguageVersion(); + + // Notify that the parse went OK so we can avoid logging very recent exceptions + designerRoot.getLogger().logEvent(new LogEntry(null, Category.PARSE_OK)); + return getCompilationUnit(); } diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/LogEntry.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/LogEntry.java index 7d129630bf..a70deda233 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/LogEntry.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/LogEntry.java @@ -44,7 +44,7 @@ public class LogEntry { public String getStackTrace() { - return ExceptionUtils.getStackTrace(throwable); + return throwable == null ? "" : ExceptionUtils.getStackTrace(throwable); } @@ -56,10 +56,15 @@ public class LogEntry { public enum Category { PARSE_EXCEPTION("Parse exception"), TYPERESOLUTION_EXCEPTION("Type resolution exception"), - QUALIFIED_NAME_RESOLUTION_EXCEPTION("Qualified name resolution exception"), + QNAME_RESOLUTION_EXCEPTION("Qualified name resolution exception"), SYMBOL_FACADE_EXCEPTION("Symbol façade exception"), XPATH_EVALUATION_EXCEPTION("XPath evaluation exception"), - OTHER("Other"); + OTHER("Other"), + + // These are "flag" categories that signal that previous exceptions + // thrown during code or XPath edition may be discarded as uninteresting + PARSE_OK("Parsing success"), + XPATH_OK("XPath evaluation success"); public final String name;