/** * 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; }
private void disassemble(String indent, MethodInfo method) { SignatureAttr sig = method.getSignatureAttr(); if (method.isDeprecated() || method.isSynthetic() || sig != null) { println(indent, "/**"); if (method.isDeprecated()) { println(indent, " * @deprecated"); if (method.isSynthetic()) { println(indent, " * @synthetic"); disassemble(indent, method.getRuntimeVisibleAnnotations()); disassemble(indent, method.getRuntimeInvisibleAnnotations()); MethodDesc md = method.getMethodDescriptor(); if ("<clinit>".equals(method.getName()) && md.getReturnType() == TypeDesc.VOID && md.getParameterCount() == 0 && (method.getModifiers().isStatic()) && (!method.getModifiers().isAbstract()) && method.getExceptions().length == 0) { Modifiers modifiers = method.getModifiers(); boolean varargs = modifiers.isVarArgs(); if (varargs) { print(md.toMethodSignature(method.getName(), varargs)); CodeAttr code = method.getCodeAttr();
static MethodInfo readFrom(ClassFile parent, DataInput din, AttributeFactory attrFactory) throws IOException { ConstantPool cp = parent.getConstantPool(); int modifier = din.readUnsignedShort(); int index = din.readUnsignedShort(); ConstantUTFInfo nameConstant = (ConstantUTFInfo)cp.getConstant(index); index = din.readUnsignedShort(); ConstantUTFInfo descConstant = (ConstantUTFInfo)cp.getConstant(index); MethodInfo info = new MethodInfo(parent, modifier, nameConstant, descConstant); // Read attributes. int size = din.readUnsignedShort(); for (int i=0; i<size; i++) { info.addAttribute(Attribute.readFrom(cp, din, attrFactory)); } return info; } }
void set(ConstantPool cp, MethodInfo info) { TypeDesc[] paramTypes = info.getMethodDescriptor().getParameterTypes(); VerificationTypeInfo[] infos; int offset; if (info.getModifiers().isStatic()) { infos = new VerificationTypeInfo[paramTypes.length]; offset = 0; } else { infos = new VerificationTypeInfo[1 + paramTypes.length]; if (info.getName().equals("<init>")) { infos[0] = UninitThisVariableInfo.THE; } else { infos[0] = VerificationTypeInfo.forType(cp, info.getClassFile().getType()); } offset = 1; } for (int i=0; i<paramTypes.length; i++) { infos[offset + i] = VerificationTypeInfo.forType(cp, paramTypes[i]); } mLocalInfos = infos; } }
boolean saveLocalVariableInfo) { String target = info.getClassFile().getTarget(); if ("1.0".equals(target)) { mTarget = 0x00010000; mCodeAttr = info.getCodeAttr(); mClassFile = info.getClassFile(); mCp = mClassFile.getConstantPool(); mInstructions = new InstructionList(saveLocalVariableInfo); if (info.getModifiers().isStatic()) { mThisReference = null; } else { TypeDesc[] paramTypes = info.getMethodDescriptor().getParameterTypes(); int paramSize = paramTypes.length;
if (mi.getName().equals("<clinit>")) { println("Initializer();"); } else if (mi.getName().equals("<init>")) { print("Constructor("); printModifiers(mi); print(", "); print(mi.getMethodDescriptor().getParameterTypes()); println(");"); } else { printModifiers(mi); print(", "); print("\"" + escape(mi.getName()) + "\", "); print(mi.getMethodDescriptor().getReturnType()); print(", "); print(mi.getMethodDescriptor().getParameterTypes()); println(");"); if (mi.isSynthetic()) { println("mi.markSynthetic();"); if (mi.isDeprecated()) { println("mi.markDeprecated();"); TypeDesc[] exceptions = mi.getExceptions(); for (int j=0; j<exceptions.length; j++) { print("mi.addException("); if (mi.getCodeAttr() != null) {
mAssembler = assembler; mLocals = new Vector<Object>(); if (mHasThis = !mMethod.getModifiers().isStatic()) { TypeDesc[] paramTypes = mMethod.getMethodDescriptor().getParameterTypes(); assembler.invokeConstructor(paramTypes); } else { if ("<init>".equals(mMethod.getName()) && className.equals(mSuperClassName)) { assembler.invokeSuperConstructor(paramTypes);
mi.markSynthetic(); if (property.isJoin()) { mi.addException(TypeDesc.forClass(FetchException.class)); mi.setModifiers(mi.getModifiers().toSynchronized(true)); mi = mClassFile.addMethod(Modifiers.PROTECTED, writeName, null, new TypeDesc[]{type}); mi.markSynthetic(); mi.setModifiers(mi.getModifiers().toSynchronized(true)); CodeBuilder b = new CodeBuilder(mi); MethodInfo mi = mClassFile.addMethod (Modifiers.PROTECTED, readName, toType, null); mi.markSynthetic(); MethodInfo mi = mClassFile.addMethod (Modifiers.PROTECTED, writeName, null, new TypeDesc[] {fromType}); mi.markSynthetic(); mi.setModifiers(mi.getModifiers().toSynchronized(true)); mi.addException(TypeDesc.forClass(FetchException.class)); (Modifiers.PROTECTED.toAbstract(true), DO_TRY_LOAD_METHOD_NAME, TypeDesc.BOOLEAN, null); mi.addException(TypeDesc.forClass(FetchException.class)); mi.addException(TypeDesc.forClass(FetchException.class));
if (trace != null) { new AnnotationBuilder().visit (trace, mi.addRuntimeVisibleAnnotation(TypeDesc.forClass(Trace.class))); for (TypeDesc desc : exceptionDescs) { if (isKnownType(mType.getClassLoader(), desc)) { mi.addException(desc); mi.addException(desc); b.loadConstant(mi.getMethodDescriptor().toMethodSignature(localMethod.getName())); b.invokeConstructor(UNIMPLEMENTED_EX_TYPE, new TypeDesc[] {TypeDesc.STRING}); b.throwObject();
for (int i=0; i<methods.length; i++) { MethodInfo method = methods[i]; if ("define".equals(method.getName())) { if (defineMethod != null) { throw new IllegalArgumentException("Multiple define methods found"); TypeDesc[] paramTypes = defineMethod.getMethodDescriptor().getParameterTypes(); LocalVariable[] paramVars = new LocalVariable[paramTypes.length]; for (int i=paramVars.length; --i>=0; ) {
aFlags = ((FieldInfo)a).getModifiers(); } else { aFlags = ((MethodInfo)a).getModifiers(); bFlags = ((FieldInfo)b).getModifiers(); } else { bFlags = ((MethodInfo)b).getModifiers(); String aName = ((MethodInfo)a).getName(); String bName = ((MethodInfo)b).getName();
MethodInfo mi) if (mi.getModifiers().isAbstract() || mi.getModifiers().isNative()) { return; Annotation[] annotations = mi.getRuntimeVisibleAnnotations(); for (Annotation ann : annotations) { if (ann.getType().getFullName().equals(Trace.class.getName())) {
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 int getParameterCount() { return mMethod.getMethodDescriptor().getParameterCount(); }
/** * Returns the static initializer defined in this class or null if there * isn't one. */ public MethodInfo getInitializer() { int size = mMethods.size(); for (int i=0; i<size; i++) { MethodInfo method = mMethods.get(i); if ("<clinit>".equals(method.getName())) { return method; } } return null; }
private static RuntimeClassFile generateClassFile(Class beanType, PropertySet set) { BeanProperty[][] props = getBeanProperties(beanType, set); RuntimeClassFile cf = new RuntimeClassFile (BeanPropertyAccessor.class.getName(), BeanPropertyAccessor.class.getName(), beanType.getClassLoader()); cf.markSynthetic(); cf.setSourceFile(BeanPropertyAccessor.class.getName()); try { cf.setTarget(System.getProperty("java.specification.version")); } catch (Exception e) { } MethodInfo ctor = cf.addConstructor(Modifiers.PUBLIC, null); ctor.markSynthetic(); CodeBuilder b = new CodeBuilder(ctor); b.loadThis(); b.invokeSuperConstructor(null); b.returnVoid(); generateAccessMethod(cf, beanType, props[0], READ_METHOD); generateAccessMethod(cf, beanType, props[0], TRY_READ_METHOD); generateAccessMethod(cf, beanType, props[0], HAS_READ_METHOD); generateAccessMethod(cf, beanType, props[1], WRITE_METHOD); generateAccessMethod(cf, beanType, props[1], TRY_WRITE_METHOD); generateAccessMethod(cf, beanType, props[1], HAS_WRITE_METHOD); generateSearchMethod(cf, beanType, props[0]); return cf; }
/** * Mark this method as being synthetic by adding a special attribute. */ public void markSynthetic() { addAttribute(new SyntheticAttr(mCp)); }
private void printModifiers(MethodInfo mi) { printModifiers(mi.getModifiers()); }
/** * Add a method to this class. */ public MethodInfo addMethod(Modifiers modifiers, String methodName, MethodDesc md) { MethodInfo mi = new MethodInfo(this, modifiers, methodName, md); mMethods.add(mi); return mi; }
/** * Add an inner class to this method. * * @param innerClassName Optional short inner class name. */ public ClassFile addInnerClass(String innerClassName) { return addInnerClass(innerClassName, (String)null); }