From cadc961499edb7f5e824f40499840d1ab1c5d72f Mon Sep 17 00:00:00 2001 From: Henning Kiel Date: Tue, 7 May 2024 11:21:13 +0200 Subject: [PATCH] put .java tabs in separate files outside sketch class --- resources/build.properties | 6 +-- src/javadoc/tool/JavaDoc.java | 87 ++++++++++++++++++++--------------- 2 files changed, 52 insertions(+), 41 deletions(-) diff --git a/resources/build.properties b/resources/build.properties index 935245f..0c2ae3f 100644 --- a/resources/build.properties +++ b/resources/build.properties @@ -134,12 +134,12 @@ source.repository=https://github.com/hkiel/JavaDoc.git # This is used to compare different versions of the same Tool, and check if an # update is available. -tool.version=6 +tool.version=7 # The version as the user will see it. -tool.prettyVersion=1.0.5 +tool.prettyVersion=1.0.6 # The min and max revision of Processing compatible with your Tool. @@ -162,7 +162,7 @@ tested.processingVersion=4.2 # Additional information for the generated webpage. -tool.copyright=(c) 2023 +tool.copyright=(c) 2024 tool.dependencies=? tool.keywords=javadoc diff --git a/src/javadoc/tool/JavaDoc.java b/src/javadoc/tool/JavaDoc.java index 651420b..8876af0 100644 --- a/src/javadoc/tool/JavaDoc.java +++ b/src/javadoc/tool/JavaDoc.java @@ -38,11 +38,11 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.FileWriter; -import java.lang.StringBuilder; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -123,7 +123,7 @@ public void run() { String extraLibs = getJarsInDir(Paths.get(Preferences.getSketchbookPath()+(isWindows?'\\':'/')+"libraries")); extraLibs += getJarsInDir(folder); extraLibs += getJarsInDir(Platform.getContentFile("modes/java/libraries")); - SketchCode codes[] = sketch.getCode(); + SketchCode[] codes = sketch.getCode(); String mainTab = codes[0].getProgram(); if (!mainTab.contains("setup") && !mainTab.contains("draw")) { System.err.println("Can only generate JavaDoc for sketches in dynamic mode."); @@ -135,42 +135,47 @@ public void run() { StringBuilder main = new StringBuilder(); StringBuilder imports = new StringBuilder(); + List javaFiles = new ArrayList<>(); for (SketchCode c : codes) { - String tab = c.getProgram(); - boolean hasImports = tab.indexOf("import")>=0; - if (hasImports) { - String[] code = tab.split("\n"); - boolean blockComment = false; - for (String line : code) { - if (blockComment) { - int stopComment = line.indexOf("*/"); - if (stopComment >= 0) { + if (c.getExtension().equals("java")) { + javaFiles.add(c.getFile().getAbsolutePath()); + } else { + String tab = c.getProgram(); + boolean hasImports = tab.indexOf("import")>=0; + if (hasImports) { + String[] code = tab.split("\n"); + boolean blockComment = false; + for (String line : code) { + if (blockComment) { + int stopComment = line.indexOf("*/"); + if (stopComment >= 0) { + int startComment = line.indexOf("/*"); + if (startComment < stopComment) { + blockComment = false; + } + } + } else { + int lineComment = line.indexOf("//"); int startComment = line.indexOf("/*"); - if (startComment < stopComment) { - blockComment = false; + if (startComment >= 0 && (lineComment < 0 || lineComment > startComment)) { + int stopComment = line.indexOf("*/"); + if (startComment > stopComment) { + blockComment = true; } - } - } else { - int lineComment = line.indexOf("//"); - int startComment = line.indexOf("/*"); - if (startComment >= 0 && (lineComment < 0 || lineComment > startComment)) { - int stopComment = line.indexOf("*/"); - if (startComment > stopComment) { - blockComment = true; } } + if (!blockComment && line.trim().startsWith("import")) { + imports.append(line); + imports.append("\n"); + } else { + main.append(line); + main.append("\n"); + } } - if (!blockComment && line.trim().startsWith("import")) { - imports.append(line); - imports.append("\n"); - } else { - main.append(line); - main.append("\n"); - } + } else { + main.append(tab); } - } else { - main.append(tab); } } @@ -182,18 +187,24 @@ public void run() { // then Sketch main class myWriter.write("import processing.core.*;\nimport processing.data.*;\nimport processing.event.*;\nimport processing.opengl.*;\nimport java.util.HashMap;\nimport java.util.ArrayList;\nimport java.io.File;\nimport java.io.BufferedReader;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\n\n"); - myWriter.write("/** "+sketch.getName()+" */\npublic class "+sketch.getName()+" {\n"); + myWriter.write("/** Processing Sketch "+sketch.getName()+" */\npublic class "+sketch.getName()+" {\n"); myWriter.write(main.toString().replace("#", "0x").replaceAll("\\bint\\b\\s*[(]", "PApplet.parseInt(").replaceAll("\\bfloat\\b\\s*[(]", "PApplet.parseFloat(").replaceAll("\\bboolean\\b\\s*[(]", "PApplet.parseBoolean(").replaceAll("\\bbyte\\b\\s*[(]", "PApplet.parseByte(").replaceAll("\\bchar\\b\\s*[(]", "PApplet.parseChar(").replaceAll("\\b(color)\\b\\s*([^\\(])", "int $2")); myWriter.write("\n}\n\n"); myWriter.close(); - ProcessBuilder builder = new ProcessBuilder( - System.getProperty("java.home") + (isWindows?"\\bin\\javadoc":"/bin/javadoc"), - src.getAbsolutePath(), - "-d", ref.getAbsolutePath(), - "-package", "-quiet", - "-cp", System.getProperty("java.class.path") + extraLibs - ); + List command = new ArrayList<>(); + command.add(System.getProperty("java.home") + (isWindows?"\\bin\\javadoc":"/bin/javadoc")); + command.add(src.getAbsolutePath()); + for (String j : javaFiles) { + command.add(j); + } + command.add("-d"); + command.add(ref.getAbsolutePath()); + command.add("-package"); + command.add("-quiet"); + command.add("-cp"); + command.add(System.getProperty("java.class.path") + extraLibs); + ProcessBuilder builder = new ProcessBuilder(command); Process process = builder.start(); String lines;