1 8 package org.codehaus.aspectwerkz.reflect.impl.asm; 9 10 import gnu.trove.TIntObjectHashMap; 11 import gnu.trove.TIntArrayList; 12 import org.codehaus.aspectwerkz.annotation.instrumentation.asm.AsmAnnotationHelper; 13 import org.codehaus.aspectwerkz.annotation.AnnotationInfo; 14 import org.codehaus.aspectwerkz.exception.WrappedRuntimeException; 15 import org.codehaus.aspectwerkz.reflect.ClassInfo; 16 import org.codehaus.aspectwerkz.reflect.ConstructorInfo; 17 import org.codehaus.aspectwerkz.reflect.FieldInfo; 18 import org.codehaus.aspectwerkz.reflect.MethodInfo; 19 import org.codehaus.aspectwerkz.reflect.StaticInitializationInfo; 20 import org.codehaus.aspectwerkz.reflect.StaticInitializationInfoImpl; 21 import org.codehaus.aspectwerkz.reflect.impl.java.JavaClassInfo; 22 import org.codehaus.aspectwerkz.transform.inlining.AsmHelper; 23 import org.codehaus.aspectwerkz.transform.TransformationConstants; 24 import org.codehaus.aspectwerkz.proxy.ProxyCompiler; 25 import org.objectweb.asm.Attribute; 26 import org.objectweb.asm.ClassReader; 27 import org.objectweb.asm.CodeVisitor; 28 import org.objectweb.asm.Label; 29 import org.objectweb.asm.Type; 30 import org.objectweb.asm.attrs.Annotation; 31 import org.objectweb.asm.attrs.Attributes; 32 33 import java.io.IOException ; 34 import java.io.InputStream ; 35 import java.lang.ref.WeakReference ; 36 import java.lang.reflect.Array ; 37 import java.lang.reflect.Modifier ; 38 import java.util.ArrayList ; 39 import java.util.List ; 40 import java.util.Iterator ; 41 42 53 public class AsmClassInfo implements ClassInfo { 54 55 protected final static String [] EMPTY_STRING_ARRAY = new String [0]; 56 57 protected final static List EMPTY_LIST = new ArrayList(); 58 59 private final static Attribute[] NO_ATTRIBUTES = new Attribute[0]; 60 61 64 private final WeakReference m_loaderRef; 65 66 69 private String m_name; 70 71 74 private String m_signature; 75 76 79 private int m_modifiers; 80 81 84 private boolean m_isInterface = false; 85 86 89 private boolean m_isPrimitive = false; 90 91 94 private boolean m_isArray = false; 95 96 99 private boolean m_hasStaticInitializer = false; 100 101 104 private StaticInitializationInfo m_staticInitializer = null; 105 106 111 private final TIntObjectHashMap m_constructors = new TIntObjectHashMap(); 112 private TIntArrayList m_sortedConstructorHashes = new TIntArrayList(); 113 private ConstructorInfo[] m_constructorsLazy = null; 114 115 116 121 private final TIntObjectHashMap m_methods = new TIntObjectHashMap(); 122 private TIntArrayList m_sortedMethodHashes = new TIntArrayList(); 123 private MethodInfo[] m_methodsLazy = null; 124 125 130 private final TIntObjectHashMap m_fields = new TIntObjectHashMap(); 131 private TIntArrayList m_sortedFieldHashes = new TIntArrayList(); 132 private FieldInfo[] m_fieldsLazy = null; 133 134 137 private String [] m_interfaceClassNames = null; 138 139 142 private ClassInfo[] m_interfaces = null; 143 144 147 private String m_superClassName = null; 148 149 152 private ClassInfo m_superClass = null; 153 154 158 private List m_annotations = null; 159 160 163 private String m_componentTypeName = null; 164 165 168 private ClassInfo m_componentType = null; 169 170 173 private final AsmClassInfoRepository m_classInfoRepository; 174 175 181 AsmClassInfo(final byte[] bytecode, final ClassLoader loader, boolean lazyAttributes) { 182 if (bytecode == null) { 183 throw new IllegalArgumentException ("bytecode can not be null"); 184 } 185 m_loaderRef = new WeakReference (loader); 186 m_classInfoRepository = AsmClassInfoRepository.getRepository(loader); 187 try { 188 ClassReader cr = new ClassReader(bytecode); 189 ClassInfoClassAdapter visitor = new ClassInfoClassAdapter(lazyAttributes); 190 cr.accept(visitor, lazyAttributes ? NO_ATTRIBUTES : Attributes.getDefaultAttributes(), false); 191 } catch (Throwable t) { 192 t.printStackTrace(); 193 } 194 m_classInfoRepository.addClassInfo(this); 195 } 196 197 203 AsmClassInfo(final InputStream resourceStream, final ClassLoader loader) { 204 if (resourceStream == null) { 205 throw new IllegalArgumentException ("resource stream can not be null"); 206 } 207 m_loaderRef = new WeakReference (loader); 208 m_classInfoRepository = AsmClassInfoRepository.getRepository(loader); 209 try { 210 ClassReader cr = new ClassReader(resourceStream); 211 ClassInfoClassAdapter visitor = new ClassInfoClassAdapter(true); 212 cr.accept(visitor, NO_ATTRIBUTES, false); 213 } catch (Throwable t) { 214 t.printStackTrace(); 215 } 216 m_classInfoRepository.addClassInfo(this); 217 } 218 219 228 AsmClassInfo(final String className, 229 final ClassLoader loader, 230 final ClassInfo componentInfo) { 231 m_loaderRef = new WeakReference (loader); 232 m_name = className.replace('/', '.'); 233 m_classInfoRepository = AsmClassInfoRepository.getRepository(loader); 234 m_isArray = true; 235 m_componentType = componentInfo; 236 m_componentTypeName = componentInfo.getName(); 237 m_modifiers = componentInfo.getModifiers() | Modifier.ABSTRACT | Modifier.FINAL; 238 m_isInterface = false; m_superClass = JavaClassInfo.getClassInfo(Object .class); 240 m_superClassName = m_superClass.getName(); 241 m_interfaceClassNames = new String [0]; 242 m_interfaces = new ClassInfo[0]; 243 m_signature = AsmHelper.getClassDescriptor(this); 244 m_classInfoRepository.addClassInfo(this); 245 } 246 247 254 public static ClassInfo newClassInfo(final byte[] bytecode, final ClassLoader loader) { 255 final String className = AsmClassInfo.retrieveClassNameFromBytecode(bytecode); 256 AsmClassInfoRepository repository = AsmClassInfoRepository.getRepository(loader); 257 repository.removeClassInfo(className); 258 return new AsmClassInfo(bytecode, loader, true); 259 } 260 261 268 public static ClassInfo getClassInfo(final String className, final ClassLoader loader) { 269 final String javaClassName = getJavaClassName(className); 270 AsmClassInfoRepository repository = AsmClassInfoRepository.getRepository(loader); 271 ClassInfo classInfo = repository.getClassInfo(javaClassName); 272 if (classInfo == null) { 273 classInfo = createClassInfoFromStream(javaClassName, loader, true); 274 } 275 return classInfo; 276 } 277 278 285 public static ClassInfo getClassInfo(final byte[] bytecode, final ClassLoader loader) { 286 final String className = AsmClassInfo.retrieveClassNameFromBytecode(bytecode); 287 AsmClassInfoRepository repository = AsmClassInfoRepository.getRepository(loader); 288 ClassInfo classInfo = repository.getClassInfo(className); 289 if (classInfo == null) { 290 classInfo = new AsmClassInfo(bytecode, loader, true); 291 } 292 return classInfo; 293 } 294 295 302 public static ClassInfo getClassInfo(final InputStream stream, final ClassLoader loader) { 303 try { 304 ClassReader cr = new ClassReader(stream); 305 byte[] bytes = cr.b; 307 ClassNameRetrievalClassAdapter visitor = new ClassNameRetrievalClassAdapter(); 308 cr.accept(visitor, NO_ATTRIBUTES, true); 309 final String className = visitor.getClassName(); 310 AsmClassInfoRepository repository = AsmClassInfoRepository.getRepository(loader); 311 ClassInfo classInfo = repository.getClassInfo(className); 312 if (classInfo == null) { 313 classInfo = new AsmClassInfo(bytes, loader, true); 314 } 315 return classInfo; 316 } catch (IOException e) { 317 throw new WrappedRuntimeException(e); 318 } 319 } 320 321 329 public static ClassInfo getClassInfo(final InputStream stream, final ClassLoader loader, boolean lazyAttributes) { 330 if (lazyAttributes) { 331 return getClassInfo(stream, loader); 332 } 333 try { 334 ClassReader cr = new ClassReader(stream); 335 byte[] bytes = cr.b; 337 ClassNameRetrievalClassAdapter visitor = new ClassNameRetrievalClassAdapter(); 338 cr.accept(visitor, NO_ATTRIBUTES, true); 339 String className = visitor.getClassName(); 340 AsmClassInfoRepository repository = AsmClassInfoRepository.getRepository(loader); 341 ClassInfo classInfo = repository.getClassInfo(className); 342 if (classInfo == null) { 343 classInfo = new AsmClassInfo(bytes, loader, lazyAttributes); 344 } 345 return classInfo; 346 } catch (IOException e) { 347 throw new WrappedRuntimeException(e); 348 } 349 } 350 351 356 public static void markDirty(final String className, final ClassLoader loader) { 357 AsmClassInfoRepository.getRepository(loader).removeClassInfo(className); 358 } 359 360 366 public static String retrieveClassNameFromBytecode(final byte[] bytecode) { 367 ClassReader cr = new ClassReader(bytecode); 368 ClassNameRetrievalClassAdapter visitor = new ClassNameRetrievalClassAdapter(); 369 cr.accept(visitor, NO_ATTRIBUTES, true); 370 return visitor.getClassName(); 371 } 372 373 379 public static Class getPrimitiveClass(final String className) { 380 if (className.equals("void")) { 381 return void.class; 382 } else if (className.equals("long")) { 383 return long.class; 384 } else if (className.equals("int")) { 385 return int.class; 386 } else if (className.equals("short")) { 387 return short.class; 388 } else if (className.equals("double")) { 389 return double.class; 390 } else if (className.equals("float")) { 391 return float.class; 392 } else if (className.equals("byte")) { 393 return byte.class; 394 } else if (className.equals("boolean")) { 395 return boolean.class; 396 } else if (className.equals("char")) { 397 return char.class; 398 } else { 399 return null; 400 } 401 } 402 403 408 public List getAnnotations() { 409 if (m_annotations == null) { 410 if (isPrimitive() || isArray()) { 411 m_annotations = EMPTY_LIST; 412 } else { 413 try { 414 InputStream in = null; 415 ClassReader cr = null; 416 try { 417 if ((ClassLoader ) m_loaderRef.get() != null) { 418 in = 419 ((ClassLoader ) m_loaderRef.get()).getResourceAsStream(m_name.replace('.', '/') + ".class"); 420 } else { 421 in = ClassLoader.getSystemClassLoader().getResourceAsStream(m_name.replace('.', '/') + ".class"); 422 } 423 if (in == null) { 424 in = ProxyCompiler.getProxyResourceAsStream((ClassLoader ) m_loaderRef.get(), m_name); 425 } 426 cr = new ClassReader(in); 427 } finally { 428 try { 429 in.close(); 430 } catch (Exception e) { 431 ; 432 } 433 } 434 List annotations = new ArrayList(); 435 cr.accept( 436 new AsmAnnotationHelper.ClassAnnotationExtractor( 437 annotations, (ClassLoader ) m_loaderRef.get() 438 ), 439 Attributes.getDefaultAttributes(), 440 true 441 ); 442 m_annotations = annotations; 443 } catch (IOException e) { 444 System.err.println( 446 "AW::WARNING could not load " + m_name + " as a resource to retrieve annotations" 447 ); 448 m_annotations = EMPTY_LIST; 449 } 450 } 451 } 452 return m_annotations; 453 } 454 455 460 public String getName() { 461 return m_name; 462 } 463 464 469 public String getSignature() { 470 return m_signature; 471 } 472 473 478 public int getModifiers() { 479 return m_modifiers; 480 } 481 482 487 public ClassLoader getClassLoader() { 488 return (ClassLoader ) m_loaderRef.get(); 489 } 490 491 496 public boolean hasStaticInitializer() { 497 return m_hasStaticInitializer; 498 } 499 500 505 public StaticInitializationInfo staticInitializer() { 506 if(hasStaticInitializer() && m_staticInitializer == null) { 507 m_staticInitializer = new StaticInitializationInfoImpl(this); 508 } 509 return m_staticInitializer; 510 } 511 512 518 public ConstructorInfo getConstructor(final int hash) { 519 ConstructorInfo constructor = (ConstructorInfo) m_constructors.get(hash); 520 if (constructor == null && getSuperclass() != null) { 521 constructor = getSuperclass().getConstructor(hash); 522 } 523 return constructor; 524 } 525 526 531 public ConstructorInfo[] getConstructors() { 532 if (m_constructorsLazy == null) { 533 ConstructorInfo[] constructorInfos = new ConstructorInfo[m_sortedConstructorHashes.size()]; 534 for (int i = 0; i < m_sortedConstructorHashes.size(); i++) { 535 constructorInfos[i] = (ConstructorInfo) m_constructors.get(m_sortedConstructorHashes.get(i)); 536 } 537 m_constructorsLazy = constructorInfos; 538 } 539 return m_constructorsLazy; 540 } 541 542 548 public MethodInfo getMethod(final int hash) { 549 MethodInfo method = (MethodInfo) m_methods.get(hash); 550 if (method == null) { 551 for (int i = 0; i < getInterfaces().length; i++) { 552 method = getInterfaces()[i].getMethod(hash); 553 if (method != null) { 554 break; 555 } 556 } 557 } 558 if (method == null && getSuperclass() != null) { 559 method = getSuperclass().getMethod(hash); 560 } 561 return method; 562 } 563 564 569 public MethodInfo[] getMethods() { 570 if (m_methodsLazy == null) { 571 MethodInfo[] methodInfos = new MethodInfo[m_sortedMethodHashes.size()]; 572 for (int i = 0; i < m_sortedMethodHashes.size(); i++) { 573 methodInfos[i] = (MethodInfo) m_methods.get(m_sortedMethodHashes.get(i)); 574 } 575 m_methodsLazy = methodInfos; 576 } 577 return m_methodsLazy; 578 } 579 580 586 public FieldInfo getField(final int hash) { 587 FieldInfo field = (FieldInfo) m_fields.get(hash); 588 if (field == null && getSuperclass() != null) { 589 field = getSuperclass().getField(hash); 590 } 591 return field; 592 } 593 594 599 public FieldInfo[] getFields() { 600 if (m_fieldsLazy == null) { 601 FieldInfo[] fieldInfos = new FieldInfo[m_sortedFieldHashes.size()]; 602 for (int i = 0; i < m_sortedFieldHashes.size(); i++) { 603 fieldInfos[i] = (FieldInfo) m_fields.get(m_sortedFieldHashes.get(i)); 604 } 605 m_fieldsLazy = fieldInfos; 606 } 607 return m_fieldsLazy; 608 } 609 610 615 public ClassInfo[] getInterfaces() { 616 if (m_interfaces == null) { 617 m_interfaces = new ClassInfo[m_interfaceClassNames.length]; 618 for (int i = 0; i < m_interfaceClassNames.length; i++) { 619 m_interfaces[i] = AsmClassInfo.getClassInfo(m_interfaceClassNames[i], (ClassLoader ) m_loaderRef.get()); 620 } 621 } 622 return m_interfaces; 623 } 624 625 630 public ClassInfo getSuperclass() { 631 if (m_superClass == null && m_superClassName != null) { 632 m_superClass = AsmClassInfo.getClassInfo(m_superClassName, (ClassLoader ) m_loaderRef.get()); 633 } 634 return m_superClass; 635 } 636 637 642 public ClassInfo getComponentType() { 643 if (isArray() && (m_componentTypeName == null)) { 644 m_componentType = AsmClassInfo.getClassInfo(m_componentTypeName, (ClassLoader ) m_loaderRef.get()); 645 } 646 return m_componentType; 647 } 648 649 654 public boolean isInterface() { 655 return m_isInterface; 656 } 657 658 663 public boolean isPrimitive() { 664 return m_isPrimitive; 665 } 666 667 672 public boolean isArray() { 673 return m_isArray; 674 } 675 676 679 public boolean equals(Object o) { 680 if (this == o) { 681 return true; 682 } 683 if (!(o instanceof ClassInfo)) { 684 return false; 685 } 686 ClassInfo classInfo = (ClassInfo) o; 687 return m_name.equals(classInfo.getName()); 688 } 689 690 693 public int hashCode() { 694 return m_name.hashCode(); 695 } 696 697 public String toString() { 698 return m_name; 699 } 700 701 709 public static ClassInfo getArrayClassInfo(final String className, 710 final ClassLoader loader, 711 final ClassInfo componentClassInfo) { 712 return new AsmClassInfo(className, loader, componentClassInfo); 713 } 714 715 723 private static ClassInfo createClassInfoFromStream(final String name, 724 final ClassLoader loader, 725 boolean lazyAttributes) { 726 final String className = name.replace('.', '/'); 727 728 if (name.indexOf('/') < 0) { 730 int dimension = 0; 733 for (int i = className.indexOf('['); i > 0; i = className.indexOf('[', i+1)) { 734 dimension++; 735 } 736 String unidimComponentName = className; 737 if (dimension > 0) { 738 int unidimComponentTypeIndex = className.indexOf('['); 739 unidimComponentName = className.substring(0, unidimComponentTypeIndex); 740 } 741 Class primitiveClass = AsmClassInfo.getPrimitiveClass(unidimComponentName); 742 if (primitiveClass != null && primitiveClass.isPrimitive()) { 743 if (dimension == 0) { 744 return JavaClassInfo.getClassInfo(primitiveClass); 745 } else { 746 Class arrayClass = Array.newInstance(primitiveClass, new int[dimension]).getClass(); 747 return JavaClassInfo.getClassInfo(arrayClass); 748 } 749 } 750 } 751 752 int componentTypeIndex = className.lastIndexOf('['); 755 String componentName = className; 756 boolean isArray = false; 757 if (componentTypeIndex > 0) { 758 componentName = className.substring(0, componentTypeIndex); 759 isArray = true; 760 } 761 762 ClassInfo componentInfo = null; 763 764 if (componentName.indexOf('[') > 0) { 766 componentInfo = getClassInfo(componentName, loader); 767 } else { 768 InputStream componentClassAsStream = null; 769 if (loader != null) { 770 componentClassAsStream = loader.getResourceAsStream(componentName + ".class"); 771 } else { 772 componentClassAsStream = ClassLoader.getSystemClassLoader().getResourceAsStream(componentName + ".class"); 774 } 775 if (componentClassAsStream == null) { 776 if (componentName.indexOf('[') > 0) { 778 return getClassInfo(componentName, loader); 779 } 780 System.out.println( 781 "AW::WARNING - could not load class [" 782 + componentName 783 + "] as a resource in loader [" 784 + loader 785 + "]" 786 ); 787 componentInfo = new ClassInfo.NullClassInfo(); 788 } 789 try { 790 componentInfo = AsmClassInfo.getClassInfo(componentClassAsStream, loader, lazyAttributes); 791 } finally { 792 try { 793 componentClassAsStream.close(); 794 } catch (Exception e) { 795 ; 796 } 797 } 798 } 799 800 if (!isArray) { 801 return componentInfo; 802 } else { 803 return AsmClassInfo.getArrayClassInfo(className, loader, componentInfo); 804 } 805 } 806 807 831 836 public static class ClassNameRetrievalClassAdapter extends AsmAnnotationHelper.NullClassAdapter { 837 838 private String m_className; 839 840 public void visit(final int version, 841 final int access, 842 final String name, 843 final String superName, 844 final String [] interfaces, 845 final String sourceFile) { 846 m_className = name.replace('/', '.'); 847 } 848 849 public String getClassName() { 850 return m_className; 851 } 852 } 853 854 859 private class ClassInfoClassAdapter extends AsmAnnotationHelper.NullClassAdapter { 860 861 public boolean m_lazyAttributes = true; 862 863 public ClassInfoClassAdapter(boolean lazyAttributes) { 864 m_lazyAttributes = lazyAttributes; 865 } 866 867 public void visit(final int version, 868 final int access, 869 final String name, 870 final String superName, 871 final String [] interfaces, 872 final String sourceFile) { 873 874 m_name = name.replace('/', '.'); 875 m_modifiers = access; 876 m_isInterface = Modifier.isInterface(m_modifiers); 877 m_superClassName = superName == null ? null : superName.replace('/', '.'); 879 m_interfaceClassNames = new String [interfaces.length]; 880 for (int i = 0; i < interfaces.length; i++) { 881 m_interfaceClassNames[i] = interfaces[i].replace('/', '.'); 882 } 883 if (m_name.endsWith("[]")) { 887 m_isArray = true; 888 int index = m_name.indexOf('['); 889 m_componentTypeName = m_name.substring(0, index); 890 } else if (m_name.equals("long") 891 || m_name.equals("int") 892 || m_name.equals("short") 893 || m_name.equals("double") 894 || m_name.equals("float") 895 || m_name.equals("byte") 896 || m_name.equals("boolean") 897 || m_name.equals("char")) { 898 m_isPrimitive = true; 899 } 900 } 901 902 public void visitAttribute(final Attribute attribute) { 903 if (!m_lazyAttributes) { 905 List annotations = new ArrayList(); 906 annotations = 907 AsmAnnotationHelper.extractAnnotations(annotations, attribute, (ClassLoader ) m_loaderRef.get()); 908 m_annotations = annotations; 909 } 910 } 911 912 public void visitField(final int access, 913 final String name, 914 final String desc, 915 final Object value, 916 final Attribute attrs) { 917 final FieldStruct struct = new FieldStruct(); 918 struct.modifiers = access; 919 struct.name = name; 920 struct.desc = desc; 921 struct.value = value; 922 AsmFieldInfo fieldInfo = new AsmFieldInfo(struct, m_name, (ClassLoader ) m_loaderRef.get()); 923 if (!m_lazyAttributes) { 925 List annotations = new ArrayList(); 926 annotations = 927 AsmAnnotationHelper.extractAnnotations(annotations, attrs, (ClassLoader ) m_loaderRef.get()); 928 fieldInfo.m_annotations = annotations; 929 } 930 int hash = AsmHelper.calculateFieldHash(name, desc); 931 m_fields.put(hash, fieldInfo); 932 m_sortedFieldHashes.add(hash); 933 } 934 935 public CodeVisitor visitMethod(final int access, 936 final String name, 937 final String desc, 938 final String [] exceptions, 939 final Attribute attrs) { 940 final MethodStruct struct = new MethodStruct(); 941 struct.modifiers = access; 942 struct.name = name; 943 struct.desc = desc; 944 struct.exceptions = exceptions; 945 int hash = AsmHelper.calculateMethodHash(name, desc); 946 AsmMethodInfo methodInfo = null; 948 if (name.equals(TransformationConstants.CLINIT_METHOD_NAME)) { 949 m_hasStaticInitializer = true; 950 } else { 951 AsmMemberInfo memberInfo = null; 952 if (name.equals(TransformationConstants.INIT_METHOD_NAME)) { 953 memberInfo = new AsmConstructorInfo(struct, m_name, (ClassLoader ) m_loaderRef.get()); 954 m_constructors.put(hash, memberInfo); 955 m_sortedConstructorHashes.add(hash); 956 } else { 957 memberInfo = new AsmMethodInfo(struct, m_name, (ClassLoader ) m_loaderRef.get()); 958 m_methods.put(hash, memberInfo); 959 m_sortedMethodHashes.add(hash); 960 methodInfo = (AsmMethodInfo) memberInfo; 961 } 962 if (!m_lazyAttributes) { 964 List annotations = new ArrayList(); 965 annotations = 966 AsmAnnotationHelper.extractAnnotations(annotations, attrs, (ClassLoader ) m_loaderRef.get()); 967 memberInfo.m_annotations = annotations; 968 } 969 } 970 if (methodInfo != null) { 971 Type[] parameterTypes = Type.getArgumentTypes(desc); 974 if (parameterTypes.length > 0) { 975 CodeVisitor methodParameterNamesVisitor = new MethodParameterNamesCodeAdapter( 976 Modifier.isStatic(access), 977 parameterTypes.length, methodInfo 978 ); 979 return methodParameterNamesVisitor; 980 } else { 981 methodInfo.m_parameterNames = EMPTY_STRING_ARRAY; 982 } 983 } 984 return AsmAnnotationHelper.NullCodeAdapter.NULL_CODE_ADAPTER; 985 } 986 987 public void visitEnd() { 988 m_signature = AsmHelper.getClassDescriptor(AsmClassInfo.this); 989 } 990 } 991 992 997 static class MethodParameterNamesCodeAdapter extends AsmAnnotationHelper.NullCodeAdapter { 998 private final boolean m_isStatic; 999 private final int m_parameterCount; 1000 private AsmMethodInfo m_methodInfo; 1001 private int m_signatureParameterRegisterDepth = 0; 1002 1003 public MethodParameterNamesCodeAdapter(boolean isStatic, int parameterCount, AsmMethodInfo methodInfo) { 1004 m_isStatic = isStatic; 1005 m_parameterCount = parameterCount; 1006 m_methodInfo = methodInfo; 1007 m_methodInfo.m_parameterNames = new String [m_parameterCount]; 1008 1009 if (!m_isStatic) { 1013 m_signatureParameterRegisterDepth++; } 1015 m_signatureParameterRegisterDepth += AsmHelper.getRegisterDepth(Type.getArgumentTypes(m_methodInfo.m_member.desc)); 1016 } 1017 1018 1027 public void visitLocalVariable(String name, String desc, Label start, Label end, int index) { 1028 if (index < m_signatureParameterRegisterDepth) { 1029 if (index == 0) { 1031 if (!m_isStatic) { 1032 ; } else { 1034 m_methodInfo.pushParameterNameFromRegister(index, name); 1035 } 1036 } else { 1037 m_methodInfo.pushParameterNameFromRegister(index, name); 1038 } 1039 } else { 1040 ; } 1042 } 1043 } 1044 1045 1051 private static String getJavaClassName(final String className) { 1052 String javaClassName; 1053 if (className.startsWith("[")) { 1054 javaClassName = Type.getType(className).getClassName(); 1055 } else { 1056 javaClassName = className.replace('/', '.'); 1057 } 1058 return javaClassName; 1059 } 1060} | Popular Tags |