ajkdwqn;kfnewkfnkenfkjer
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.lumijiez;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.lumijiez.models.Package;
|
||||
@@ -8,11 +9,13 @@ import org.lumijiez.parser.WinxParser;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -38,17 +41,36 @@ public class Main {
|
||||
|
||||
// Retrieve the collected data and save it to JSON
|
||||
List<Package> packages = collector.getPackages();
|
||||
saveAsJson(packages, "output.json");
|
||||
String json = saveAsJson(packages, "output.json");
|
||||
|
||||
System.out.println("Data successfully saved to 'output.json'.");
|
||||
|
||||
Path templatePath = Path.of(Objects.requireNonNull(Main.class.getResource("/graph.html")).toURI());
|
||||
String htmlTemplate = Files.readString(templatePath);
|
||||
|
||||
// Replace placeholder with JSON
|
||||
String finalHtmlContent = htmlTemplate.replace("const jsonData = null;", "const jsonData = " + json + ";");
|
||||
|
||||
// Save the modified HTML to a temporary file and open in a browser
|
||||
Path tempFile = Files.createTempFile("output", ".html");
|
||||
Files.writeString(tempFile, finalHtmlContent);
|
||||
Desktop.getDesktop().browse(tempFile.toUri());
|
||||
|
||||
System.out.println("HTML with JSON data successfully opened in a browser.");
|
||||
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
System.err.println("Error processing the input file: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveAsJson(List<Package> packages, String filePath) throws IOException {
|
||||
private static String saveAsJson(List<Package> packages, String filePath) throws IOException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
// Write JSON output to a file with pretty printing
|
||||
mapper.writerWithDefaultPrettyPrinter().writeValue(new File(filePath), packages);
|
||||
try {
|
||||
String jsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(packages);
|
||||
Files.writeString(Paths.get(filePath), jsonString);
|
||||
return jsonString;
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IOException("Failed to serialize data to JSON", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,10 @@ public class WinxCollector extends WinxBaseVisitor<Void> {
|
||||
|
||||
function.addReturnType(new Variable(ctx.function_body().return_type().variable().type().getText(), ctx.function_body().return_type().variable().ID().getText()));
|
||||
|
||||
if (ctx.importance() != null) {
|
||||
function.setImportance(ctx.importance().getText());
|
||||
}
|
||||
|
||||
if (ctx.impls() != null) function.setImplemented_interface(ctx.impls().ID().getText());
|
||||
|
||||
if (ctx.function_body().specification_entry() != null)
|
||||
|
||||
@@ -6,6 +6,7 @@ public class FunctionSpec {
|
||||
private final String name;
|
||||
private String access_modifier;
|
||||
private String implemented_interface = "none";
|
||||
private String importance = "none";
|
||||
private final List<Variable> inputTypes = new ArrayList<>();
|
||||
private final List<Variable> returnTypes = new ArrayList<>();
|
||||
private final List<SpecificationEntry> specificationEntries = new ArrayList<>();
|
||||
@@ -57,5 +58,13 @@ public class FunctionSpec {
|
||||
public void setImplemented_interface(String implemented_interface) {
|
||||
this.implemented_interface = implemented_interface;
|
||||
}
|
||||
|
||||
public String getImportance() {
|
||||
return importance;
|
||||
}
|
||||
|
||||
public void setImportance(String importance) {
|
||||
this.importance = importance;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user