diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-04-02 14:52:21 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-04-02 14:52:21 +0100 |
| commit | 7fccda0f13f6f8b7f7a1f6e87a648fe1c3396656 (patch) | |
| tree | 3b73a695446faaff9e50232584815e7ef50d9e9c /src/main/java/org/zwobble/couscous/frontends | |
| parent | def25b112080df902121b09a35c02d1fe7728386 (diff) | |
Use JSON to configure CLI
Diffstat (limited to 'src/main/java/org/zwobble/couscous/frontends')
| -rw-r--r-- | src/main/java/org/zwobble/couscous/frontends/java/JavaFrontend.java | 28 | ||||
| -rw-r--r-- | src/main/java/org/zwobble/couscous/frontends/java/JavaParser.java | 6 |
2 files changed, 20 insertions, 14 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 9925068..b633093 100644 --- a/src/main/java/org/zwobble/couscous/frontends/java/JavaFrontend.java +++ b/src/main/java/org/zwobble/couscous/frontends/java/JavaFrontend.java @@ -1,34 +1,40 @@ package org.zwobble.couscous.frontends.java; import com.google.common.collect.Multimaps; -import org.zwobble.couscous.ast.*; +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 java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import java.util.stream.Collectors; -import java.util.stream.Stream; 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.ExtraLists.flatMap; -import static org.zwobble.couscous.util.ExtraLists.list; import static org.zwobble.couscous.util.ExtraStreams.toStream; public class JavaFrontend { - public List<TypeNode> readSourceDirectory(List<Path> sourcePaths, Path directoryPath) throws IOException { - List<TypeNode> classNodes = flatMap( - findJavaFiles(directoryPath), - javaFile -> JavaReader.readClassesFromFiles(sourcePaths, list(javaFile))); + public List<TypeNode> readSourceDirectory(List<Path> sourcePaths, List<Path> sourceFiles) throws IOException { + List<Path> expandedSourceFiles = eagerFlatMap(sourceFiles, this::findJavaFiles); + List<TypeNode> classNodes = JavaReader.readClassesFromFiles(sourcePaths, expandedSourceFiles); ensureDeclarationsAreUnique(classNodes); return classNodes; } - private Stream<Path> findJavaFiles(Path directoryPath) throws IOException { - return Files.walk(directoryPath) - .filter(path -> path.toFile().isFile() && path.toString().endsWith(".java")); + 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) { diff --git a/src/main/java/org/zwobble/couscous/frontends/java/JavaParser.java b/src/main/java/org/zwobble/couscous/frontends/java/JavaParser.java index e1addd3..e97d853 100644 --- a/src/main/java/org/zwobble/couscous/frontends/java/JavaParser.java +++ b/src/main/java/org/zwobble/couscous/frontends/java/JavaParser.java @@ -25,6 +25,9 @@ public class JavaParser { public JavaParser() { parser = ASTParser.newParser(AST.JLS8); + } + + public CompilationUnit parseCompilationUnit(List<Path> sourcePaths, Path sourcePath) throws IOException { parser.setBindingsRecovery(false); parser.setKind(ASTParser.K_COMPILATION_UNIT); @SuppressWarnings("unchecked") @@ -34,9 +37,6 @@ public class JavaParser { options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8); parser.setCompilerOptions(options); parser.setResolveBindings(true); - } - - public CompilationUnit parseCompilationUnit(List<Path> sourcePaths, Path sourcePath) throws IOException { parser.setUnitName(sourcePath.toString()); String[] sourcePathArguments = Iterables.toArray( |
