[core] Abort on semantic errors

This commit is contained in:
Clément Fournier committed 2022-04-02 01:44:15 +02:00
1 parent 9d816d28b9
commit 4fa7db254e
2 files changed
+24 -1

No files matched your search

@@ -17,6 +17,18 @@ public interface SemanticErrorReporter {
// TODO use resource bundle keys instead of string messages.
/**
* Report an informational message at the given location.
*
* @param location Location where the message should be reported
* @param message Message (rendered using a {@link MessageFormat})
* @param formatArgs Format arguments
*/
default void info(Node location, String message, Object... formatArgs) {
// noop
}
/**
* Report a warning at the given location. Warnings do not abort
* the analysis.
@@ -87,6 +99,11 @@ public interface SemanticErrorReporter {
return fullMessage;
}
@Override
public void info(Node location, String message, Object... formatArgs) {
logMessage(Level.INFO, location, message, formatArgs);
}
@Override
public void warning(Node location, String message, Object... args) {
logMessage(Level.WARN, location, message, args);
@@ -125,11 +125,12 @@ abstract class PmdRunnable implements Runnable {
LanguageVersion languageVersion,
String filename) throws FileAnalysisException {
SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(LOGGER);
ParserTask task = new ParserTask(
languageVersion,
filename,
sourceCode,
SemanticErrorReporter.reportToLogger(LOGGER),
reporter,
configuration.getClassLoader()
);
@@ -143,6 +144,11 @@ abstract class PmdRunnable implements Runnable {
RootNode rootNode = parse(parser, task);
if (reporter.hasError()) {
reporter.info(rootNode, "Errors occurred in file, skipping rule analysis");
return;
}
ruleSets.apply(rootNode, listener);
}