From 53c06909bec4b7c3bfb399b5823b356bd5e6b19b Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 2 Apr 2016 15:21:39 +0100 Subject: Allow richer description of file list --- .../zwobble/couscous/frontends/java/JavaFrontend.java | 18 +++--------------- .../zwobble/couscous/frontends/java/JavaReader.java | 6 +++++- 2 files changed, 8 insertions(+), 16 deletions(-) (limited to 'src/main/java/org/zwobble/couscous/frontends') diff --git a/src/main/java/org/zwobble/couscous/frontends/java/JavaFrontend.java b/src/main/java/org/zwobble/couscous/frontends/java/JavaFrontend.java index b633093..651c820 100644 --- a/src/main/java/org/zwobble/couscous/frontends/java/JavaFrontend.java +++ b/src/main/java/org/zwobble/couscous/frontends/java/JavaFrontend.java @@ -5,38 +5,26 @@ import org.zwobble.couscous.ast.Node; import org.zwobble.couscous.ast.TypeNode; import org.zwobble.couscous.ast.VariableDeclaration; import org.zwobble.couscous.ast.VariableNode; +import org.zwobble.couscous.util.FileSet; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import java.util.stream.Collectors; import static org.zwobble.couscous.ast.structure.NodeStructure.descendantNodesAndSelf; import static org.zwobble.couscous.util.Casts.tryCast; -import static org.zwobble.couscous.util.ExtraIterables.iterable; import static org.zwobble.couscous.util.ExtraLists.eagerFlatMap; import static org.zwobble.couscous.util.ExtraStreams.toStream; public class JavaFrontend { - public List readSourceDirectory(List sourcePaths, List sourceFiles) throws IOException { - List expandedSourceFiles = eagerFlatMap(sourceFiles, this::findJavaFiles); + public List readSourceDirectory(List sourcePaths, FileSet sourceFiles) throws IOException { + List expandedSourceFiles = sourceFiles.filter(path -> path.toString().endsWith(".java")).files(); List classNodes = JavaReader.readClassesFromFiles(sourcePaths, expandedSourceFiles); ensureDeclarationsAreUnique(classNodes); return classNodes; } - private Iterable findJavaFiles(Path directoryPath) { - return iterable(() -> { - try { - return Files.walk(directoryPath) - .filter(path -> path.toFile().isFile() && path.toString().endsWith(".java")); - } catch (IOException exception) { - throw new RuntimeException(exception); - } - }); - } - private void ensureDeclarationsAreUnique(List classNodes) { List declarations = eagerFlatMap(classNodes, this::findDeclarations); Multimaps.index(declarations, VariableDeclaration::getId) diff --git a/src/main/java/org/zwobble/couscous/frontends/java/JavaReader.java b/src/main/java/org/zwobble/couscous/frontends/java/JavaReader.java index 82d9d78..d4366c2 100644 --- a/src/main/java/org/zwobble/couscous/frontends/java/JavaReader.java +++ b/src/main/java/org/zwobble/couscous/frontends/java/JavaReader.java @@ -59,7 +59,11 @@ public class JavaReader { if (!errors.isEmpty()) { throw new RuntimeException("Errors during parsing:\n\n" + describe(errors)); } - reader.readCompilationUnit(ast); + try { + reader.readCompilationUnit(ast); + } catch (Exception exception) { + throw new RuntimeException("Error reading " + sourceFile, exception); + } } return reader.types(); } -- cgit v1.2.3