3838import java .io .BufferedReader ;
3939import java .io .IOException ;
4040import java .io .FileWriter ;
41- import java .lang .StringBuilder ;
4241
4342import java .nio .file .Files ;
4443import java .nio .file .Path ;
4544import java .nio .file .Paths ;
45+ import java .util .ArrayList ;
4646import java .util .List ;
4747import java .util .stream .Collectors ;
4848import java .util .stream .Stream ;
@@ -123,7 +123,7 @@ public void run() {
123123 String extraLibs = getJarsInDir (Paths .get (Preferences .getSketchbookPath ()+(isWindows ?'\\' :'/' )+"libraries" ));
124124 extraLibs += getJarsInDir (folder );
125125 extraLibs += getJarsInDir (Platform .getContentFile ("modes/java/libraries" ));
126- SketchCode codes [] = sketch .getCode ();
126+ SketchCode [] codes = sketch .getCode ();
127127 String mainTab = codes [0 ].getProgram ();
128128 if (!mainTab .contains ("setup" ) && !mainTab .contains ("draw" )) {
129129 System .err .println ("Can only generate JavaDoc for sketches in dynamic mode." );
@@ -135,42 +135,47 @@ public void run() {
135135
136136 StringBuilder main = new StringBuilder ();
137137 StringBuilder imports = new StringBuilder ();
138+ List <String > javaFiles = new ArrayList <>();
138139
139140 for (SketchCode c : codes ) {
140- String tab = c .getProgram ();
141- boolean hasImports = tab .indexOf ("import" )>=0 ;
142- if (hasImports ) {
143- String [] code = tab .split ("\n " );
144- boolean blockComment = false ;
145- for (String line : code ) {
146- if (blockComment ) {
147- int stopComment = line .indexOf ("*/" );
148- if (stopComment >= 0 ) {
141+ if (c .getExtension ().equals ("java" )) {
142+ javaFiles .add (c .getFile ().getAbsolutePath ());
143+ } else {
144+ String tab = c .getProgram ();
145+ boolean hasImports = tab .indexOf ("import" )>=0 ;
146+ if (hasImports ) {
147+ String [] code = tab .split ("\n " );
148+ boolean blockComment = false ;
149+ for (String line : code ) {
150+ if (blockComment ) {
151+ int stopComment = line .indexOf ("*/" );
152+ if (stopComment >= 0 ) {
153+ int startComment = line .indexOf ("/*" );
154+ if (startComment < stopComment ) {
155+ blockComment = false ;
156+ }
157+ }
158+ } else {
159+ int lineComment = line .indexOf ("//" );
149160 int startComment = line .indexOf ("/*" );
150- if (startComment < stopComment ) {
151- blockComment = false ;
161+ if (startComment >= 0 && (lineComment < 0 || lineComment > startComment )) {
162+ int stopComment = line .indexOf ("*/" );
163+ if (startComment > stopComment ) {
164+ blockComment = true ;
152165 }
153- }
154- } else {
155- int lineComment = line .indexOf ("//" );
156- int startComment = line .indexOf ("/*" );
157- if (startComment >= 0 && (lineComment < 0 || lineComment > startComment )) {
158- int stopComment = line .indexOf ("*/" );
159- if (startComment > stopComment ) {
160- blockComment = true ;
161166 }
162167 }
168+ if (!blockComment && line .trim ().startsWith ("import" )) {
169+ imports .append (line );
170+ imports .append ("\n " );
171+ } else {
172+ main .append (line );
173+ main .append ("\n " );
174+ }
163175 }
164- if (!blockComment && line .trim ().startsWith ("import" )) {
165- imports .append (line );
166- imports .append ("\n " );
167- } else {
168- main .append (line );
169- main .append ("\n " );
170- }
176+ } else {
177+ main .append (tab );
171178 }
172- } else {
173- main .append (tab );
174179 }
175180 }
176181
@@ -182,18 +187,24 @@ public void run() {
182187 // then Sketch main class
183188 myWriter .write ("import processing.core.*;\n import processing.data.*;\n import processing.event.*;\n import processing.opengl.*;\n import java.util.HashMap;\n import java.util.ArrayList;\n import java.io.File;\n import java.io.BufferedReader;\n import java.io.PrintWriter;\n import java.io.InputStream;\n import java.io.OutputStream;\n import java.io.IOException;\n \n " );
184189
185- myWriter .write ("/** " +sketch .getName ()+" */\n public class " +sketch .getName ()+" {\n " );
190+ myWriter .write ("/** Processing Sketch " +sketch .getName ()+" */\n public class " +sketch .getName ()+" {\n " );
186191 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" ));
187192 myWriter .write ("\n }\n \n " );
188193 myWriter .close ();
189194
190- ProcessBuilder builder = new ProcessBuilder (
191- System .getProperty ("java.home" ) + (isWindows ?"\\ bin\\ javadoc" :"/bin/javadoc" ),
192- src .getAbsolutePath (),
193- "-d" , ref .getAbsolutePath (),
194- "-package" , "-quiet" ,
195- "-cp" , System .getProperty ("java.class.path" ) + extraLibs
196- );
195+ List <String > command = new ArrayList <>();
196+ command .add (System .getProperty ("java.home" ) + (isWindows ?"\\ bin\\ javadoc" :"/bin/javadoc" ));
197+ command .add (src .getAbsolutePath ());
198+ for (String j : javaFiles ) {
199+ command .add (j );
200+ }
201+ command .add ("-d" );
202+ command .add (ref .getAbsolutePath ());
203+ command .add ("-package" );
204+ command .add ("-quiet" );
205+ command .add ("-cp" );
206+ command .add (System .getProperty ("java.class.path" ) + extraLibs );
207+ ProcessBuilder builder = new ProcessBuilder (command );
197208 Process process = builder .start ();
198209
199210 String lines ;
0 commit comments