1 package org.incava.javadoc; 2 3 import java.awt.Point ; 4 import java.util.ArrayList ; 5 import java.util.List ; 6 7 8 12 public class JavadocParser 13 { 14 17 private int pos; 18 19 22 private int len; 23 24 27 private String text; 28 29 33 public List parse(String text) 34 { 35 return parse(text, 1, 1); 36 } 37 38 public List parse(String text, int startLine, int startColumn) 39 { 40 42 this.text = text; 43 44 len = text.length(); 45 ArrayList ary = new ArrayList (); 46 pos = 0; 47 48 while (pos < len && Character.isWhitespace(text.charAt(pos))) { 49 ++pos; 50 } 51 52 if (pos + 3 < len && text.startsWith("/**")) { pos += 3; 55 56 while (pos < len && (Character.isWhitespace(text.charAt(pos)) || text.charAt(pos) == '*')) { 57 ++pos; 58 } 59 60 --len; 61 while (len >= 0) { 62 if (Character.isWhitespace(text.charAt(len)) || text.charAt(len) == '*') { 64 --len; 66 } 67 else if (len > 0 && text.charAt(len) == '/' && text.charAt(len - 1) == '*') { 68 len -= 2; 70 } 71 else { 72 break; 73 } 74 } 75 ++len; 76 77 79 if (pos < len) { 80 if (text.charAt(pos) == '@') { 82 ary.add(null); 85 } 86 else { 87 89 Point desc = new Point (pos, -1); 90 91 read(desc); 92 93 95 ary.add(desc); 96 } 97 98 while (pos < len && text.charAt(pos) == '@') { 100 102 Point tag = new Point (pos, -1); 103 104 ++pos; 105 read(tag); 106 107 109 ary.add(tag); 110 } 111 } 112 113 115 return ary; 116 } 117 else { 118 return null; 120 } 121 } 122 123 126 protected void read(Point pt) 127 { 128 130 pt.y = pos; 131 while (pos < len && (text.charAt(pos) != '@' || (pos >= 0 && text.charAt(pos - 1) == '{'))) { 132 pt.y = pos; 134 135 ++pos; 136 137 if (text.charAt(pos) == '\r') { 140 if (pos + 1 < len && text.charAt(pos + 1) == '\n') { 141 ++pos; 142 } 143 } 144 else if (text.charAt(pos) != '\n') { 145 continue; 146 } 147 148 150 while (pos < len && (Character.isWhitespace(text.charAt(pos)) || text.charAt(pos) == '*')) { 152 ++pos; 153 } 155 } 156 157 ++pt.y; 158 } 160 161 } 162
| Popular Tags
|