1 4 5 package com.tc.aspectwerkz.definition; 6 7 import java.util.HashMap ; 8 import java.util.Map ; 9 import java.util.StringTokenizer ; 10 11 57 public class DescriptorUtil { 58 private static Map _paramTypeMap = new HashMap (); 59 60 private static Map _returnTypeMap = new HashMap (); 61 62 static { 63 _paramTypeMap.put("byte", "B"); 64 _paramTypeMap.put("char", "C"); 65 _paramTypeMap.put("double", "D"); 66 _paramTypeMap.put("float", "F"); 67 _paramTypeMap.put("int", "I"); 68 _paramTypeMap.put("long", "J"); 69 70 _paramTypeMap.put("java.lang.Object", "Ljava/lang/Object;"); 74 _paramTypeMap.put("short", "S"); 75 _paramTypeMap.put("boolean", "Z"); 76 77 _paramTypeMap.put("array reference", "["); 79 _returnTypeMap.put("void", "V"); 80 } 81 82 89 public static String convert(String javadocSig, String javadocReturnType) { 90 String javadocSigTrim = javadocSig.substring(1, javadocSig.length() - 1); 92 StringTokenizer st = new StringTokenizer (javadocSigTrim, ","); 93 StringBuffer jvmBuff = new StringBuffer ("("); 94 while (st.hasMoreTokens()) { 95 String sigElement = st.nextToken().trim(); 97 if (_paramTypeMap.containsKey(sigElement)) { 98 jvmBuff.append(_paramTypeMap.get(sigElement)); 99 } 100 } 101 jvmBuff.append(")"); 102 if (_returnTypeMap.containsKey(javadocReturnType)) { 103 jvmBuff.append(_returnTypeMap.get(javadocReturnType)); 104 } 105 return jvmBuff.toString(); 106 } 107 108 114 public static String [] getParameters(final String jvmSignature) { 115 int i = 0; 116 if (jvmSignature.charAt(i) != '(') { 117 return null; 118 } 119 int j = 0; 120 StringBuffer stringbuffer = new StringBuffer (); 121 for (i++; i < jvmSignature.length();) { 122 if (jvmSignature.charAt(i) == ')') { 123 i++; 124 break; } 126 if (i > 1) { 127 stringbuffer.append(" "); 129 } 130 i = jvmFormatToJavaFormat(jvmSignature, i, stringbuffer); 131 132 j++; 134 } 135 136 String convertedString = stringbuffer.toString(); 138 String [] as = new String [j]; 139 int k = 0; 140 StringTokenizer st = new StringTokenizer (convertedString); 141 while (st.hasMoreTokens()) { 142 as[k++] = st.nextToken(); 143 } 144 return as; 145 } 146 147 157 private static int jvmFormatToJavaFormat(final String jvmFormat, int i, StringBuffer stringbuffer) { 158 String s1 = ""; 159 160 for (; jvmFormat.charAt(i) == '['; i++) { 162 s1 = s1 + "[]"; 163 } 164 startover: 165 switch (jvmFormat.charAt(i)) { 166 case 66: stringbuffer.append("byte"); 168 break; 169 case 67: stringbuffer.append("char"); 171 break; 172 case 68: stringbuffer.append("double"); 174 break; 175 case 70: stringbuffer.append("float"); 177 break; 178 case 73: stringbuffer.append("int"); 180 break; 181 case 74: stringbuffer.append("long"); 183 break; 184 case 83: stringbuffer.append("short"); 186 break; 187 case 90: stringbuffer.append("boolean"); 189 break; 190 case 86: stringbuffer.append("void"); 192 break; 193 case 76: 195 for (i++; i < jvmFormat.length(); i++) { 197 if (jvmFormat.charAt(i) == '/') { 198 stringbuffer.append('.'); 200 } else { 201 if (jvmFormat.charAt(i) == ';') { 202 break startover; 204 } 205 206 stringbuffer.append(jvmFormat.charAt(i)); 208 } 209 } 210 break; 211 default: 212 return jvmFormat.length(); 213 } 214 stringbuffer = stringbuffer.append(s1); 215 return ++i; 216 } 217 } | Popular Tags |