1 30 package com.sleepycat.asm.signature; 31 32 39 public class SignatureReader { 40 41 44 private final String signature; 45 46 52 public SignatureReader(final String signature) { 53 this.signature = signature; 54 } 55 56 71 public void accept(final SignatureVisitor v) { 72 String signature = this.signature; 73 int len = signature.length(); 74 int pos; 75 char c; 76 77 if (signature.charAt(0) == '<') { 78 pos = 2; 79 do { 80 int end = signature.indexOf(':', pos); 81 v.visitFormalTypeParameter(signature.substring(pos - 1, end)); 82 pos = end + 1; 83 84 c = signature.charAt(pos); 85 if (c == 'L' || c == '[' || c == 'T') { 86 pos = parseType(signature, pos, v.visitClassBound()); 87 } 88 89 for (;;) { 90 if ((c = signature.charAt(pos++)) == ':') { 91 pos = parseType(signature, pos, v.visitInterfaceBound()); 92 } else { 93 break; 94 } 95 } 96 } while (c != '>'); 97 } else { 98 pos = 0; 99 } 100 101 if (signature.charAt(pos) == '(') { 102 pos = pos + 1; 103 while (signature.charAt(pos) != ')') { 104 pos = parseType(signature, pos, v.visitParameterType()); 105 } 106 pos = parseType(signature, pos + 1, v.visitReturnType()); 107 while (pos < len) { 108 pos = parseType(signature, pos + 1, v.visitExceptionType()); 109 } 110 } else { 111 pos = parseType(signature, pos, v.visitSuperclass()); 112 while (pos < len) { 113 pos = parseType(signature, pos, v.visitInterface()); 114 } 115 } 116 } 117 118 132 public void acceptType(final SignatureVisitor v) { 133 parseType(this.signature, 0, v); 134 } 135 136 144 private static int parseType( 145 final String signature, 146 int pos, 147 final SignatureVisitor v) 148 { 149 char c; 150 int start, end; 151 boolean visited, inner; 152 String name; 153 154 switch (c = signature.charAt(pos++)) { 155 case 'Z': 156 case 'C': 157 case 'B': 158 case 'S': 159 case 'I': 160 case 'F': 161 case 'J': 162 case 'D': 163 case 'V': 164 v.visitBaseType(c); 165 return pos; 166 167 case '[': 168 return parseType(signature, pos, v.visitArrayType()); 169 170 case 'T': 171 end = signature.indexOf(';', pos); 172 v.visitTypeVariable(signature.substring(pos, end)); 173 return end + 1; 174 175 default: start = pos; 177 visited = false; 178 inner = false; 179 for (;;) { 180 switch (c = signature.charAt(pos++)) { 181 case '.': 182 case ';': 183 if (!visited) { 184 name = signature.substring(start, pos - 1); 185 if (inner) { 186 v.visitInnerClassType(name); 187 } else { 188 v.visitClassType(name); 189 } 190 } 191 if (c == ';') { 192 v.visitEnd(); 193 return pos; 194 } 195 start = pos; 196 visited = false; 197 inner = true; 198 break; 199 200 case '<': 201 name = signature.substring(start, pos - 1); 202 if (inner) { 203 v.visitInnerClassType(name); 204 } else { 205 v.visitClassType(name); 206 } 207 visited = true; 208 top: for (;;) { 209 switch (c = signature.charAt(pos)) { 210 case '>': 211 break top; 212 case '*': 213 ++pos; 214 v.visitTypeArgument(); 215 break; 216 case '+': 217 case '-': 218 pos = parseType(signature, 219 pos + 1, 220 v.visitTypeArgument(c)); 221 break; 222 default: 223 pos = parseType(signature, 224 pos, 225 v.visitTypeArgument('=')); 226 break; 227 } 228 } 229 } 230 } 231 } 232 } 233 } 234 | Popular Tags |