1 32 package net.sf.retrotranslator.runtime.java.lang.reflect; 33 34 import java.lang.reflect.*; 35 import net.sf.retrotranslator.runtime.asm.Opcodes; 36 import net.sf.retrotranslator.runtime.impl.*; 37 import net.sf.retrotranslator.runtime.java.lang.annotation.Annotation_; 38 39 42 public class _Method { 43 44 public static Annotation_ getAnnotation(Method method, Class annotationType) { 45 return MethodDescriptor.getInstance(method).getAnnotation(annotationType); 46 } 47 48 public static Annotation_[] getAnnotations(Method method) { 49 return MethodDescriptor.getInstance(method).getAnnotations(); 50 } 51 52 public static Annotation_[] getDeclaredAnnotations(Method method) { 53 return MethodDescriptor.getInstance(method).getDeclaredAnnotations(); 54 } 55 56 public static Object getDefaultValue(Method method) { 57 return MethodDescriptor.getInstance(method).getDefaultValue(); 58 } 59 60 public static Type[] getGenericExceptionTypes(Method method) { 61 Type[] types = MethodDescriptor.getInstance(method).getGenericExceptionTypes(); 62 return types != null ? types : method.getExceptionTypes(); 63 } 64 65 public static Type[] getGenericParameterTypes(Method method) { 66 Type[] types = MethodDescriptor.getInstance(method).getGenericParameterTypes(); 67 return types != null ? types : method.getParameterTypes(); 68 } 69 70 public static Type getGenericReturnType(Method method) { 71 Type type = MethodDescriptor.getInstance(method).getGenericReturnType(); 72 return type != null ? type : method.getReturnType(); 73 } 74 75 public static Annotation_[][] getParameterAnnotations(Method method) { 76 return MethodDescriptor.getInstance(method).getParameterAnnotations(); 77 } 78 79 public static TypeVariable[] getTypeParameters(Method method) { 80 return MethodDescriptor.getInstance(method).getTypeParameters(); 81 } 82 83 public static boolean isAnnotationPresent(Method method, Class annotationType) { 84 return MethodDescriptor.getInstance(method).isAnnotationPresent(annotationType); 85 } 86 87 public static boolean isBridge(Method method) { 88 return MethodDescriptor.getInstance(method).isAccess(Opcodes.ACC_BRIDGE); 89 } 90 91 public static boolean isSynthetic(Method method) { 92 return MethodDescriptor.getInstance(method).isAccess(Opcodes.ACC_SYNTHETIC); 93 } 94 95 public static boolean isVarArgs(Method method) { 96 return MethodDescriptor.getInstance(method).isAccess(Opcodes.ACC_VARARGS); 97 } 98 99 public static String toGenericString(Method method) { 100 StringBuilder builder = new StringBuilder (); 101 if (method.getModifiers() != 0) { 102 builder.append(Modifier.toString(method.getModifiers())).append(' '); 103 } 104 TypeVariable[] typeParameters = getTypeParameters(method); 105 if (typeParameters.length > 0) { 106 RuntimeTools.append(builder.append('<'), typeParameters).append("> "); 107 } 108 builder.append(RuntimeTools.getString(getGenericReturnType(method))).append(' '); 109 builder.append(RuntimeTools.getString(method.getDeclaringClass())).append('.').append(method.getName()); 110 RuntimeTools.append(builder.append('('), getGenericParameterTypes(method)).append(')'); 111 Type[] exceptionTypes = getGenericExceptionTypes(method); 112 if (exceptionTypes.length > 0) { 113 RuntimeTools.append(builder.append(" throws "), exceptionTypes); 114 } 115 return builder.toString(); 116 } 117 118 } 119 | Popular Tags |