1 19 20 package org.openide.src; 22 23 import org.openide.ErrorManager; 24 import org.openide.src.JavaDocTag; 25 26 27 41 42 class JavaDocTagMemoryImpl implements JavaDocTag { 43 44 String name; 45 String text; 46 47 JavaDocTagMemoryImpl( String name, String text ) { 48 this.name = name; 49 this.text = JavaDocMemoryImpl.convertNewLines(text); 50 } 51 52 public String toString() { 53 return name + " " + text; } 55 56 57 60 public String name() { 61 return name; 62 } 63 64 67 public String kind() { 68 return name; 69 } 70 71 74 public String text() { 75 return text; 76 } 77 78 80 83 String [] divideAtWhite() { 84 String [] sa = new String [2]; 85 int len = text.length(); 86 sa[0] = text; 88 sa[1] = ""; for (int inx = 0; inx < len; ++inx) { 90 char ch = text.charAt(inx); 91 if (Character.isWhitespace(ch)) { 92 sa[0] = text.substring(0, inx); 93 for (; inx < len; ++inx) { 94 ch = text.charAt(inx); 95 if (!Character.isWhitespace(ch)) { 96 sa[1] = text.substring(inx, len); 97 break; 98 } 99 } 100 break; 101 } 102 } 103 return sa; 104 } 105 106 107 109 113 114 static class See extends JavaDocTagMemoryImpl implements JavaDocTag.See { 115 116 private String label = ""; 118 119 private String where; 120 private String what; 121 122 See( String name, String text ) { 123 super( name, text ); 124 parseSeeString(); 125 } 126 127 130 public String label() { 131 return label; 132 } 133 134 141 public String referencedClassName() { 142 return where; 143 } 144 145 153 public String referencedMemberName() { 154 return what; 155 } 156 157 160 public String kind() { 161 return "@see"; } 163 164 167 168 public String toString() { 169 StringBuffer sb = new StringBuffer ( 100 ); 170 171 sb.append( name ).append( " " ).append( text ); return sb.toString(); 173 } 174 175 177 180 private void parseSeeString( ) { 181 int len = text.length(); 182 183 if (len == 0) { 184 return; 185 } 186 187 switch (text.charAt(0)) { 188 case '<': 189 case '"': 190 return; 191 } 192 193 198 int parens = 0; 200 int commentstart = 0; 201 int start = 0; 202 203 for (int i = start; i < len ; i++) { 204 char ch = text.charAt(i); 205 switch (ch) { 206 case '(': 207 parens++; 208 break; 209 case ')': 210 parens--; 211 break; 212 case '[': case ']': case '.': case '#': 213 break; 214 case ',': 215 if (parens <= 0) { 216 return; 217 } 218 break; 219 case ' ': case '\t': case '\n': 220 if (parens == 0) { commentstart = i; 222 i = len; 223 } 224 break; 225 default: 226 if (!Character.isJavaIdentifierPart(ch)) { 227 return; 228 } 229 break; 230 } 231 } 232 if (parens != 0) { 233 return; 234 } 235 236 String seetext = ""; String labeltext = ""; 239 if (commentstart > 0) { 240 seetext = text.substring(start, commentstart); 241 labeltext = text.substring(commentstart + 1); 242 for (int i = 0; i < labeltext.length(); i++) { 245 char ch = labeltext.charAt(i); 246 if (!(ch == ' ' || ch == '\t' || ch == '\n')) { 247 label = labeltext.substring(i); 248 break; 249 } 250 } 251 } 252 else { 253 seetext = text; 254 label = ""; } 256 257 int sharp = seetext.indexOf('#'); 258 if (sharp >= 0) { 259 where = seetext.substring(0, sharp); 261 what = seetext.substring(sharp + 1); 262 } 263 else { 264 if (seetext.indexOf('(') >= 0) { 265 where = ""; what = seetext; 267 } 268 else { 269 where = seetext; 271 what = null; 272 } 273 } 274 } 275 } 276 277 282 283 static class Param extends JavaDocTagMemoryImpl implements JavaDocTag.Param { 284 285 private String parameterName; 286 private String parameterComment; 287 288 Param( String name, String text ) { 289 super( name, text ); 290 291 String [] sa = this.divideAtWhite(); 292 293 this.parameterName = sa[0]; 294 this.parameterComment = sa[1]; 295 296 301 } 302 303 306 public String parameterName() { 307 return parameterName; 308 } 309 310 313 public String parameterComment() { 314 return parameterComment; 315 } 316 317 320 public String kind() { 321 return "@param"; } 323 324 325 328 public String toString() { 329 return name + " " + parameterName() + " " + parameterComment(); } 331 } 332 333 338 static class Throws extends JavaDocTagMemoryImpl implements JavaDocTag.Throws { 339 340 private String exceptionName; 341 private String exceptionComment; 342 343 Throws( String name, String text ) { 344 super( name, text ); 345 346 351 String [] sa = this.divideAtWhite(); 352 this.exceptionName = sa[0]; 353 this.exceptionComment = sa[1]; 354 355 376 } 377 378 381 public String exceptionName() { 382 return exceptionName; 383 } 384 385 388 public String exceptionComment() { 389 return exceptionComment; 390 } 391 392 396 public String kind() { 397 return "@throws"; } 399 400 403 public String toString() { 404 return name + " " + exceptionName() + " " + exceptionComment(); } 406 } 407 408 423 424 static class SerialField extends JavaDocTagMemoryImpl implements JavaDocTag.SerialField { 425 426 private String fieldName; 427 private String fieldType; 428 private String description; 429 430 431 SerialField( String name, String text ) { 432 super( name, text ); 433 parseSerialFieldString( text ); 434 } 435 436 437 440 public String fieldName() { 441 return fieldName; 442 } 443 444 447 public String fieldType() { 448 return fieldType; 449 } 450 451 455 public String description() { 456 return description; 457 } 458 459 462 public String kind() { 463 return "@serialField"; } 465 466 469 470 public String toString() { 471 return name + " " + fieldName() + " " + fieldType() + " " + description(); } 473 474 482 private void parseSerialFieldString( String text) { 483 484 int len = text.length(); 485 486 int inx = 0; 489 for (; inx < len && Character.isWhitespace(text.charAt(inx)); inx++) ; 490 491 if ( inx == len ) { 492 fieldName = ""; fieldType = ""; description = ""; return; 496 } 497 498 int first = inx; 500 int last = inx; 501 if (! Character.isJavaIdentifierStart(text.charAt(inx))) { 502 return; 503 } 504 505 for (; inx < len && Character.isJavaIdentifierPart(text.charAt(inx)); inx++); 506 507 if (inx < len && ! Character.isWhitespace(text.charAt(inx))) { 508 return; 509 } 510 511 last = inx; 512 fieldName = text.substring(first, last); 513 514 for (; inx < len && Character.isWhitespace(text.charAt(inx)); inx++) ; 516 517 first = inx; 519 last = inx; 520 521 for (; inx < len && ! Character.isWhitespace(text.charAt(inx)); inx++); 522 if (inx < len && ! Character.isWhitespace(text.charAt(inx))) { 523 return; 524 } 525 last = inx; 526 fieldType = text.substring(first, last); 527 528 for (; inx < len && Character.isWhitespace(text.charAt(inx)); inx++) ; 530 description = text.substring(inx); 531 } 532 533 } 534 535 } 536 | Popular Tags |