1 17 package org.apache.ws.jaxme.js; 18 19 import java.io.IOException ; 20 import java.util.ArrayList ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 25 29 public class JavaComment { 30 boolean forJavaDoc; 31 32 35 JavaComment() { forJavaDoc = true; } 36 37 41 JavaComment(boolean javaDoc) { forJavaDoc = javaDoc; } 42 43 private List authors; 44 49 public List getAuthors() { return authors; } 50 54 public void addAuthor(String author) { 55 if (authors == null) { 56 authors = new ArrayList (); 57 } 58 authors.add(author); 59 } 60 61 private String version; 62 67 public String getVersion() { return version; } 68 72 public void setVersion(String pVersion) { 73 version = (pVersion != null && pVersion.length() > 0) ? pVersion : null; 74 } 75 76 private String returns; 77 82 public String getReturn() { return returns; } 83 87 public void setReturn(String pReturns) { 88 returns = (pReturns != null && pReturns.length() > 0) ? pReturns : null; 89 } 90 91 private List see = new ArrayList (); 92 96 public List getSee() { return see; } 97 102 public void addSee(String pSee) { see.add(pSee); } 103 104 private ArrayList lines = new ArrayList (); 105 109 public ArrayList getLines() { return lines; } 110 114 public void addLine(String s) { 115 if (s == null) s = ""; 116 boolean done = false; 117 for (java.util.StringTokenizer st = new java.util.StringTokenizer (s, "\n"); 118 st.hasMoreTokens(); ) { 119 String t = st.nextToken(); 120 if (t.length() > 0 && t.charAt(t.length()-1) == '\r') { 121 t = t.substring(0, t.charAt(t.length()-1)); 122 } 123 lines.add(t); 124 done = true; 125 } 126 if (!done) lines.add(""); 127 } 128 129 private List params = new ArrayList (); 130 134 public List getParams() { return params; } 135 139 public void addParam(String s) { params.add(s); } 140 141 private List throwsList = new ArrayList (); 142 146 public List getThrows() { return throwsList; } 147 151 public void addThrows(String s) { throwsList.add(s); } 152 153 155 public void write(IndentationTarget pTarget) throws IOException { 156 String sep = "/*" + (forJavaDoc ? "* " : " "); 157 String othersep = " * "; 158 if (lines.size() > 0) { 159 for (int i = 0; i < lines.size(); i++) { 160 if (i > 0) pTarget.indent(0); 161 pTarget.write(sep); 162 pTarget.write(lines.get(i).toString()); 163 pTarget.write(); 164 sep = othersep; 165 } 166 } else { 167 pTarget.write(sep); 168 pTarget.write(); 169 sep = othersep; 170 } 171 pTarget.indent(0); 172 pTarget.write(sep); 173 pTarget.write(); 174 175 for (int i = 0; i < params.size(); i++) { 176 pTarget.indent(0); 177 pTarget.write(sep); 178 pTarget.write("@param "); 179 pTarget.write(params.get(i).toString()); 180 pTarget.write(); 181 } 182 if (returns != null) { 183 pTarget.indent(0); 184 pTarget.write(sep); 185 pTarget.write("@return "); 186 pTarget.write(returns); 187 pTarget.write(); 188 } 189 for (int i = 0; i < throwsList.size(); i++) { 190 pTarget.indent(0); 191 pTarget.write(sep); 192 pTarget.write("@throws "); 193 pTarget.write(throwsList.get(i).toString()); 194 pTarget.write(); 195 } 196 for (int i = 0; i < see.size(); i++) { 197 pTarget.indent(0); 198 pTarget.write(sep); 199 pTarget.write("@see "); 200 pTarget.write(see.get(i).toString()); 201 pTarget.write(); 202 } 203 List myAuthors = getAuthors(); 204 if (myAuthors != null) { 205 for (Iterator iter = myAuthors.iterator(); iter.hasNext(); ) { 206 pTarget.indent(0); 207 pTarget.write(sep); 208 pTarget.write("@author "); 209 pTarget.write((String ) iter.next()); 210 pTarget.write(); 211 } 212 } 213 if (version != null) { 214 pTarget.indent(0); 215 pTarget.write(sep); 216 pTarget.write("@version "); 217 pTarget.write(version); 218 pTarget.write(); 219 } 220 pTarget.indent(0); 221 pTarget.write(" */"); 222 pTarget.write(); 223 } 224 } 225 | Popular Tags |