Only use MessageReporter as backend of SemanticErrorReporter

This commit is contained in:
Clément Fournier
2022-05-15 14:14:17 +02:00
parent f291a2917b
commit 02571c6c04
5 changed files with 7 additions and 16 deletions

View File

@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.ast;
import java.text.MessageFormat;
import org.slf4j.Logger;
import org.slf4j.event.Level;
import net.sourceforge.pmd.util.StringUtil;
@ -90,7 +89,7 @@ public interface SemanticErrorReporter {
* Forwards to a {@link MessageReporter}, except trace and debug
* messages which are reported on a logger.
*/
static SemanticErrorReporter reportToLogger(MessageReporter reporter, Logger logger) {
static SemanticErrorReporter reportToLogger(MessageReporter reporter) {
return new SemanticErrorReporter() {
private boolean hasError = false;
@ -105,11 +104,7 @@ public interface SemanticErrorReporter {
private String logMessage(Level level, Node location, String message, Object[] args) {
String fullMessage = makeMessage(location, message, args);
if (level.compareTo(Level.INFO) > 0) {
logger.atLevel(level).log(fullMessage);
} else {
reporter.log(level, StringUtil.quoteMessageFormat(fullMessage)); // already formatted
}
reporter.log(level, StringUtil.quoteMessageFormat(fullMessage)); // already formatted
return fullMessage;
}

View File

@ -129,7 +129,7 @@ abstract class PmdRunnable implements Runnable {
LanguageVersion languageVersion,
String filename) throws FileAnalysisException {
SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(configuration.getReporter(), LOG);
SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(configuration.getReporter());
ParserTask task = new ParserTask(
languageVersion,
filename,

View File

@ -45,7 +45,7 @@ public class SemanticErrorReporterTest {
@Test
public void testErrorLogging() {
SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(mockReporter, mockLogger);
SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(mockReporter);
RootNode node = parseMockNode(reporter);
assertFalse(reporter.hasError());
@ -61,7 +61,7 @@ public class SemanticErrorReporterTest {
@Test
public void testEscaping() {
SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(mockReporter, mockLogger);
SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(mockReporter);
RootNode node = parseMockNode(reporter);
// this is a MessageFormat string

View File

@ -4,9 +4,6 @@
package net.sourceforge.pmd.lang.html.ast;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.sourceforge.pmd.cpd.SourceCode;
import net.sourceforge.pmd.cpd.TokenEntry;
import net.sourceforge.pmd.cpd.Tokenizer;
@ -17,7 +14,6 @@ import net.sourceforge.pmd.lang.ast.SemanticErrorReporter;
import net.sourceforge.pmd.lang.html.HtmlLanguageModule;
public class HtmlTokenizer implements Tokenizer {
private static final Logger LOG = LoggerFactory.getLogger(HtmlTokenizer.class);
@Override
public void tokenize(SourceCode sourceCode, Tokens tokenEntries) {
@ -25,7 +21,7 @@ public class HtmlTokenizer implements Tokenizer {
LanguageRegistry.getLanguage(HtmlLanguageModule.NAME).getDefaultVersion(),
sourceCode.getFileName(),
sourceCode.getCodeBuffer().toString(),
SemanticErrorReporter.reportToLogger(LOG)
SemanticErrorReporter.noop() // todo
);
HtmlParser parser = new HtmlParser();

View File

@ -125,7 +125,7 @@ public class JavaParsingHelper extends BaseParsingHelper<JavaParsingHelper, ASTC
}
Logger consoleLogger = LoggerFactory.getLogger(TestCheckLogger.class);
MessageReporter reporter = new SimpleMessageReporter(consoleLogger);
return SemanticErrorReporter.reportToLogger(reporter, consoleLogger);
return SemanticErrorReporter.reportToLogger(reporter);
}
@Override