NX01: Added nether tone kode gen and java module thus changed version
This commit is contained in:
parent
6659889ca8
commit
babb2cf188
47 changed files with 860 additions and 60 deletions
10
nx01-kode-gen/pom.xml
Normal file
10
nx01-kode-gen/pom.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>love.distributedrebirth.nx01</groupId>
|
||||
<artifactId>nx01</artifactId>
|
||||
<version>5786.SHEVAT〄.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>nx01-kode-gen</artifactId>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package love.distributedrebirth.nx01.kode.generator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import love.distributedrebirth.nx01.kode.generator.klass.ModelKlass;
|
||||
import love.distributedrebirth.nx01.kode.generator.klass.ModelKlassWriter;
|
||||
|
||||
/// Generated the nether tone interface tree forest.
|
||||
///
|
||||
/// @author للَّٰهِilLצسُو
|
||||
/// @version ©Δ∞ 仙上主天
|
||||
public class GenerateNetherTone {
|
||||
|
||||
private final static String SERIAL_VERSON_ID = "11";
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
List<String> argu = Arrays.asList(args);
|
||||
GenerateNetherTone gen = new GenerateNetherTone();
|
||||
boolean writeToFile = argu.contains("generate");
|
||||
if (argu.contains("based")) {
|
||||
gen.updateBased(writeToFile);
|
||||
} else {
|
||||
System.err.println("No command given.");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBased(boolean writeToFile) throws IOException {
|
||||
Path hashFile = new File("target/generated-sources.hash").toPath();
|
||||
if (hashFile.toFile().exists()) {
|
||||
String hash = Files.readString(hashFile);
|
||||
if (SERIAL_VERSON_ID.equals(hash)) {
|
||||
System.out.println("SKIPPED: Generated source are up to date");
|
||||
return;
|
||||
}
|
||||
}
|
||||
Files.writeString(hashFile, SERIAL_VERSON_ID);
|
||||
|
||||
ModelKlassWriter writer = new ModelKlassWriter("target/generated-sources");
|
||||
writer.setProlog(new File("../licence.txt"));
|
||||
|
||||
buildQuadrants(writer, 1, "ᐧᐧᐧ");
|
||||
buildQuadrants(writer, 2, "ᐧᐧᣟ");
|
||||
buildQuadrants(writer, 3, "ᐧᣟᐧ");
|
||||
buildQuadrants(writer, 4, "ᐧᣟᣟ");
|
||||
buildQuadrants(writer, 5, "ᣟᐧᐧ");
|
||||
buildQuadrants(writer, 6, "ᣟᐧᣟ");
|
||||
buildQuadrants(writer, 7, "ᣟᣟᐧ");
|
||||
buildQuadrants(writer, 8, "ᣟᣟᣟ");
|
||||
|
||||
createNetherQuadrant(writer, "NetherTone", "NetherToneQ", false);
|
||||
|
||||
// write all sources to files or stdout
|
||||
writer.write(writeToFile);
|
||||
}
|
||||
|
||||
private void buildQuadrants(ModelKlassWriter writer, int quadrant, String s) {
|
||||
String q = "ᐊQ" + quadrant;
|
||||
String e = "NetherToneQ" + quadrant;
|
||||
|
||||
writer.addModelKlass(buildNetherTreeSlug(s, q + "AG1", "ᐅ", 64, e));
|
||||
writer.addModelKlass(buildNetherTreeMutex(s, q + "AG1"));
|
||||
writer.addModelKlass(buildNetherTreeSlug(s, q + "AG2", "ᐅ", 64, e));
|
||||
writer.addModelKlass(buildNetherTreeMutex(s, q + "AG2"));
|
||||
writer.addModelKlass(buildNetherTreeSlug(s, q + "AG3", "ᐅ", 64, e));
|
||||
writer.addModelKlass(buildNetherTreeMutex(s, q + "AG3"));
|
||||
|
||||
writer.addModelKlass(buildNetherTreeSlug(s, q + "BL0W", "ᐅ", 512, e));
|
||||
writer.addModelKlass(buildNetherTreeMutex(s, q + "BL0W"));
|
||||
|
||||
writer.addModelKlass(buildNetherTreeSlug(s, q + "CR1", "ᐅ", 64, e));
|
||||
writer.addModelKlass(buildNetherTreeMutex(s, q + "CR1"));
|
||||
writer.addModelKlass(buildNetherTreeSlug(s, q + "CR2", "ᐅ", 64, e));
|
||||
writer.addModelKlass(buildNetherTreeMutex(s, q + "CR2"));
|
||||
writer.addModelKlass(buildNetherTreeSlug(s, q + "CR3", "ᐅ", 64, e));
|
||||
writer.addModelKlass(buildNetherTreeMutex(s, q + "CR3"));
|
||||
|
||||
writer.addModelKlass(buildNetherTreeSlug(s, q + "DB1", "ᐅ", 64, e));
|
||||
writer.addModelKlass(buildNetherTreeMutex(s, q + "DB1"));
|
||||
writer.addModelKlass(buildNetherTreeSlug(s, q + "DB2", "ᐅ", 64, e));
|
||||
writer.addModelKlass(buildNetherTreeMutex(s, q + "DB2"));
|
||||
writer.addModelKlass(buildNetherTreeSlug(s, q + "DB3", "ᐅ", 64, e));
|
||||
writer.addModelKlass(buildNetherTreeMutex(s, q + "DB3"));
|
||||
|
||||
writer.addModelKlass(buildNetherTreeSlug(s, q + "ER0W", "ᐅ", 512, e));
|
||||
writer.addModelKlass(buildNetherTreeMutex(s, q + "ER0W"));
|
||||
|
||||
createNetherQuadrant(writer, e, q, true); // permits all above
|
||||
}
|
||||
|
||||
private ModelKlass buildNetherTreeMutex(String subPackage, String javaName) {
|
||||
ModelKlass klass = new ModelKlass("ᒢᐩᐩ.ᑊᑉᒻᣔᔆᔆ.ᣕᓫᐪᑋᓫᣗ.ᐪᐤᣕᓫ." + subPackage, javaName + "Mutex");
|
||||
StringBuilder buf = klass.getBody();
|
||||
buf.append("interface ");
|
||||
buf.append(klass.getJavaName());
|
||||
buf.append("<T> {\n");
|
||||
buf.append("}\n");
|
||||
return klass;
|
||||
}
|
||||
|
||||
private ModelKlass buildNetherTreeSlug(String subPackage, String javaName, String slugName, int slugSize, String quadrant) {
|
||||
ModelKlass klass = new ModelKlass("ᒢᐩᐩ.ᑊᑉᒻᣔᔆᔆ.ᣕᓫᐪᑋᓫᣗ.ᐪᐤᣕᓫ." + subPackage, javaName);
|
||||
klass.addJavaImport("ᒢᐩᐩ.ᑊᑉᒻᣔᔆᔆ.ᣕᓫᐪᑋᓫᣗ.ᐪᐤᣕᓫ."+quadrant);
|
||||
StringBuilder buf = klass.getBody();
|
||||
buf.append("public sealed interface ");
|
||||
buf.append(klass.getJavaName());
|
||||
buf.append(" extends ");
|
||||
buf.append(quadrant);
|
||||
buf.append(" {\n");
|
||||
for (int i = 1 ; i <= slugSize; i++) {
|
||||
String partCode = String.format("%03d", i);
|
||||
String clsBase = slugName + partCode + " extends " + klass.getJavaName();
|
||||
String clsMutexExt = ", " + javaName + "Mutex<" + slugName + partCode + ">";
|
||||
buf.append("\tnon-sealed interface "+clsBase+clsMutexExt+" {}\n");
|
||||
}
|
||||
buf.append("}\n");
|
||||
return klass;
|
||||
}
|
||||
|
||||
private void createNetherQuadrant(ModelKlassWriter writer, String javaName, String javaSearch, boolean child) {
|
||||
ModelKlass klass = new ModelKlass("ᒢᐩᐩ.ᑊᑉᒻᣔᔆᔆ.ᣕᓫᐪᑋᓫᣗ.ᐪᐤᣕᓫ", javaName);
|
||||
StringBuilder buf = klass.getBody();
|
||||
buf.append("public sealed interface ");
|
||||
buf.append(klass.getJavaName());
|
||||
if (child) {
|
||||
buf.append(" extends NetherTone");
|
||||
}
|
||||
buf.append(" permits\n");
|
||||
Stream<ModelKlass> f = writer.getModelKlasses().stream().filter(v -> !v.getJavaName().contains("Mutex")).filter(v -> v.getJavaName().contains(javaSearch));
|
||||
for (Iterator<ModelKlass> i = f.iterator(); i.hasNext() ;) {
|
||||
ModelKlass mk = i.next();
|
||||
if (child) {
|
||||
klass.addJavaImport(mk.getJavaPackage() + "." + mk.getJavaName());
|
||||
}
|
||||
buf.append("\t");
|
||||
buf.append(mk.getJavaName());
|
||||
if (i.hasNext()) {
|
||||
buf.append(",\n");
|
||||
} else {
|
||||
buf.append("\n");
|
||||
}
|
||||
}
|
||||
buf.append("\t{\n");
|
||||
buf.append("}\n");
|
||||
writer.addModelKlass(klass);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package love.distributedrebirth.nx01.kode.generator.klass;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/// Java model klass.
|
||||
///
|
||||
/// @author للَّٰهِilLצسُو
|
||||
/// @version ©Δ∞ 仙上主天
|
||||
public class ModelKlass {
|
||||
|
||||
private final File javaFile;
|
||||
private final String javaPackage;
|
||||
private final String javaName;
|
||||
private final List<String> javaDescriptions;
|
||||
private final List<String> javaImports;
|
||||
private final StringBuilder body;
|
||||
|
||||
public ModelKlass(String javaPackage, String javaName) {
|
||||
this.javaPackage = Objects.requireNonNull(javaPackage);
|
||||
this.javaName = Objects.requireNonNull(javaName);
|
||||
this.javaDescriptions = new ArrayList<>();
|
||||
String packageFolder = javaPackage.replaceAll("\\.", "/");
|
||||
String filePath = packageFolder + "/" + javaName + ".java";
|
||||
this.javaFile = new File(filePath);
|
||||
this.javaImports = new ArrayList<>();
|
||||
this.body = new StringBuilder();
|
||||
}
|
||||
|
||||
public File getJavaFile() {
|
||||
return javaFile;
|
||||
}
|
||||
|
||||
public void addJavaImport(String javaKlass) {
|
||||
if (javaImports.contains(javaKlass)) {
|
||||
return;
|
||||
}
|
||||
javaImports.add(javaKlass);
|
||||
}
|
||||
|
||||
public List<String> getJavaImports() {
|
||||
return javaImports;
|
||||
}
|
||||
|
||||
public String getJavaPackage() {
|
||||
return javaPackage;
|
||||
}
|
||||
|
||||
public String getJavaName() {
|
||||
return javaName;
|
||||
}
|
||||
|
||||
public void addJavaDescription(String javaDescription) {
|
||||
javaDescriptions.add(javaDescription);
|
||||
}
|
||||
|
||||
public List<String> getJavaDescriptions() {
|
||||
return javaDescriptions;
|
||||
}
|
||||
|
||||
public StringBuilder getBody() {
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package love.distributedrebirth.nx01.kode.generator.klass;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/// Java klass model writer.
|
||||
///
|
||||
/// @author للَّٰهِilLצسُو
|
||||
/// @version ©Δ∞ 仙上主天
|
||||
public class ModelKlassWriter {
|
||||
|
||||
private final List<ModelKlass> klasses = new ArrayList<>();
|
||||
private File prolog;
|
||||
private Path outputPath;
|
||||
|
||||
public ModelKlassWriter(String outputPath) {
|
||||
this.outputPath = FileSystems.getDefault().getPath(Objects.requireNonNull(outputPath));
|
||||
}
|
||||
|
||||
public void setProlog(File prolog) {
|
||||
this.prolog = prolog;
|
||||
}
|
||||
|
||||
public List<ModelKlass> getModelKlasses() {
|
||||
return klasses;
|
||||
}
|
||||
|
||||
public void addModelKlass(ModelKlass klass) {
|
||||
klasses.add(Objects.requireNonNull(klass));
|
||||
}
|
||||
|
||||
public void write(boolean writeFile) throws IOException {
|
||||
if (writeFile) {
|
||||
if (!outputPath.toFile().exists()) {
|
||||
outputPath.toFile().mkdirs();
|
||||
}
|
||||
}
|
||||
for (ModelKlass klass : klasses) {
|
||||
String content = writeKlass(klass);
|
||||
if (writeFile) {
|
||||
Path outFile = outputPath.resolve(klass.getJavaFile().toPath());
|
||||
outFile.toFile().getParentFile().mkdirs();
|
||||
outFile.toFile().createNewFile();
|
||||
Files.writeString(outFile, content);
|
||||
System.out.println("Wrote file: " + klass.getJavaFile());
|
||||
} else {
|
||||
System.out.println("Debug file: " + klass.getJavaFile());
|
||||
System.out.println(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String writeKlass(ModelKlass klass) throws IOException {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
writeKlassProlog(buf);
|
||||
writeKlassHeader(buf, klass);
|
||||
buf.append(klass.getBody());
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private void writeKlassProlog(StringBuilder buf) throws IOException {
|
||||
if (prolog == null) {
|
||||
return;
|
||||
}
|
||||
if (!prolog.canRead()) {
|
||||
return;
|
||||
}
|
||||
List<String> prologLines = Files.readAllLines(prolog.toPath());
|
||||
buf.append("/*\n");
|
||||
for (Iterator<String> i = prologLines.iterator(); i.hasNext() ;) {
|
||||
buf.append(" * ");
|
||||
buf.append(i.next());
|
||||
buf.append("\n");
|
||||
}
|
||||
buf.append(" */\n");
|
||||
buf.append("\n");
|
||||
}
|
||||
|
||||
private void writeKlassHeader(StringBuilder buf, ModelKlass klass) throws IOException {
|
||||
buf.append("package ");
|
||||
buf.append(klass.getJavaPackage());
|
||||
buf.append(";\n");
|
||||
buf.append("\n");
|
||||
for (String javaImport : klass.getJavaImports()) {
|
||||
buf.append("import ");
|
||||
buf.append(javaImport);
|
||||
buf.append(";\n");
|
||||
}
|
||||
buf.append("\n");
|
||||
for (String javaDescription : klass.getJavaDescriptions()) {
|
||||
buf.append("/// ");
|
||||
buf.append(javaDescription);
|
||||
buf.append("\n");
|
||||
}
|
||||
buf.append("/// @author للَّٰهِilLצسُو\n");
|
||||
buf.append("/// @version ©Δ∞ 仙上主天\n");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue