fields.write(out); out.writeShort(methods.numOfMethods()); methods.write(out); if (aw == null) out.writeShort(0);
writeThrows(exceptions);
writeThrows(exceptions);
/** * Adds the right bytecode to call ALOAD depending on the * number of the parameter * * @param i the number of the parameter * @see Bytecode#addAload(int) */ void addAload(int i) { if (i < 4) mw.add(Opcode.ALOAD_0 + i); else if (i < 0x100) { mw.add(Opcode.ALOAD); // aload mw.add(i); } else { mw.add(Opcode.WIDE); mw.add(Opcode.ALOAD); addIndex(i); } //From Opcode.STACK_GROW[] (see test in main()) growStack(1); }
/** * Adds the right bytecode to call ALOAD depending on the * number of the parameter * * @param i the number of the parameter * @see Bytecode#addAload(int) */ void addAload(int i) { if (i < 4) mw.add(Opcode.ALOAD_0 + i); else if (i < 0x100) { mw.add(Opcode.ALOAD); // aload mw.add(i); } else { mw.add(Opcode.WIDE); mw.add(Opcode.ALOAD); addIndex(i); } //From Opcode.STACK_GROW[] (see test in main()) growStack(1); }
ClassFileWriterContext(String name, String superClassName, Class<T> type, String[] interfaceNames) { this.name = name; this.type = type; //FIXME Once we get rid of the old ClassFile stuff we should make the real names look like this //to start with name = ClassFileWriterContext.jvmClassName(name); superClassName = ClassFileWriterContext.jvmClassName(superClassName); for (int i = 0 ; i < interfaceNames.length ; i++) interfaceNames[i] = ClassFileWriterContext.jvmClassName(interfaceNames[i]); fileWriter = new ClassFileWriter(ClassFile.JAVA_4, 0); poolWriter = fileWriter.getConstPool(); thisClass = poolWriter.addClassInfo(name); superClass = poolWriter.addClassInfo(superClassName); interfaces = poolWriter.addClassInfo(interfaceNames); //Add default constructor mw = fileWriter.getMethodWriter(); mw.begin(Modifier.PUBLIC, MethodInfo.nameInit, "()V", null, null); mw.add(Opcode.ALOAD_0); mw.add(Opcode.INVOKESPECIAL); int signature = poolWriter.addNameAndTypeInfo(MethodInfo.nameInit, "()V"); mw.add16(poolWriter.addMethodrefInfo(superClass, signature)); mw.add(Opcode.RETURN); mw.codeEnd(1, 1); mw.end(null, null); }
ClassFileWriterContext(String name, String superClassName, Class<T> type, String[] interfaceNames) { this.name = name; this.type = type; //FIXME Once we get rid of the old ClassFile stuff we should make the real names look like this //to start with name = ClassFileWriterContext.jvmClassName(name); superClassName = ClassFileWriterContext.jvmClassName(superClassName); for (int i = 0 ; i < interfaceNames.length ; i++) interfaceNames[i] = ClassFileWriterContext.jvmClassName(interfaceNames[i]); fileWriter = new ClassFileWriter(ClassFile.JAVA_4, 0); poolWriter = fileWriter.getConstPool(); thisClass = poolWriter.addClassInfo(name); superClass = poolWriter.addClassInfo(superClassName); interfaces = poolWriter.addClassInfo(interfaceNames); //Add default constructor mw = fileWriter.getMethodWriter(); mw.begin(Modifier.PUBLIC, MethodInfo.nameInit, "()V", null, null); mw.add(Opcode.ALOAD_0); mw.add(Opcode.INVOKESPECIAL); int signature = poolWriter.addNameAndTypeInfo(MethodInfo.nameInit, "()V"); mw.add16(poolWriter.addMethodrefInfo(superClass, signature)); mw.add(Opcode.RETURN); mw.codeEnd(1, 1); mw.end(null, null); }
/** * Starts Adding a new method. * * @param accessFlags access flags. * @param name the method name. * @param descriptor the method signature. * @param exceptions throws clause. It may be null. * The class names must be the JVM-internal * representations like <code>java/lang/Exception</code>. * @param aw attributes to the <code>Method_info</code>. */ public void begin(int accessFlags, String name, String descriptor, String[] exceptions, AttributeWriter aw) { int nameIndex = constPool.addUtf8Info(name); int descIndex = constPool.addUtf8Info(descriptor); int[] intfs; if (exceptions == null) intfs = null; else intfs = constPool.addClassInfo(exceptions); begin(accessFlags, nameIndex, descIndex, intfs, aw); }