diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-04-02 15:21:39 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-04-02 15:21:39 +0100 |
| commit | 53c06909bec4b7c3bfb399b5823b356bd5e6b19b (patch) | |
| tree | 522b8cd9b0588c99e0ddb6096ba7ac5b0c5b4679 /src/main/java/org/zwobble/couscous/frontends | |
| parent | 7fccda0f13f6f8b7f7a1f6e87a648fe1c3396656 (diff) | |
Allow richer description of file list
Diffstat (limited to 'src/main/java/org/zwobble/couscous/frontends')
| -rw-r--r-- | src/main/java/org/zwobble/couscous/frontends/java/JavaFrontend.java | 18 | ||||
| -rw-r--r-- | src/main/java/org/zwobble/couscous/frontends/java/JavaReader.java | 6 |
2 files changed, 8 insertions, 16 deletions
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<TypeNode> readSourceDirectory(List<Path> sourcePaths, List<Path> sourceFiles) throws IOException { - List<Path> expandedSourceFiles = eagerFlatMap(sourceFiles, this::findJavaFiles); + public List<TypeNode> readSourceDirectory(List<Path> sourcePaths, FileSet sourceFiles) throws IOException { + List<Path> expandedSourceFiles = sourceFiles.filter(path -> path.toString().endsWith(".java")).files(); List<TypeNode> classNodes = JavaReader.readClassesFromFiles(sourcePaths, expandedSourceFiles); ensureDeclarationsAreUnique(classNodes); return classNodes; } - private Iterable<Path> 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<TypeNode> classNodes) { List<VariableDeclaration> 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(); } |
