1 package org.codehaus.aspectwerkz.definition; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 import java.util.StringTokenizer ; 6 7 53 public class DescriptorUtil { 54 private static Map _paramTypeMap = new HashMap (); 55 56 private static Map _returnTypeMap = new HashMap (); 57 58 static { 59 _paramTypeMap.put("byte", "B"); 60 _paramTypeMap.put("char", "C"); 61 _paramTypeMap.put("double", "D"); 62 _paramTypeMap.put("float", "F"); 63 _paramTypeMap.put("int", "I"); 64 _paramTypeMap.put("long", "J"); 65 66 _paramTypeMap.put("java.lang.Object", "Ljava/lang/Object;"); 70 _paramTypeMap.put("short", "S"); 71 _paramTypeMap.put("boolean", "Z"); 72 73 _paramTypeMap.put("array reference", "["); 75 _returnTypeMap.put("void", "V"); 76 } 77 78 85 public static String convert(String javadocSig, String javadocReturnType) { 86 String javadocSigTrim = javadocSig.substring(1, javadocSig.length() - 1); 88 StringTokenizer st = new StringTokenizer (javadocSigTrim, ","); 89 StringBuffer jvmBuff = new StringBuffer ("("); 90 while (st.hasMoreTokens()) { 91 String sigElement = st.nextToken().trim(); 93 if (_paramTypeMap.containsKey(sigElement)) { 94 jvmBuff.append(_paramTypeMap.get(sigElement)); 95 } 96 } 97 jvmBuff.append(")"); 98 if (_returnTypeMap.containsKey(javadocReturnType)) { 99 jvmBuff.append(_returnTypeMap.get(javadocReturnType)); 100 } 101 return jvmBuff.toString(); 102 } 103 104 110 public static String [] getParameters(final String jvmSignature) { 111 int i = 0; 112 if (jvmSignature.charAt(i) != '(') { 113 return null; 114 } 115 int j = 0; 116 StringBuffer stringbuffer = new StringBuffer (); 117 for (i++; i < jvmSignature.length();) { 118 if (jvmSignature.charAt(i) == ')') { 119 i++; 120 break; } 122 if (i > 1) { 123 stringbuffer.append(" "); 125 } 126 i = jvmFormatToJavaFormat(jvmSignature, i, stringbuffer); 127 128 j++; 130 } 131 132 String convertedString = stringbuffer.toString(); 134 String [] as = new String [j]; 135 int k = 0; 136 StringTokenizer st = new StringTokenizer (convertedString); 137 while (st.hasMoreTokens()) { 138 as[k++] = st.nextToken(); 139 } 140 return as; 141 } 142 143 153 private static int jvmFormatToJavaFormat(final String jvmFormat, int i, StringBuffer stringbuffer) { 154 String s1 = ""; 155 156 for (; jvmFormat.charAt(i) == '['; i++) { 158 s1 = s1 + "[]"; 159 } 160 startover: switch (jvmFormat.charAt(i)) { 161 case 66: stringbuffer.append("byte"); 163 break; 164 case 67: stringbuffer.append("char"); 166 break; 167 case 68: stringbuffer.append("double"); 169 break; 170 case 70: stringbuffer.append("float"); 172 break; 173 case 73: stringbuffer.append("int"); 175 break; 176 case 74: stringbuffer.append("long"); 178 break; 179 case 83: stringbuffer.append("short"); 181 break; 182 case 90: stringbuffer.append("boolean"); 184 break; 185 case 86: stringbuffer.append("void"); 187 break; 188 case 76: 190 for (i++; i < jvmFormat.length(); i++) { 192 if (jvmFormat.charAt(i) == '/') { 193 stringbuffer.append('.'); 195 } else { 196 if (jvmFormat.charAt(i) == ';') { 197 break startover; 199 } 200 201 stringbuffer.append(jvmFormat.charAt(i)); 203 } 204 } 205 break; 206 default: 207 return jvmFormat.length(); 208 } 209 stringbuffer = stringbuffer.append(s1); 210 return ++i; 211 } 212 } | Popular Tags |