1 package org.incava.javadoc; 2 3 import java.io.*; 4 import java.util.*; 5 import org.incava.text.LineMapping; 6 import org.incava.text.Location; 7 8 9 13 public class JavadocTaggedNode extends JavadocElement 14 { 15 private boolean parsed = false; 16 17 private JavadocTag tag = null; 18 19 private JavadocElement target = null; 20 21 private JavadocElement description = null; 22 23 private JavadocElement descriptionNonTarget = null; 24 25 public JavadocTaggedNode(String text, Location start, Location end) 26 { 27 super(text, start, end); 28 } 29 30 public JavadocTag getTag() 31 { 32 parse(); 33 return tag; 34 } 35 36 43 public JavadocElement getTarget() 44 { 45 parse(); 46 return target; 47 } 48 49 52 public JavadocElement getDescription() 53 { 54 parse(); 55 return description; 56 } 57 58 61 public JavadocElement getDescriptionNonTarget() 62 { 63 parse(); 64 return descriptionNonTarget; 65 } 66 67 protected void parse() 68 { 69 if (!parsed) { 70 int pos = 0; 71 int line = start.line; 72 int col = start.column; 73 int len = text.length(); 74 75 while (pos < len && !Character.isWhitespace(text.charAt(pos))) { 77 ++pos; 78 } 79 80 85 tag = new JavadocTag(text.substring(0, pos), new Location(line, start.column), new Location(line, pos - 1 + start.column)); 86 87 89 LineMapping lines = new LineMapping(text, start.line, start.column); 90 91 while (pos < len && (Character.isWhitespace(text.charAt(pos)) || text.charAt(pos) == '*')) { 93 ++pos; 94 } 95 96 99 if (pos < len) { 100 102 final int HTML = 0; 104 final int QUOTED = 1; 105 final int WORD = 2; 106 107 int targetStart = pos; 108 109 int type; 110 if (pos + 2 < len && text.substring(pos, pos + 2).equalsIgnoreCase("<a")) { 111 type = HTML; 112 } 113 else if (text.charAt(pos) == '"') { 114 type = QUOTED; 115 } 116 else { 117 type = WORD; 118 } 119 120 122 126 boolean inParen = false; 127 128 while (pos < len) { 129 char ch = text.charAt(pos); 130 if (ch == '\\' && pos + 1 < len) { 131 ++pos; 132 } 133 else if (type == WORD) { 134 if (ch == '(') { 135 inParen = true; 136 } 137 else if (inParen && ch == ')') { 138 inParen = false; 139 } 140 if (!inParen) { 141 if (pos + 1 == len) { 142 ++pos; 144 break; 145 } 146 else if (Character.isWhitespace(ch)) { 147 break; 149 } 150 } 151 } 152 else if (type == HTML && ch == '>' && Character.toLowerCase(text.charAt(pos - 1)) == 'a') { 153 ++pos; 155 break; 156 } 157 else if (type == QUOTED && ch == '"') { 158 ++pos; 160 break; 161 } 162 ++pos; 163 } 164 165 167 Location[] targetLocations = lines.getLocations(targetStart, pos - 1); 168 169 target = new JavadocElement(text.substring(targetStart, pos), targetLocations[0], targetLocations[1]); 171 173 while (pos < len && (Character.isWhitespace(text.charAt(pos)) || text.charAt(pos) == '*')) { 175 ++pos; 176 } 177 178 if (pos == len) { 179 descriptionNonTarget = null; 182 description = new JavadocElement(text.substring(targetStart, len), targetLocations[0], end); 183 } 184 else if (pos < len && !Character.isWhitespace(text.charAt(pos))) { 185 Location dntStart = lines.getLocation(pos); 187 descriptionNonTarget = new JavadocElement(text.substring(pos, len), dntStart, end); 188 description = new JavadocElement(text.substring(targetStart, len), targetLocations[0], end); 190 } 191 } 192 } 193 } 194 195 } 196 | Popular Tags |