better api
This commit is contained in:
@@ -19,7 +19,7 @@ public class JavaConcatenator {
|
||||
|
||||
String targetPackage = "click.kamil";
|
||||
|
||||
List<Path> javaFiles = FileUtils.findFilesWithExtension(sourceDir, ".java");
|
||||
List<Path> javaFiles = FileUtils.findFilesWithExtension(Set.of(sourceDir), ".java");
|
||||
|
||||
Set<String> uniqueImports = new TreeSet<>();
|
||||
List<String> classBodies = new ArrayList<>();
|
||||
@@ -59,7 +59,7 @@ public class JavaConcatenator {
|
||||
}
|
||||
|
||||
private static FileParseResult parseAndTransform(String source) {
|
||||
ASTParser parser = ASTParser.newParser(AST.JLS17);
|
||||
ASTParser parser = ASTParser.newParser(AST.getJLSLatest());
|
||||
parser.setSource(source.toCharArray());
|
||||
parser.setKind(ASTParser.K_COMPILATION_UNIT);
|
||||
parser.setResolveBindings(false);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Main {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
AstFileFinder finder = new AstFileFinder();
|
||||
List<Path> javaFiles = FileUtils.findFilesWithExtension(Paths.get(START_DIR), EXTENSION);
|
||||
List<Path> javaFiles = FileUtils.findFilesWithExtension(Set.of(Paths.get(START_DIR)), EXTENSION);
|
||||
|
||||
// List of output handlers
|
||||
List<StateMachineExporter> outputs = List.of(
|
||||
|
||||
@@ -4,12 +4,20 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class FileUtils {
|
||||
public static List<Path> findFilesWithExtension(Path startDir, String extension) throws IOException {
|
||||
try (Stream<Path> paths = Files.walk(startDir)) {
|
||||
public static List<Path> findFilesWithExtension(Set<Path> startDirs, String extension) throws RuntimeException {
|
||||
try (Stream<Path> paths = startDirs.stream()
|
||||
.flatMap(startDir -> {
|
||||
try {
|
||||
return Files.walk(startDir);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
})) {
|
||||
return paths
|
||||
.filter(p -> Files.isRegularFile(p) && p.toString().endsWith(extension))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Reference in New Issue
Block a user