mirror of
https://github.com/processing/processing4.git
synced 2026-02-18 12:55:49 +01:00
Added doclet and changed comments in PApplet.java
This commit is contained in:
114
doclet/ReferenceGenerator/src/writers/FieldWriter.java
Normal file
114
doclet/ReferenceGenerator/src/writers/FieldWriter.java
Normal file
@@ -0,0 +1,114 @@
|
||||
package writers;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.io.*;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
import com.sun.javadoc.FieldDoc;
|
||||
import com.sun.javadoc.Tag;
|
||||
|
||||
import org.json.*;
|
||||
|
||||
|
||||
public class FieldWriter extends BaseWriter {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param vars inherited from containing ClassDoc
|
||||
* @param doc
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
public static void write(HashMap<String, String> vars, FieldDoc doc, String classname) throws IOException
|
||||
{
|
||||
String filename = getAnchor(doc);
|
||||
TemplateWriter templateWriter = new TemplateWriter();
|
||||
|
||||
JSONObject fieldJSON = new JSONObject();
|
||||
|
||||
String fileName;
|
||||
if (classname != "") {
|
||||
fileName = jsonDir + classname + "_" + getName(doc) + ".json";
|
||||
} else {
|
||||
fileName = jsonDir + getName(doc) + ".json";
|
||||
}
|
||||
|
||||
Tag[] tags = doc.tags(Shared.i().getWebrefTagName());
|
||||
String category = getCategory(tags[0]);
|
||||
String subcategory = getSubcategory(tags[0]);
|
||||
|
||||
try
|
||||
{
|
||||
fieldJSON.put("type", "field");
|
||||
fieldJSON.put("description", getWebDescriptionFromSource(doc));
|
||||
fieldJSON.put("brief", getWebBriefFromSource(doc));
|
||||
fieldJSON.put("category", category);
|
||||
fieldJSON.put("subcategory", subcategory);
|
||||
fieldJSON.put("name", getName(doc));
|
||||
fieldJSON.put("related", getRelated(doc));
|
||||
|
||||
if(Shared.i().isRootLevel(doc.containingClass())){
|
||||
fieldJSON.put("classname", "");
|
||||
} else {
|
||||
fieldJSON.put("classanchor", getLocalAnchor(doc.containingClass()));
|
||||
fieldJSON.put("parameters", getParentParam(doc));
|
||||
String syntax = templateWriter.writePartial("field.syntax.partial.html", getSyntax(doc));
|
||||
ArrayList<String> syntaxList = new ArrayList<String>();
|
||||
syntaxList.add(syntax);
|
||||
fieldJSON.put("syntax", syntaxList);
|
||||
}
|
||||
} catch (JSONException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
FileWriter file = new FileWriter(fileName);
|
||||
file.write(fieldJSON.toString());
|
||||
file.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void write(FieldDoc doc) throws IOException
|
||||
{
|
||||
String classname = "";
|
||||
write(new HashMap<String, String>(), doc, classname);
|
||||
}
|
||||
|
||||
protected static HashMap<String, String> getSyntax(FieldDoc doc){
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("object", getInstanceName(doc));
|
||||
map.put("field", getName(doc));
|
||||
return map;
|
||||
}
|
||||
|
||||
protected static ArrayList<JSONObject> getParentParam(FieldDoc doc){
|
||||
ArrayList<JSONObject> retList = new ArrayList<JSONObject>();
|
||||
JSONObject ret = new JSONObject();
|
||||
try
|
||||
{
|
||||
ret.put("name", getInstanceName(doc));
|
||||
ret.put("desc", getInstanceDescription(doc));
|
||||
} catch (JSONException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
retList.add(ret);
|
||||
return retList;
|
||||
}
|
||||
|
||||
protected static HashMap<String, String> getParent(FieldDoc doc){
|
||||
HashMap<String, String> parent = new HashMap<String, String>();
|
||||
ClassDoc cd = doc.containingClass();
|
||||
parent.put("name", getInstanceName(doc));
|
||||
parent.put("name", getInstanceName(doc));
|
||||
parent.put("type", cd.name());
|
||||
parent.put("description", getInstanceDescription(doc));
|
||||
return parent;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user