@Override public MethodInfo get(int i) { return new MethodInfo(clazz, methods[i]); }
throw new IllegalArgumentException(e); return new MethodInfo(clazz, bytes, parameterNameBytes, args, returnType, flags, typeParameters, exceptions);
/** * Retrieves a method based on its signature, which includes a method name and an argument list. * The argument list is compared based on the underlying raw type of the type arguments. As an example, * a generic type parameter "T" is equivalent to <code>java.lang.Object</code>, since the raw form * of a type parameter is its upper bound. * * <p>Eligible methods include constructors and static initializer blocks which have the special JVM * assigned names of "<init>" and "<clinit>", respectively. This does not, however, include * inherited methods. These must be discovered by traversing the class hierarchy.</p> * * @param name the name of the method to find * @param parameters the type parameters of the method * @return the located method or null if not found */ public final MethodInfo method(String name, Type... parameters) { MethodInternal key = new MethodInternal(Utils.toUTF8(name), MethodInternal.EMPTY_PARAMETER_NAMES, parameters, null, (short) 0); int i = Arrays.binarySearch(methods, key, MethodInternal.NAME_AND_PARAMETER_COMPONENT_COMPARATOR); return i >= 0 ? new MethodInfo(this, methods[i]) : null; }
/** * Retrieves the "first" occurrence of a method by the given name. Note that the order of methods * is not defined, and may change in the future. Therefore, this method should not be used when * overloading is possible. It's merely intended to provide a handy shortcut for throw away or test * code. * * @param name the name of the method * @return the first discovered method matching this name, or null if no match is found */ public final MethodInfo firstMethod(String name) { MethodInternal key = new MethodInternal(Utils.toUTF8(name), MethodInternal.EMPTY_PARAMETER_NAMES, Type.EMPTY_ARRAY, null, (short) 0); int i = Arrays.binarySearch(methods, key, MethodInternal.NAME_AND_PARAMETER_COMPONENT_COMPARATOR); if (i < -methods.length) { return null; } MethodInfo method = new MethodInfo(this,i >= 0 ? methods[i] : methods[++i * -1]); return method.name().equals(name) ? method : null; }
private MethodInfo readMethod(ClassInfo clazz, PackedDataInputStream stream) throws IOException { String name = stringTable[stream.readPackedU32()]; int numArgs = stream.readPackedU32(); List<Type> args = new ArrayList<Type>(numArgs); for (int i = 0; i < numArgs; i ++) { args.add(readType(stream)); } Type[] parameters = args.toArray(new Type[args.size()]); Type returnType = readType(stream); short flags = stream.readShort(); byte[] bytes = Utils.toUTF8(name); return new MethodInfo(clazz, bytes, MethodInternal.EMPTY_PARAMETER_NAMES, parameters, returnType, flags); }
private void processMethodInfo(DataInputStream data) throws IOException { int numMethods = data.readUnsignedShort(); List<MethodInfo> methods = numMethods > 0 ? new ArrayList<MethodInfo>(numMethods) : Collections.<MethodInfo>emptyList(); for (int i = 0; i < numMethods; i++) { short flags = (short) data.readUnsignedShort(); byte[] name = intern(decodeUtf8EntryAsBytes(data.readUnsignedShort())); String descriptor = decodeUtf8Entry(data.readUnsignedShort()); IntegerHolder pos = new IntegerHolder(); Type[] parameters = intern(parseMethodArgs(descriptor, pos)); Type returnType = parseType(descriptor, pos); MethodInfo method = new MethodInfo(currentClass, name, MethodInternal.EMPTY_PARAMETER_NAMES, parameters, returnType, flags); if (parameters.length == 0 && Arrays.equals(INIT_METHOD_NAME, name)) { currentClass.setHasNoArgsConstructor(true); } methodParameterNames = debugParameterNames = null; processAttributes(data, method); method.setAnnotations(elementAnnotations); elementAnnotations.clear(); // Prefer method parameter names over debug info if(methodParameterNames != null) method.methodInternal().setParameterNames(methodParameterNames); else if(debugParameterNames != null) method.methodInternal().setParameterNames(debugParameterNames); methods.add(method); } this.methods = methods; }
MethodInfo methodInfo = new MethodInfo(); AnnotationInstance[] annotations = readAnnotations(stream, methodInfo); MethodInternal methodInternal = new MethodInternal(name, methodParameterBytes, parameters, returnType, flags,