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); }
/** * Appends a invokevirtual, inovkespecial, or invokestatic bytecode. * * @see Opcode */ public void addInvoke(int opcode, String targetClass, String methodName, String descriptor) { int target = constPool.addClassInfo(targetClass); int nt = constPool.addNameAndTypeInfo(methodName, descriptor); int method = constPool.addMethodrefInfo(target, nt); add(opcode); add16(method); }
/** * Appends a invokevirtual, inovkespecial, or invokestatic bytecode. * * @see Opcode */ public void addInvoke(int opcode, String targetClass, String methodName, String descriptor) { int target = constPool.addClassInfo(targetClass); int nt = constPool.addNameAndTypeInfo(methodName, descriptor); int method = constPool.addMethodrefInfo(target, nt); add(opcode); add16(method); }
/** * Appends a invokevirtual, inovkespecial, or invokestatic bytecode. * * @see Opcode */ public void addInvoke(int opcode, String targetClass, String methodName, String descriptor) { int target = constPool.addClassInfo(targetClass); int nt = constPool.addNameAndTypeInfo(methodName, descriptor); int method = constPool.addMethodrefInfo(target, nt); add(opcode); add16(method); }
private void addFieldRefInfo(String className, String fieldName, String type) { addIndex(poolWriter.addFieldrefInfo(poolWriter.addClassInfo(className), poolWriter.addNameAndTypeInfo(fieldName, type))); }
/** * Appends a invokevirtual, inovkespecial, or invokestatic bytecode. * * @see Opcode */ public void addInvoke(int opcode, String targetClass, String methodName, String descriptor) { int target = constPool.addClassInfo(targetClass); int nt = constPool.addNameAndTypeInfo(methodName, descriptor); int method = constPool.addMethodrefInfo(target, nt); add(opcode); add16(method); }
private void addFieldRefInfo(String className, String fieldName, String type) { addIndex(poolWriter.addFieldrefInfo(poolWriter.addClassInfo(className), poolWriter.addNameAndTypeInfo(fieldName, type))); }
/** * Adds a new <code>CONSTANT_NameAndType_info</code> structure. * * @param name <code>name_index</code> * @param type <code>descriptor_index</code> * @return the index of the added entry. */ public int addNameAndTypeInfo(String name, String type) { return addNameAndTypeInfo(addUtf8Info(name), addUtf8Info(type)); }
/** * Adds a new <code>CONSTANT_NameAndType_info</code> structure. * * @param name <code>name_index</code> * @param type <code>descriptor_index</code> * @return the index of the added entry. */ public int addNameAndTypeInfo(String name, String type) { return addNameAndTypeInfo(addUtf8Info(name), addUtf8Info(type)); }
/** * Adds a new <code>CONSTANT_NameAndType_info</code> structure. * * @param name <code>name_index</code> * @param type <code>descriptor_index</code> * @return the index of the added entry. */ public int addNameAndTypeInfo(String name, String type) { return addNameAndTypeInfo(addUtf8Info(name), addUtf8Info(type)); }
/** * Adds a new <code>CONSTANT_NameAndType_info</code> structure. * * @param name <code>name_index</code> * @param type <code>descriptor_index</code> * @return the index of the added entry. */ public int addNameAndTypeInfo(String name, String type) { return addNameAndTypeInfo(addUtf8Info(name), addUtf8Info(type)); }
/** * Appends a invokevirtual, inovkespecial, or invokestatic bytecode. * * @see Opcode */ public void addInvoke(int opcode, String targetClass, String methodName, String descriptor) { int target = constPool.addClassInfo(targetClass); int nt = constPool.addNameAndTypeInfo(methodName, descriptor); int method = constPool.addMethodrefInfo(target, nt); add(opcode); add16(method); }
/** * Adds a new <code>CONSTANT_NameAndType_info</code> structure. * * @param name <code>name_index</code> * @param type <code>descriptor_index</code> * @return the index of the added entry. */ public int addNameAndTypeInfo(String name, String type) { return addNameAndTypeInfo(addUtf8Info(name), addUtf8Info(type)); }
/** * Appends a invokevirtual, inovkespecial, or invokestatic bytecode. * * @see Opcode */ public void addInvoke(int opcode, String targetClass, String methodName, String descriptor) { int target = constPool.addClassInfo(targetClass); int nt = constPool.addNameAndTypeInfo(methodName, descriptor); int method = constPool.addMethodrefInfo(target, nt); add(opcode); add16(method); }
/** * Adds a new <code>CONSTANT_NameAndType_info</code> structure. * * @param name <code>name_index</code> * @param type <code>descriptor_index</code> * @return the index of the added entry. */ public int addNameAndTypeInfo(String name, String type) { return addNameAndTypeInfo(addUtf8Info(name), addUtf8Info(type)); }