Skip to content

Commit

Permalink
Merge pull request #7 from alberlau/fix/refactor-classWriter-params
Browse files Browse the repository at this point in the history
Refactor ClassWriter params
  • Loading branch information
alberlau authored Dec 22, 2023
2 parents d9ac4a9 + a5a3d4c commit 5bd1807
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,27 @@
import java.nio.file.Paths;

public class ClassWriter {
public void write(
String baseDir,
String targetFolder,
String pkg,
String claz,
String source,
String ext) {
public void write(ExecutorParams params, String claz, String source) {

FileWriter fw = null;
try {
String pkg = params.getTargetPackage();
if (pkg == null) {
pkg = "";
}
String targetFolder = params.getTargetFolder();
if (targetFolder == null) {
targetFolder = ".";
}
String baseDir = params.getBaseDir();
if (isBlank(baseDir)) {
throw new RuntimeException("baseDir is required");
}
Path path = Paths.get(baseDir, targetFolder, pkg.replaceAll("\\.", "/"));
if (!path.toFile().exists() && !path.toFile().mkdirs()) {
throw new RuntimeException("Dir cannot be created " + path);
}
String ext = params.getExt();
File classFile = new File(path.toFile(), claz + (ext == null ? ".java" : ext));
if (classFile.exists()) {
classFile.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ public void execute(ExecutorParams params) {
private void generateSource(
ExecutorParams params, JavaClassAdapter javaClass, String template) {
String source = generator.generate(javaClass, template);
classWriter.write(
params.getBaseDir(),
params.getTargetFolder(),
params.getTargetPackage(),
javaClass.getClassName(),
source,
params.getExt());
classWriter.write(params, javaClass.getClassName(), source);
}
}

0 comments on commit 5bd1807

Please sign in to comment.