1 21 22 package org.armedbear.j; 23 24 import java.util.StringTokenizer ; 25 26 public final class JavaTag extends LocalTag 27 { 28 private final JavaClass parent; 29 30 public JavaTag(String name, Position pos, int type, int flags) 31 { 32 this(name, pos, type, flags, null); 33 } 34 35 public JavaTag(String name, Position pos, int type, int flags, 36 JavaClass parent) 37 { 38 super(name, pos, type, flags); 39 this.parent = parent; 40 switch (type) { 41 case TAG_METHOD: 42 canonicalSignature = parseCanonicalSignatureForMethod(); 43 break; 44 case TAG_EXPLICIT: 45 canonicalSignature = pos.getLine().trim(); 46 break; 47 } 48 } 49 50 public final JavaClass getParent() 51 { 52 return parent; 53 } 54 55 public String getMethodName() 56 { 57 return getShortName(); 58 } 59 60 private String getShortName() 61 { 62 int index = name.lastIndexOf('.'); 63 if (index >= 0) 64 return name.substring(index+1); 65 else 66 return name; 67 } 68 69 public String getLongName() 70 { 71 if (name.startsWith("class ")) 72 return name; 73 if (canonicalSignature != null) 74 return canonicalSignature; 75 if (getType() == TAG_FIELD) { 76 return canonicalSignature = parseCanonicalSignatureForField(); 80 } 81 String s = signature.trim(); 82 int index = s.indexOf("//"); 84 if (index >= 0) 85 s = s.substring(0, index).trim(); 86 index = s.indexOf('='); 87 if (index >= 0) 88 s = s.substring(0, index).trim(); 89 index = s.indexOf(';'); 90 if (index >= 0) 91 s = s.substring(0, index).trim(); 92 return s; 93 } 94 95 public String getClassName() 96 { 97 if (parent != null) 98 return parent.getName(); 99 return null; 100 } 101 102 private String parseCanonicalSignatureForField() 103 { 104 String s = signature.trim(); 105 int index = s.indexOf("//"); 107 if (index >= 0) 108 s = s.substring(0, index).trim(); 109 index = s.indexOf(','); 112 if (index >= 0) 113 s = s.substring(0, index).trim(); 114 index = s.indexOf('='); 115 if (index >= 0) 116 s = s.substring(0, index).trim(); 117 index = s.indexOf(';'); 118 if (index >= 0) 119 s = s.substring(0, index).trim(); 120 StringTokenizer st = new StringTokenizer (s); 127 int count = st.countTokens(); 128 FastStringBuffer sb = new FastStringBuffer(); 129 for (int i = 0; i < count-1; i++) { 130 sb.append(st.nextToken()); 131 sb.append(' '); 132 } 133 sb.append(getShortName()); 134 return sb.toString(); 135 } 136 137 private String parseCanonicalSignatureForMethod() 138 { 139 FastStringBuffer sb = new FastStringBuffer(); 140 Position pos = getPosition().copy(); 141 pos.setOffset(0); 142 while (Character.isWhitespace(pos.getChar())) 143 if (!pos.next()) 144 return null; 145 char lastChar = 0; 146 char c; 147 while ((c = pos.getChar()) != ')') { 148 if (c == '/') { 149 if (!pos.next()) 150 return null; 151 skipComment(pos); 152 if (pos.atEnd()) 153 return null; 154 continue; 155 } 156 if (c == '\n' || c == '\t') 157 c = ' '; 158 if (c != ' ' || lastChar != ' ') { 159 sb.append(c); 160 lastChar = c; 161 } 162 if (!pos.next()) 163 return null; 164 } 165 if (c == ')') 166 sb.append(c); 167 return sb.toString(); 168 } 169 170 private static void skipComment(Position pos) 173 { 174 char c = pos.getChar(); 175 if (!pos.next()) 176 return; 177 if (c == '/') { 178 while ((c = pos.getChar()) != '\n') 179 if (!pos.next()) 180 return; 181 pos.next(); 182 } else if (c == '*') { 183 while (!pos.lookingAt("*/")) 184 if (!pos.next()) 185 return; 186 pos.skip(2); 187 } 188 } 189 190 public String getSidebarText() 191 { 192 switch (getType()) { 193 case TAG_EXTENDS: 194 return "extends ".concat(getMethodName()); 195 case TAG_IMPLEMENTS: 196 return "implements ".concat(getMethodName()); 197 default: 198 return getMethodName(); 199 } 200 } 201 202 public String getToolTipText() 203 { 204 switch (getType()) { 205 case TAG_EXTENDS: 206 return "class ".concat(getMethodName()); 207 case TAG_IMPLEMENTS: 208 return "interface ".concat(getMethodName()); 209 default: 210 return getLongName(); 211 } 212 } 213 214 public void gotoTag(Editor editor) 215 { 216 switch (getType()) { 217 case TAG_EXTENDS: 218 case TAG_IMPLEMENTS: 219 if (!TagCommands.findClass(editor, getMethodName(), false)) 220 super.gotoTag(editor); 221 break; 222 default: 223 super.gotoTag(editor); 224 break; 225 } 226 } 227 } 228 | Popular Tags |