/** * Add a method to this class. This method is handy for implementing * methods defined by a pre-existing interface. */ public MethodInfo addMethod(Method method) { Modifiers modifiers = Modifiers.getInstance(method.getModifiers()).toAbstract(false); MethodInfo mi = addMethod(modifiers, method.getName(), MethodDesc.forMethod(method)); // exception stuff... Class[] exceptions = method.getExceptionTypes(); for (int i=0; i<exceptions.length; i++) { mi.addException(TypeDesc.forClass(exceptions[i])); } return mi; }
public NullCodeAssembler(MethodInfo mi) { mMethod = mi; TypeDesc[] paramTypes = mMethod.getMethodDescriptor().getParameterTypes(); mParams = new LocalVariable[paramTypes.length]; for (int i=0; i<paramTypes.length; i++) { mParams[i] = new Variable(null, paramTypes[i]); } }
/** * Add a constructor to this class. * * @param params May be null if constructor accepts no parameters. */ public MethodInfo addConstructor(Modifiers modifiers, TypeDesc[] params) { MethodDesc md = MethodDesc.forArguments(null, params); MethodInfo mi = new MethodInfo(this, modifiers, "<init>", md); mMethods.add(mi); return mi; }
/** * Acquire a MethodDesc from a set of arguments. * @param ret return type of method; null implies void * @param params parameters to method; null implies none */ public static MethodDesc forArguments(TypeDesc ret, TypeDesc[] params) { if (ret == null) { ret = TypeDesc.VOID; } if (params == null || params.length == 0) { params = EMPTY_PARAMS; } return intern(new MethodDesc(ret, params)); }
throw invalidDescriptor(desc); throw invalidDescriptor(desc); return intern(new MethodDesc(desc, ret, tds)); } catch (NullPointerException e) { throw invalidDescriptor(desc); } catch (IndexOutOfBoundsException e) { throw invalidDescriptor(desc);
printModifiers(mi); print(", "); print(mi.getMethodDescriptor().getParameterTypes()); println(");"); } else { print(", "); print("\"" + escape(mi.getName()) + "\", "); print(mi.getMethodDescriptor().getReturnType()); print(", "); print(mi.getMethodDescriptor().getParameterTypes()); println(");"); println(); TypeDesc[] paramTypes = mi.getMethodDescriptor().getParameterTypes(); boolean isStatic = mi.getModifiers().isStatic(); String indentStr = generateIndent(mIndent);
MethodDesc desc = MethodDesc.forMethod(method); String sig = desc.toMethodSignature(name); desc.getReturnType(), desc.getParameterTypes()) .addException(exType);
md.getReturnType() == TypeDesc.VOID && md.getParameterCount() == 0 && (method.getModifiers().isStatic()) && (!method.getModifiers().isAbstract()) && print(md.toMethodSignature(method.getName(), varargs));
/** * Create a representation of the signature which includes the method name. * This uniquely identifies the method. * * @param m method to describe */ private static String createSig(Method m) { return m.getName() + ':' + MethodDesc.forMethod(m).getDescriptor(); }
static String methodDesc(Method m, Class exceptionType) { String name = m.getDeclaringClass().getName() + '.' + m.getName(); StringBuilder b = new StringBuilder(); b.append('"'); b.append(MethodDesc.forMethod(m).toMethodSignature(name)); if (exceptionType != null) { b.append(" throws "); b.append(exceptionType.getName()); } b.append('"'); return b.toString(); }
/** * Returns this in Java method signature syntax. * * @param name method name */ public String toMethodSignature(String name) { return toMethodSignature(name, false); }
boolean graft) if (mi.getMethodDescriptor().getReturnType() == TypeDesc.VOID) { result = false; params = new TypeDesc[] {TypeDesc.INT}; } else { int argCount = mi.getMethodDescriptor().getParameterCount(); int hasThis = mi.getModifiers().isStatic() ? 0 : 1; argCount += hasThis; if (result) { resultVar = b.createLocalVariable ("result", mi.getMethodDescriptor().getReturnType()); b.storeLocal(resultVar); b.loadLocal(resultVar); b.returnValue(mi.getMethodDescriptor().getReturnType());
public Object readResolve() throws ObjectStreamException { return forDescriptor(mDescriptor); } }
public int getParameterCount() { return mMethod.getMethodDescriptor().getParameterCount(); }
MethodInfo(ClassFile parent, Modifiers modifiers, String name, MethodDesc desc) { mParent = parent; mCp = parent.getConstantPool(); mName = name; mDesc = desc; mModifiers = modifiers; mNameConstant = mCp.addConstantUTF(name); mDescriptorConstant = mCp.addConstantUTF(desc.getDescriptor()); if (!modifiers.isAbstract() && !modifiers.isNative()) { addAttribute(new CodeAttr(mCp)); } }
private MethodDesc(TypeDesc ret, TypeDesc[] params) { mDescriptor = generateDescriptor(ret, params); mRetType = ret; mParams = params; }
break; disassemble(((MethodDesc)type).getReturnType()); print(" "); if (className != null) { TypeDesc[] params = ((MethodDesc)type).getParameterTypes(); for (int i=0; i<params.length; i++) { if (i > 0) {
md.getReturnType() == TypeDesc.VOID && md.getParameterCount() == 0 && (method.getModifiers().isStatic()) && (!method.getModifiers().isAbstract()) && print(md.toMethodSignature(method.getName(), varargs));
/** * Create a representation of the signature which includes the method name. * This uniquely identifies the method. * * @param m method to describe */ private static String createSig(Method m) { return m.getName() + ':' + MethodDesc.forMethod(m).getDescriptor(); }
throw invalidDescriptor(desc); throw invalidDescriptor(desc); return intern(new MethodDesc(desc, ret, tds)); } catch (NullPointerException e) { throw invalidDescriptor(desc); } catch (IndexOutOfBoundsException e) { throw invalidDescriptor(desc);