|
|
@@ -3,12 +3,12 @@ package de.jplag.java;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
import java.util.Set;
|
|
|
|
|
|
-import javax.tools.Diagnostic;
|
|
|
import javax.tools.DiagnosticCollector;
|
|
|
import javax.tools.JavaCompiler;
|
|
|
import javax.tools.JavaCompiler.CompilationTask;
|
|
|
@@ -34,6 +34,7 @@ public class JavacAdapter {
|
|
|
public void parseFiles(Set<File> files, final Parser parser) throws ParsingException {
|
|
|
var listener = new DiagnosticCollector<>();
|
|
|
|
|
|
+ List<ParsingException> parsingExceptions = new ArrayList<>();
|
|
|
try (final StandardJavaFileManager fileManager = javac.getStandardFileManager(listener, null, StandardCharsets.UTF_8)) {
|
|
|
var javaFiles = fileManager.getJavaFileObjectsFromFiles(files);
|
|
|
|
|
|
@@ -47,15 +48,16 @@ public class JavacAdapter {
|
|
|
final LineMap map = ast.getLineMap();
|
|
|
var scanner = new TokenGeneratingTreeScanner(file, parser, map, positions, ast);
|
|
|
ast.accept(scanner, null);
|
|
|
- if (scanner.getParsingException() != null) {
|
|
|
- throw scanner.getParsingException();
|
|
|
- }
|
|
|
+ parsingExceptions.addAll(scanner.getParsingExceptions());
|
|
|
parser.add(Token.fileEnd(file));
|
|
|
}
|
|
|
} catch (IOException exception) {
|
|
|
throw new ParsingException(null, exception.getMessage(), exception);
|
|
|
}
|
|
|
- processErrors(parser.logger, listener);
|
|
|
+ parsingExceptions.addAll(processErrors(parser.logger, listener));
|
|
|
+ if (!parsingExceptions.isEmpty()) {
|
|
|
+ throw ParsingException.wrappingExceptions(parsingExceptions);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private Iterable<? extends CompilationUnitTree> executeCompilationTask(final CompilationTask task, Logger logger) {
|
|
|
@@ -68,18 +70,16 @@ public class JavacAdapter {
|
|
|
return abstractSyntaxTrees;
|
|
|
}
|
|
|
|
|
|
- private void processErrors(Logger logger, DiagnosticCollector<Object> listener) throws ParsingException {
|
|
|
- for (Diagnostic<?> diagnosticItem : listener.getDiagnostics()) {
|
|
|
- if (diagnosticItem.getKind() == javax.tools.Diagnostic.Kind.ERROR) {
|
|
|
- File file = null;
|
|
|
- if (diagnosticItem.getSource() instanceof JavaFileObject) {
|
|
|
- JavaFileObject fileObject = (JavaFileObject) diagnosticItem.getSource();
|
|
|
- file = new File(fileObject.toUri());
|
|
|
- }
|
|
|
- logger.error("{}", diagnosticItem);
|
|
|
- throw new ParsingException(file, diagnosticItem.getMessage(Locale.getDefault()));
|
|
|
+ private List<ParsingException> processErrors(Logger logger, DiagnosticCollector<Object> listener) {
|
|
|
+ return listener.getDiagnostics().stream().filter(it -> it.getKind() == javax.tools.Diagnostic.Kind.ERROR).map(diagnosticItem -> {
|
|
|
+ File file = null;
|
|
|
+ if (diagnosticItem.getSource() instanceof JavaFileObject) {
|
|
|
+ JavaFileObject fileObject = (JavaFileObject) diagnosticItem.getSource();
|
|
|
+ file = new File(fileObject.toUri());
|
|
|
}
|
|
|
- }
|
|
|
+ logger.error("{}", diagnosticItem);
|
|
|
+ return new ParsingException(file, diagnosticItem.getMessage(Locale.getDefault()));
|
|
|
+ }).toList();
|
|
|
}
|
|
|
|
|
|
}
|