Change error display for editor

This commit is contained in:
Clément Fournier 2019-02-21 14:33:21 +01:00
parent 99e8924198
commit 50f99743a7
3 changed files with 16 additions and 12 deletions

View File

@ -5,6 +5,7 @@
package net.sourceforge.pmd.util.fxdesigner;
import static java.util.Collections.emptyList;
import static net.sourceforge.pmd.util.fxdesigner.util.DesignerUtil.*;
import java.io.File;
import java.io.IOException;
@ -112,7 +113,7 @@ public class SourceEditorController extends AbstractController<MainDesignerContr
@Override
protected void afterParentInit() {
DesignerUtil.rewire(astManager.languageVersionProperty(), languageVersionUIProperty);
rewire(astManager.languageVersionProperty(), languageVersionUIProperty);
nodeEditionCodeArea.moveCaret(0, 0);
}
@ -121,7 +122,7 @@ public class SourceEditorController extends AbstractController<MainDesignerContr
ToggleGroup languageToggleGroup = new ToggleGroup();
DesignerUtil.getSupportedLanguageVersions()
getSupportedLanguageVersions()
.stream()
.sorted(LanguageVersion::compareTo)
.map(lv -> {
@ -134,9 +135,9 @@ public class SourceEditorController extends AbstractController<MainDesignerContr
languageSelectionMenuButton.getItems().add(item);
});
languageVersionUIProperty = DesignerUtil.mapToggleGroupToUserData(languageToggleGroup, DesignerUtil::defaultLanguageVersion);
languageVersionUIProperty = mapToggleGroupToUserData(languageToggleGroup, DesignerUtil::defaultLanguageVersion);
// this will be overwritten by property restore if needed
languageVersionUIProperty.setValue(DesignerUtil.defaultLanguageVersion());
languageVersionUIProperty.setValue(defaultLanguageVersion());
}
/**
@ -155,7 +156,7 @@ public class SourceEditorController extends AbstractController<MainDesignerContr
try {
current = astManager.updateIfChanged(source, auxclasspathClassLoader.getValue());
} catch (ParseAbortedException e) {
astTitledPane.setTitle("Abstract syntax tree (error)");
editorTitledPane.errorMessageProperty().setValue(sanitizeExceptionMessage(e));
return Optional.empty();
}
@ -171,7 +172,7 @@ public class SourceEditorController extends AbstractController<MainDesignerContr
private void setUpToDateCompilationUnit(Node node) {
parent.invalidateAst();
astTitledPane.setTitle("Abstract syntax tree");
editorTitledPane.errorMessageProperty().setValue("");
ASTTreeItem root = ASTTreeItem.getRoot(node);
astTreeView.setRoot(root);
}

View File

@ -5,6 +5,8 @@
package net.sourceforge.pmd.util.fxdesigner;
import static net.sourceforge.pmd.util.fxdesigner.util.DesignerUtil.sanitizeExceptionMessage;
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
@ -82,7 +84,6 @@ import javafx.stage.StageStyle;
*/
public class XPathPanelController extends AbstractController<MainDesignerController> implements NodeSelectionSource {
private static final Pattern EXCEPTION_PREFIX_PATTERN = Pattern.compile("(?:(?:\\w+\\.)*\\w+:\\s*)*\\s*(.*)$", Pattern.DOTALL);
private static final String NO_MATCH_MESSAGE = "No match in text";
private static final Duration XPATH_REFRESH_DELAY = Duration.ofMillis(100);
private final XPathEvaluator xpathEvaluator = new XPathEvaluator();
@ -372,7 +373,7 @@ public class XPathPanelController extends AbstractController<MainDesignerControl
String emptyResultsPlaceholder) {
Label emptyLabel = xpathError || otherError
? new Label(emptyResultsPlaceholder, new FontIcon("fas-exclamation"))
? new Label(emptyResultsPlaceholder, new FontIcon("fas-exclamation-triangle"))
: new Label(emptyResultsPlaceholder);
xpathResultListView.setPlaceholder(emptyLabel);
@ -384,9 +385,5 @@ public class XPathPanelController extends AbstractController<MainDesignerControl
}
private static String sanitizeExceptionMessage(Throwable exception) {
Matcher matcher = EXCEPTION_PREFIX_PATTERN.matcher(exception.getMessage());
return matcher.matches() ? matcher.group(1) : exception.getMessage();
}
}

View File

@ -70,6 +70,7 @@ import javafx.util.StringConverter;
*/
public final class DesignerUtil {
private static final Pattern EXCEPTION_PREFIX_PATTERN = Pattern.compile("(?:(?:\\w+\\.)*\\w+:\\s*)*\\s*(.*)$", Pattern.DOTALL);
private static final Path PMD_SETTINGS_DIR = Paths.get(System.getProperty("user.home"), ".pmd");
private static final File DESIGNER_SETTINGS_FILE = PMD_SETTINGS_DIR.resolve("designer.xml").toFile();
@ -288,6 +289,11 @@ public final class DesignerUtil {
}
public static String sanitizeExceptionMessage(Throwable exception) {
Matcher matcher = EXCEPTION_PREFIX_PATTERN.matcher(exception.getMessage());
return matcher.matches() ? matcher.group(1) : exception.getMessage();
}
/**
* Works out an xpath query that matches the node
* which was being visited during the failure.