completely separate the generated interfaces from manual ones and completely separate the manual tags from the generated ones. Also wipe the directories for code generation before code generation (#167)
This commit is contained in:
16
code_gen/src/main/java/j2html_codegen/GeneratorUtil.java
Normal file
16
code_gen/src/main/java/j2html_codegen/GeneratorUtil.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package j2html_codegen;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class GeneratorUtil {
|
||||
|
||||
public static final void deleteAllFilesInDir(final Path dir) throws IOException {
|
||||
for(final File file : dir.toFile().listFiles()){
|
||||
System.out.println("deleting " + file.toPath());
|
||||
Files.delete(file.toPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package j2html_codegen.generators;
|
||||
|
||||
import j2html_codegen.GeneratorUtil;
|
||||
import j2html_codegen.model.AttrD;
|
||||
import j2html_codegen.model.AttributesList;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -13,8 +15,14 @@ import java.util.Optional;
|
||||
|
||||
public final class AttributeInterfaceCodeGenerator {
|
||||
|
||||
private static final String relPath = "tags/attributes/";
|
||||
|
||||
public static void generate(final Path absPath, final boolean delete) throws IOException {
|
||||
|
||||
//delete all files in the directory for fresh generation
|
||||
final Path dir = Paths.get(absPath.toString(),relPath);
|
||||
GeneratorUtil.deleteAllFilesInDir(dir);
|
||||
|
||||
for (final AttrD attr : AttributesList.attributesDescriptive()) {
|
||||
final Path path = makePath(attr.attr, absPath);
|
||||
final String interfaceName = interfaceNameFromAttribute(attr.attr)+"<T extends Tag>";
|
||||
@@ -29,17 +37,12 @@ public final class AttributeInterfaceCodeGenerator {
|
||||
final String interfaceStr = getInterfaceTemplate(
|
||||
interfaceName,
|
||||
Optional.of("IInstance<T>"),
|
||||
Arrays.asList("j2html.tags.Tag"),
|
||||
Arrays.asList("j2html.tags.Tag","j2html.tags.IInstance"),
|
||||
interfaceNameFromAttribute(attr.attr).substring(1),
|
||||
attr
|
||||
);
|
||||
|
||||
if (delete) {
|
||||
if(Files.exists(path)) {
|
||||
System.out.println("deleting " + path);
|
||||
Files.delete(path);
|
||||
}
|
||||
}else{
|
||||
if (!delete) {
|
||||
System.out.println("writing to "+path);
|
||||
Files.write(path, interfaceStr.getBytes());
|
||||
}
|
||||
@@ -184,7 +187,7 @@ public final class AttributeInterfaceCodeGenerator {
|
||||
|
||||
private static Path makePath(String tagLowerCase, final Path absPath){
|
||||
final String filename = interfaceNameFromAttribute(tagLowerCase)+".java";
|
||||
return Paths.get(absPath.toString(),"tags/attributes/",filename);
|
||||
return Paths.get(absPath.toString(),relPath,filename);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package j2html_codegen.generators;
|
||||
|
||||
|
||||
import j2html_codegen.GeneratorUtil;
|
||||
import j2html_codegen.model.AttributesList;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -17,8 +18,14 @@ import static j2html_codegen.generators.TagCreatorCodeGenerator.emptyTags;
|
||||
|
||||
public final class SpecializedTagClassCodeGenerator {
|
||||
|
||||
private static final String relPath = "tags/specialized/generated";
|
||||
|
||||
public static void generate(final Path absPath, final boolean delete) throws IOException {
|
||||
|
||||
//delete all files in the directory for fresh generation
|
||||
final Path dir = Paths.get(absPath.toString(),relPath);
|
||||
GeneratorUtil.deleteAllFilesInDir(dir);
|
||||
|
||||
//the delete argument serves to give the possibility
|
||||
//to delete the classes that were written before
|
||||
System.out.println("// EmptyTags, generated in " + SpecializedTagClassCodeGenerator.class);
|
||||
@@ -47,12 +54,7 @@ public final class SpecializedTagClassCodeGenerator {
|
||||
}
|
||||
*/
|
||||
|
||||
if(delete){
|
||||
if(Files.exists(path)) {
|
||||
System.out.println("deleting " + path);
|
||||
Files.delete(path);
|
||||
}
|
||||
}else {
|
||||
if(!delete){
|
||||
System.out.println("writing to "+path);
|
||||
Files.write(path, classString.getBytes());
|
||||
}
|
||||
@@ -96,11 +98,11 @@ public final class SpecializedTagClassCodeGenerator {
|
||||
|
||||
private static Path makePath(final Path absPath, String tagLowerCase){
|
||||
final String filename = classNameFromTag(tagLowerCase)+".java";
|
||||
return Paths.get(absPath.toString(),"tags/specialized/",filename);
|
||||
return Paths.get(absPath.toString(),relPath,filename);
|
||||
}
|
||||
|
||||
private static String getPackage(){
|
||||
return "package j2html.tags.specialized;\n";
|
||||
return "package j2html.tags.specialized.generated;\n";
|
||||
}
|
||||
|
||||
private static String getClassTemplate(
|
||||
|
||||
Reference in New Issue
Block a user