diff options
author | Danny van Bruggen <lol@meuk.info> | 2017-03-07 14:12:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-07 14:12:11 +0100 |
commit | 88089dde00cf187ada99198787ce5094fcccf993 (patch) | |
tree | 218d5cecb408436ac7e87948f7740dc66a57d9c1 /javaparser-core/src/main/java/com | |
parent | 8be0c90e7bcdd0232ce0d7e3149f2232e5a0b183 (diff) | |
parent | 8d8606dd539d29934786047a0c3244280d32aaee (diff) | |
download | platform_external_javaparser-88089dde00cf187ada99198787ce5094fcccf993.tar.gz platform_external_javaparser-88089dde00cf187ada99198787ce5094fcccf993.tar.bz2 platform_external_javaparser-88089dde00cf187ada99198787ce5094fcccf993.zip |
Merge pull request #839 from arturbosch/master
Check root argument of SourceRoot must be a directory
Diffstat (limited to 'javaparser-core/src/main/java/com')
-rw-r--r-- | javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java index d3c59aa43..23b5685ba 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java +++ b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java @@ -7,8 +7,6 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.printer.PrettyPrinter; import java.io.IOException; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; @@ -26,8 +24,6 @@ import static com.github.javaparser.Providers.provider; import static com.github.javaparser.utils.CodeGenerationUtils.fileInPackageRelativePath; import static com.github.javaparser.utils.CodeGenerationUtils.packageAbsolutePath; import static com.github.javaparser.utils.SourceRoot.Callback.Result.SAVE; -import static com.github.javaparser.utils.CodeGenerationUtils.fileInPackageRelativePath; -import static com.github.javaparser.utils.CodeGenerationUtils.packageAbsolutePath; /** * A collection of Java source files located in one directory and its subdirectories on the file system. @@ -50,6 +46,9 @@ public class SourceRoot { private JavaParser javaParser = new JavaParser(); public SourceRoot(Path root) { + if (!Files.isDirectory(root)) { + throw new IllegalArgumentException("Only directories are allowed as root path!"); + } this.root = root.normalize(); Log.info("New source root at \"%s\"", this.root); } @@ -128,14 +127,9 @@ public class SourceRoot { } private void save(CompilationUnit cu, Path path) throws IOException { - path.getParent().toFile().mkdirs(); - + Files.createDirectories(path.getParent()); final String code = new PrettyPrinter().print(cu); - try (PrintWriter out = new PrintWriter(path.toFile(), UTF8.toString())) { - out.println(code); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } + Files.write(path, code.getBytes(UTF8)); } /** |