001package Torello.Browser.JsonAST; 002 003import Torello.Java.UnreachableError; 004 005/** 006 * Generates HTML for all Properties, Parameters and Return-Values, which are all stored in the 007 * AST as {@link PPR} nodes. 008 */ 009@Torello.JavaDoc.Annotations.StaticFunctional 010@Torello.JavaDoc.Annotations.JDHeaderBackgroundImg(EmbedTagFileID="TOHTML_JDHBI") 011public class HTML$PPR 012{ 013 private HTML$PPR() { } 014 015 static String run(final PPR ppr) 016 { 017 final TypeNode REFERENCE = ppr.reference(); 018 final TypeNode REFERENCE_ARRAY = ppr.referenceArray(); 019 020 String tempFlagsStr = 021 (ppr.optional ? "[OPTIONAL]<BR />\n" : "") + 022 (ppr.experimental ? "[EXPERIMENTAL]<BR />\n" : "") + 023 (ppr.deprecated ? "[DEPRECATED]<BR />\n" : ""); 024 025 final String flagsStr = (tempFlagsStr.length() == 0) ? "-" : tempFlagsStr; 026 027 final String typeStr, anchor; 028 029 if (ppr.ref != null) 030 031 anchor = 032 "<A HREF=\"javascript:GOTO(" + 033 "'" + fixAPIName(REFERENCE.ownerDomain.ownerAPI.name) + "', '" + 034 REFERENCE.ownerDomain.name + "', '" + 035 REFERENCE.name + "')\">"; 036 037 else if (ppr.refArray != null) 038 039 anchor = 040 "<A HREF=\"javascript:GOTO(" + 041 "'" + fixAPIName(REFERENCE_ARRAY.ownerDomain.ownerAPI.name) + "', '" + 042 REFERENCE_ARRAY.ownerDomain.name + "', '" + 043 REFERENCE_ARRAY.name + "')\">"; 044 045 else anchor = null; 046 047 048 // Must be a 'string' (see: 'Entity' constructor !) 049 if (ppr.enumValsStr != null) typeStr = 050 "<DIV CLASS=tooltip><SPAN CLASS=tooltiptext>" + 051 ppr.enumValsStr + "</SPAN>String<BR />[Hover] Enum</DIV>\n" + 052 "<BR />\"type\": " + ppr.typeProp + '\n'; 053 054 else 055 { 056 // Perfectly impossible, No need to check this, but it looks nice here 057 if ((ppr.typeProp == null) && (ppr.ref == null)) 058 throw (Error) ppr.verifyThrow("*BOTH* typeProp *AND* ref are null!"); 059 060 final String typePropStr = (ppr.typeProp == null) 061 ? "" 062 : "<BR />\"type\": " + ppr.typeProp + '\n'; 063 064 final String refPropStr = (ppr.ref == null) 065 ? "" 066 : "<BR />\"$ref\": " + anchor + ppr.ref + "</A>\n"; 067 068 final String itemsPropStr; 069 070 if (ppr.arrItemsTypeProp != null) itemsPropStr = 071 "<BR />\"items\":<BR />{ \"type\": " + ppr.arrItemsTypeProp + " }\n"; 072 073 else if (REFERENCE_ARRAY != null) itemsPropStr = 074 "<BR />\"items\":<BR />{ \"$ref\": " + anchor + ppr.refArray + "</A> }\n"; 075 076 else itemsPropStr = ""; 077 078 // final String T = typePropStr + refPropStr + itemsPropStr; 079 // if (T.length() == 0) throw (Error) ppr.verifyThrow("nothing is there!"); 080 081 typeStr = (typePropStr + refPropStr + itemsPropStr).substring("<BR />".length()); 082 } 083 084 085 final String descStr = ppr.description.replace("<", "<").replace(">", ">"); 086 087 return 088 "<TR>\n" + 089 " <TD>" + ppr.name + "</TD>\n" + 090 " <TD>" + typeStr + "</TD>\n" + 091 " <TD>" + descStr + "</TD>\n" + 092 " <TD>" + flagsStr + "</TD>\n" + 093 "</TR>\n"; 094 } 095 096 private static String fixAPIName(final String apiName) 097 { 098 if (! apiName.endsWith("API")) throw new UnreachableError(); 099 return apiName.substring(0, apiName.length() - "API".length()).toLowerCase(); 100 } 101}