Skip to content

Commit ec58258

Browse files
committed
using xml to document the library methods that aren't explicitly written in source code.
1 parent bd5a9c7 commit ec58258

File tree

10 files changed

+68
-32
lines changed

10 files changed

+68
-32
lines changed
60 Bytes
Binary file not shown.
510 Bytes
Binary file not shown.
268 Bytes
Binary file not shown.
Binary file not shown.

java_generate/ReferenceGenerator/src/writers/BaseWriter.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838

3939
public class BaseWriter {
4040
// Some utilities
41-
static ArrayList<String> writtenElements;
42-
public BaseWriter() {
43-
41+
42+
public BaseWriter()
43+
{
44+
4445
}
4546

4647
protected static boolean needsWriting(ProgramElementDoc doc){
@@ -55,15 +56,20 @@ protected static BufferedWriter makeWriter(String anchor) throws IOException
5556
{
5657
return makeWriter(anchor, false);
5758
}
58-
59-
protected static BufferedWriter makeWriter(String anchor, Boolean isLocal) throws IOException {
60-
FileWriter fw;
59+
60+
protected static String getWriterPath( String anchor, Boolean isLocal )
61+
{
6162
if (!isLocal) {
62-
fw = new FileWriter(Shared.i().getOutputDirectory() + "/" + anchor );
63+
return Shared.i().getOutputDirectory() + "/" + anchor;
6364
} else
6465
{
65-
fw = new FileWriter(Shared.i().getLocalOutputDirectory() + anchor );
66+
return Shared.i().getLocalOutputDirectory() + anchor;
6667
}
68+
}
69+
70+
protected static BufferedWriter makeWriter(String anchor, Boolean isLocal) throws IOException {
71+
FileWriter fw = new FileWriter( getWriterPath( anchor, isLocal ) );
72+
6773
return new BufferedWriter(fw);
6874
}
6975

@@ -239,6 +245,7 @@ protected static String getXMLPath(ProgramElementDoc doc) {
239245
path = path + "LIB_" + pkg[pkg.length-1] + "/";
240246
}
241247

248+
242249
return path + name + suffix;
243250
}
244251

java_generate/ReferenceGenerator/src/writers/ClassWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ClassWriter extends BaseWriter {
1717

1818
public ClassWriter() {
1919

20-
}
20+
}
2121

2222
@SuppressWarnings("unchecked")
2323
public void write( ClassDoc classDoc ) throws IOException {

java_generate/ReferenceGenerator/src/writers/LibraryWriter.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package writers;
22

3+
import java.io.File;
34
import java.io.IOException;
45
import java.util.ArrayList;
56

@@ -11,7 +12,7 @@ public class LibraryWriter extends BaseWriter {
1112
String pkg;
1213
LibraryIndexWriter indexWriter;
1314
String dir;
14-
ArrayList<String> filesRead;
15+
1516
static TemplateWriter templateWriter;
1617
static ArrayList<String> writtenLibraries;
1718

@@ -23,7 +24,7 @@ public LibraryWriter(){
2324
writtenLibraries = new ArrayList<String>();
2425
}
2526

26-
filesRead = new ArrayList<String>();
27+
2728
}
2829

2930
public void write(PackageDoc doc)
@@ -46,19 +47,33 @@ public void write(PackageDoc doc)
4647
//grab all relevant information for the doc
4748
for( ClassDoc classDoc : doc.allClasses() ){
4849
// document the class if it has a @webref tag
49-
try {
50+
try
51+
{
5052
new ClassWriter().write(classDoc);
51-
} catch (IOException e) {
53+
54+
} catch (IOException e)
55+
{
5256
// TODO Auto-generated catch block
5357
e.printStackTrace();
5458
}
5559
}
5660

57-
writeRemainingXml( "path/to/files" );
61+
String path = Shared.i().getXMLDirectory() + "LIB_" + pkg;
62+
writeRemainingXml( path);
5863
}
5964

6065
private void writeRemainingXml( String xmlDir )
6166
{
62-
67+
File directory = new File( xmlDir );
68+
File[] files = directory.listFiles();
69+
for( File f : files )
70+
{
71+
if( f.getAbsolutePath().endsWith("xml") )
72+
{
73+
// try writing everything (will not overwrite any existing docs)
74+
XMLReferenceWriter.parseFile( f.getAbsoluteFile(), dir, indexWriter );
75+
}
76+
77+
}
6378
}
6479
}

java_generate/ReferenceGenerator/src/writers/TemplateWriter.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package writers;
22

33
import java.io.BufferedWriter;
4+
import java.io.File;
45
import java.io.IOException;
56
import java.util.ArrayList;
67
import java.util.HashMap;
@@ -38,14 +39,15 @@ public void write( String templateName, HashMap<String, String> vars, String out
3839
vars.put("isLanguage", "class='active'");
3940
}
4041

41-
write( templateName, vars, outputName, false );
42+
Boolean written = write( templateName, vars, outputName, false );
4243
write( templateName, vars, outputName, true );
43-
if(Shared.i().isNoisy()){
44-
System.out.println("Writing " + outputName + " from template");
44+
if( written && Shared.i().isNoisy() )
45+
{
46+
System.out.println("Wrote " + outputName + " from template");
4547
}
4648
}
4749

48-
private void write( String templateName, HashMap<String, String> vars, String outputName, Boolean isLocal ) throws IOException
50+
private Boolean write( String templateName, HashMap<String, String> vars, String outputName, Boolean isLocal ) throws IOException
4951
{
5052
String[] templateFile = FileUtils.loadStrings(Shared.i().TEMPLATE_DIRECTORY() + templateName);
5153
ArrayList<String> output = new ArrayList<String>();
@@ -58,19 +60,30 @@ private void write( String templateName, HashMap<String, String> vars, String ou
5860
vars.put("navigation", writePartial("Nav.web.template.html", vars));
5961
}
6062

61-
BufferedWriter out = makeWriter(outputName, isLocal);
63+
File f = new File( getWriterPath( outputName, isLocal ) );
6264

63-
for( String line : templateFile )
64-
{
65-
//check if it contains a variable we want to replace, then replace it
66-
line = writeLine(line, vars, false);
67-
output.add(line);
65+
if( ! f.exists() )
66+
{
67+
BufferedWriter out = makeWriter(outputName, isLocal);
68+
69+
for( String line : templateFile )
70+
{
71+
//check if it contains a variable we want to replace, then replace it
72+
line = writeLine(line, vars, false);
73+
output.add(line);
74+
}
75+
for( String line : output )
76+
{
77+
out.write(line+"\n");
78+
}
79+
out.close();
80+
81+
return true;
6882
}
69-
for( String line : output )
83+
else
7084
{
71-
out.write(line+"\n");
85+
return false;
7286
}
73-
out.close();
7487
}
7588

7689
public String writePartial( String templateName, HashMap<String, String> vars )

java_generate/ReferenceGenerator/src/writers/XMLReferenceWriter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static void write(String sourceDir, String dstDir, IndexWriter indexWrite
4343
}
4444
}
4545

46-
private static void parseFile(File f, String dst, IndexWriter indexWriter)
46+
public static void parseFile(File f, String dst, IndexWriter indexWriter)
4747
{
4848
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
4949
factory.setNamespaceAware(true);
@@ -132,11 +132,11 @@ private static void parseFile(File f, String dst, IndexWriter indexWriter)
132132
{ // get constructor parameters
133133
vars.put("parameters", getParameters(doc, "c" ));
134134
}
135-
templateWriter.write("Class.template.html", vars, anchor);
135+
templateWriter.write("Class.template.html", vars, dst + anchor);
136136
}
137137
else
138138
{
139-
templateWriter.write("Generic.template.html", vars, anchor);
139+
templateWriter.write("Generic.template.html", vars, dst + anchor);
140140
}
141141

142142
} catch (XPathExpressionException e) {

todo.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ $ For the functions inside PGraphics and PImage, the Related links aren't workin
7474

7575
DAVID
7676

77-
$ How to make a reference for captureEvent() etc in the Libraries
77+
x? How to make a reference for captureEvent() etc in the Libraries
7878
will approach with .xml files, like include/ for boolean/true/while/etc.
7979
Complete list of functions not found in libraries:
8080
1.Video
@@ -85,6 +85,7 @@ $ How to make a reference for captureEvent() etc in the Libraries
8585
serialEvent()
8686
3. Network
8787
All "Network Events"
88+
The script now checks all the .xml files for the library and will write out html for ones that haven't been documented through source code
8889

8990
- Variable types that include 'boolean[], byte[], char[], int[], float[], or String[]' are not displaying correctly in the Parameters section:
9091
e.g. shorten(), splice(), and sort()

0 commit comments

Comments
 (0)