307N/A
45N/A/*
814N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
45N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45N/A *
45N/A * This code is free software; you can redistribute it and/or modify it
45N/A * under the terms of the GNU General Public License version 2 only, as
553N/A * published by the Free Software Foundation. Oracle designates this
45N/A * particular file as subject to the "Classpath" exception as provided
553N/A * by Oracle in the LICENSE file that accompanied this code.
45N/A *
45N/A * This code is distributed in the hope that it will be useful, but WITHOUT
45N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
45N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
45N/A * version 2 for more details (a copy is included in the LICENSE file that
45N/A * accompanied this code).
45N/A *
45N/A * You should have received a copy of the GNU General Public License version
45N/A * 2 along with this work; if not, write to the Free Software Foundation,
45N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
45N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
45N/A */
45N/A
45N/Apackage com.sun.tools.classfile;
45N/A
45N/Aimport java.io.ByteArrayOutputStream;
45N/Aimport java.io.DataOutputStream;
45N/Aimport java.io.File;
45N/Aimport java.io.FileOutputStream;
45N/Aimport java.io.IOException;
45N/Aimport java.io.OutputStream;
45N/A
45N/Aimport static com.sun.tools.classfile.Annotation.*;
45N/Aimport static com.sun.tools.classfile.ConstantPool.*;
45N/Aimport static com.sun.tools.classfile.StackMapTable_attribute.*;
45N/Aimport static com.sun.tools.classfile.StackMapTable_attribute.verification_type_info.*;
45N/A
45N/A/**
45N/A * Write a ClassFile data structure to a file or stream.
45N/A *
580N/A * <p><b>This is NOT part of any supported API.
580N/A * If you write code that depends on this, you do so at your own risk.
45N/A * This code and its internal interfaces are subject to change or
45N/A * deletion without notice.</b>
45N/A */
45N/Apublic class ClassWriter {
45N/A public ClassWriter() {
45N/A attributeWriter = new AttributeWriter();
45N/A constantPoolWriter = new ConstantPoolWriter();
45N/A out = new ClassOutputStream();
45N/A }
45N/A
45N/A /**
45N/A * Write a ClassFile data structure to a file.
45N/A */
45N/A public void write(ClassFile classFile, File f) throws IOException {
45N/A FileOutputStream f_out = new FileOutputStream(f);
45N/A try {
45N/A write(classFile, f_out);
45N/A } finally {
45N/A f_out.close();
45N/A }
45N/A }
45N/A
45N/A /**
45N/A * Write a ClassFile data structure to a stream.
45N/A */
45N/A public void write(ClassFile classFile, OutputStream s) throws IOException {
45N/A this.classFile = classFile;
45N/A out.reset();
45N/A write();
45N/A out.writeTo(s);
45N/A }
45N/A
45N/A protected void write() throws IOException {
45N/A writeHeader();
45N/A writeConstantPool();
45N/A writeAccessFlags(classFile.access_flags);
45N/A writeClassInfo();
45N/A writeFields();
45N/A writeMethods();
45N/A writeAttributes(classFile.attributes);
45N/A }
45N/A
45N/A protected void writeHeader() {
45N/A out.writeInt(classFile.magic);
45N/A out.writeShort(classFile.minor_version);
45N/A out.writeShort(classFile.major_version);
45N/A }
45N/A
45N/A protected void writeAccessFlags(AccessFlags flags) {
45N/A out.writeShort(flags.flags);
45N/A }
45N/A
45N/A protected void writeAttributes(Attributes attributes) {
45N/A int size = attributes.size();
45N/A out.writeShort(size);
45N/A for (Attribute attr: attributes)
45N/A attributeWriter.write(attr, out);
45N/A }
45N/A
45N/A protected void writeClassInfo() {
45N/A out.writeShort(classFile.this_class);
45N/A out.writeShort(classFile.super_class);
45N/A int[] interfaces = classFile.interfaces;
45N/A out.writeShort(interfaces.length);
45N/A for (int i: interfaces)
45N/A out.writeShort(i);
45N/A }
45N/A
45N/A protected void writeDescriptor(Descriptor d) {
45N/A out.writeShort(d.index);
45N/A }
45N/A
45N/A protected void writeConstantPool() {
45N/A ConstantPool pool = classFile.constant_pool;
45N/A int size = pool.size();
45N/A out.writeShort(size);
281N/A for (CPInfo cpInfo: pool.entries())
281N/A constantPoolWriter.write(cpInfo, out);
45N/A }
45N/A
45N/A protected void writeFields() throws IOException {
45N/A Field[] fields = classFile.fields;
45N/A out.writeShort(fields.length);
45N/A for (Field f: fields)
45N/A writeField(f);
45N/A }
45N/A
45N/A protected void writeField(Field f) throws IOException {
45N/A writeAccessFlags(f.access_flags);
45N/A out.writeShort(f.name_index);
45N/A writeDescriptor(f.descriptor);
45N/A writeAttributes(f.attributes);
45N/A }
45N/A
45N/A protected void writeMethods() throws IOException {
45N/A Method[] methods = classFile.methods;
45N/A out.writeShort(methods.length);
45N/A for (Method m: methods) {
45N/A writeMethod(m);
45N/A }
45N/A }
45N/A
45N/A protected void writeMethod(Method m) throws IOException {
45N/A writeAccessFlags(m.access_flags);
45N/A out.writeShort(m.name_index);
45N/A writeDescriptor(m.descriptor);
45N/A writeAttributes(m.attributes);
45N/A }
45N/A
45N/A protected ClassFile classFile;
45N/A protected ClassOutputStream out;
45N/A protected AttributeWriter attributeWriter;
45N/A protected ConstantPoolWriter constantPoolWriter;
45N/A
45N/A /**
45N/A * Subtype of ByteArrayOutputStream with the convenience methods of
45N/A * a DataOutputStream. Since ByteArrayOutputStream does not throw
45N/A * IOException, there are no exceptions from the additional
45N/A * convenience methods either,
45N/A */
45N/A protected static class ClassOutputStream extends ByteArrayOutputStream {
45N/A public ClassOutputStream() {
45N/A d = new DataOutputStream(this);
45N/A }
45N/A
45N/A public void writeByte(int value) {
45N/A try {
45N/A d.writeByte(value);
45N/A } catch (IOException ignore) {
45N/A }
45N/A }
45N/A
45N/A public void writeShort(int value) {
45N/A try {
45N/A d.writeShort(value);
45N/A } catch (IOException ignore) {
45N/A }
45N/A }
45N/A
45N/A public void writeInt(int value) {
45N/A try {
45N/A d.writeInt(value);
45N/A } catch (IOException ignore) {
45N/A }
45N/A }
45N/A
45N/A public void writeLong(long value) {
45N/A try {
45N/A d.writeLong(value);
45N/A } catch (IOException ignore) {
45N/A }
45N/A }
45N/A
45N/A public void writeFloat(float value) {
45N/A try {
45N/A d.writeFloat(value);
45N/A } catch (IOException ignore) {
45N/A }
45N/A }
45N/A
45N/A public void writeDouble(double value) {
45N/A try {
45N/A d.writeDouble(value);
45N/A } catch (IOException ignore) {
45N/A }
45N/A }
45N/A
45N/A public void writeUTF(String value) {
45N/A try {
45N/A d.writeUTF(value);
45N/A } catch (IOException ignore) {
45N/A }
45N/A }
45N/A
45N/A public void writeTo(ClassOutputStream s) {
45N/A try {
45N/A super.writeTo(s);
45N/A } catch (IOException ignore) {
45N/A }
45N/A }
45N/A
45N/A private DataOutputStream d;
45N/A }
45N/A
45N/A /**
45N/A * Writer for the entries in the constant pool.
45N/A */
45N/A protected static class ConstantPoolWriter
45N/A implements ConstantPool.Visitor<Integer,ClassOutputStream> {
45N/A protected int write(CPInfo info, ClassOutputStream out) {
45N/A out.writeByte(info.getTag());
45N/A return info.accept(this, out);
45N/A }
45N/A
45N/A public Integer visitClass(CONSTANT_Class_info info, ClassOutputStream out) {
45N/A out.writeShort(info.name_index);
45N/A return 1;
45N/A }
45N/A
45N/A public Integer visitDouble(CONSTANT_Double_info info, ClassOutputStream out) {
45N/A out.writeDouble(info.value);
45N/A return 2;
45N/A }
45N/A
45N/A public Integer visitFieldref(CONSTANT_Fieldref_info info, ClassOutputStream out) {
45N/A writeRef(info, out);
45N/A return 1;
45N/A }
45N/A
45N/A public Integer visitFloat(CONSTANT_Float_info info, ClassOutputStream out) {
45N/A out.writeFloat(info.value);
45N/A return 1;
45N/A }
45N/A
45N/A public Integer visitInteger(CONSTANT_Integer_info info, ClassOutputStream out) {
45N/A out.writeInt(info.value);
45N/A return 1;
45N/A }
45N/A
45N/A public Integer visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, ClassOutputStream out) {
45N/A writeRef(info, out);
45N/A return 1;
45N/A }
45N/A
825N/A public Integer visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, ClassOutputStream out) {
825N/A out.writeShort(info.bootstrap_method_attr_index);
825N/A out.writeShort(info.name_and_type_index);
825N/A return 1;
825N/A }
825N/A
45N/A public Integer visitLong(CONSTANT_Long_info info, ClassOutputStream out) {
45N/A out.writeLong(info.value);
45N/A return 2;
45N/A }
45N/A
45N/A public Integer visitNameAndType(CONSTANT_NameAndType_info info, ClassOutputStream out) {
45N/A out.writeShort(info.name_index);
45N/A out.writeShort(info.type_index);
45N/A return 1;
45N/A }
45N/A
825N/A public Integer visitMethodHandle(CONSTANT_MethodHandle_info info, ClassOutputStream out) {
825N/A out.writeByte(info.reference_kind.tag);
825N/A out.writeShort(info.reference_index);
825N/A return 1;
825N/A }
825N/A
825N/A public Integer visitMethodType(CONSTANT_MethodType_info info, ClassOutputStream out) {
825N/A out.writeShort(info.descriptor_index);
825N/A return 1;
825N/A }
825N/A
45N/A public Integer visitMethodref(CONSTANT_Methodref_info info, ClassOutputStream out) {
45N/A return writeRef(info, out);
45N/A }
45N/A
45N/A public Integer visitString(CONSTANT_String_info info, ClassOutputStream out) {
45N/A out.writeShort(info.string_index);
45N/A return 1;
45N/A }
45N/A
45N/A public Integer visitUtf8(CONSTANT_Utf8_info info, ClassOutputStream out) {
45N/A out.writeUTF(info.value);
45N/A return 1;
45N/A }
45N/A
45N/A protected Integer writeRef(CPRefInfo info, ClassOutputStream out) {
45N/A out.writeShort(info.class_index);
45N/A out.writeShort(info.name_and_type_index);
45N/A return 1;
45N/A }
45N/A }
45N/A
45N/A /**
45N/A * Writer for the different types of attribute.
45N/A */
45N/A protected static class AttributeWriter implements Attribute.Visitor<Void,ClassOutputStream> {
45N/A public void write(Attributes attributes, ClassOutputStream out) {
45N/A int size = attributes.size();
45N/A out.writeShort(size);
45N/A for (Attribute a: attributes)
45N/A write(a, out);
45N/A }
45N/A
45N/A // Note: due to the use of shared resources, this method is not reentrant.
45N/A public void write(Attribute attr, ClassOutputStream out) {
45N/A out.writeShort(attr.attribute_name_index);
45N/A sharedOut.reset();
45N/A attr.accept(this, sharedOut);
45N/A out.writeInt(sharedOut.size());
45N/A sharedOut.writeTo(out);
45N/A }
45N/A
45N/A protected ClassOutputStream sharedOut = new ClassOutputStream();
45N/A protected AnnotationWriter annotationWriter = new AnnotationWriter();
45N/A
45N/A public Void visitDefault(DefaultAttribute attr, ClassOutputStream out) {
45N/A out.write(attr.info, 0, attr.info.length);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitAnnotationDefault(AnnotationDefault_attribute attr, ClassOutputStream out) {
45N/A annotationWriter.write(attr.default_value, out);
45N/A return null;
45N/A }
45N/A
825N/A public Void visitBootstrapMethods(BootstrapMethods_attribute attr, ClassOutputStream out) {
825N/A out.writeShort(attr.bootstrap_method_specifiers.length);
825N/A for (BootstrapMethods_attribute.BootstrapMethodSpecifier bsm : attr.bootstrap_method_specifiers) {
825N/A out.writeShort(bsm.bootstrap_method_ref);
825N/A int bsm_args_count = bsm.bootstrap_arguments.length;
825N/A out.writeShort(bsm_args_count);
825N/A for (int i : bsm.bootstrap_arguments) {
825N/A out.writeShort(i);
825N/A }
825N/A }
825N/A return null;
825N/A }
825N/A
45N/A public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, ClassOutputStream out) {
45N/A out.writeShort(attr.character_range_table.length);
45N/A for (CharacterRangeTable_attribute.Entry e: attr.character_range_table)
45N/A writeCharacterRangeTableEntry(e, out);
45N/A return null;
45N/A }
45N/A
45N/A protected void writeCharacterRangeTableEntry(CharacterRangeTable_attribute.Entry entry, ClassOutputStream out) {
45N/A out.writeShort(entry.start_pc);
45N/A out.writeShort(entry.end_pc);
45N/A out.writeInt(entry.character_range_start);
45N/A out.writeInt(entry.character_range_end);
45N/A out.writeShort(entry.flags);
45N/A }
45N/A
45N/A public Void visitCode(Code_attribute attr, ClassOutputStream out) {
45N/A out.writeShort(attr.max_stack);
45N/A out.writeShort(attr.max_locals);
45N/A out.writeInt(attr.code.length);
45N/A out.write(attr.code, 0, attr.code.length);
45N/A out.writeShort(attr.exception_table.length);
45N/A for (Code_attribute.Exception_data e: attr.exception_table)
45N/A writeExceptionTableEntry(e, out);
45N/A new AttributeWriter().write(attr.attributes, out);
45N/A return null;
45N/A }
45N/A
45N/A protected void writeExceptionTableEntry(Code_attribute.Exception_data exception_data, ClassOutputStream out) {
45N/A out.writeShort(exception_data.start_pc);
45N/A out.writeShort(exception_data.end_pc);
45N/A out.writeShort(exception_data.handler_pc);
45N/A out.writeShort(exception_data.catch_type);
45N/A }
45N/A
45N/A public Void visitCompilationID(CompilationID_attribute attr, ClassOutputStream out) {
45N/A out.writeShort(attr.compilationID_index);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitConstantValue(ConstantValue_attribute attr, ClassOutputStream out) {
45N/A out.writeShort(attr.constantvalue_index);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitDeprecated(Deprecated_attribute attr, ClassOutputStream out) {
45N/A return null;
45N/A }
45N/A
45N/A public Void visitEnclosingMethod(EnclosingMethod_attribute attr, ClassOutputStream out) {
45N/A out.writeShort(attr.class_index);
45N/A out.writeShort(attr.method_index);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitExceptions(Exceptions_attribute attr, ClassOutputStream out) {
45N/A out.writeShort(attr.exception_index_table.length);
45N/A for (int i: attr.exception_index_table)
45N/A out.writeShort(i);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitInnerClasses(InnerClasses_attribute attr, ClassOutputStream out) {
45N/A out.writeShort(attr.classes.length);
45N/A for (InnerClasses_attribute.Info info: attr.classes)
45N/A writeInnerClassesInfo(info, out);
45N/A return null;
45N/A }
45N/A
45N/A protected void writeInnerClassesInfo(InnerClasses_attribute.Info info, ClassOutputStream out) {
45N/A out.writeShort(info.inner_class_info_index);
45N/A out.writeShort(info.outer_class_info_index);
45N/A out.writeShort(info.inner_name_index);
45N/A writeAccessFlags(info.inner_class_access_flags, out);
45N/A }
45N/A
45N/A public Void visitLineNumberTable(LineNumberTable_attribute attr, ClassOutputStream out) {
45N/A out.writeShort(attr.line_number_table.length);
45N/A for (LineNumberTable_attribute.Entry e: attr.line_number_table)
45N/A writeLineNumberTableEntry(e, out);
45N/A return null;
45N/A }
45N/A
45N/A protected void writeLineNumberTableEntry(LineNumberTable_attribute.Entry entry, ClassOutputStream out) {
45N/A out.writeShort(entry.start_pc);
45N/A out.writeShort(entry.line_number);
45N/A }
45N/A
45N/A public Void visitLocalVariableTable(LocalVariableTable_attribute attr, ClassOutputStream out) {
45N/A out.writeShort(attr.local_variable_table.length);
45N/A for (LocalVariableTable_attribute.Entry e: attr.local_variable_table)
45N/A writeLocalVariableTableEntry(e, out);
45N/A return null;
45N/A }
45N/A
45N/A protected void writeLocalVariableTableEntry(LocalVariableTable_attribute.Entry entry, ClassOutputStream out) {
45N/A out.writeShort(entry.start_pc);
45N/A out.writeShort(entry.length);
45N/A out.writeShort(entry.name_index);
45N/A out.writeShort(entry.descriptor_index);
45N/A out.writeShort(entry.index);
45N/A }
45N/A
45N/A public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, ClassOutputStream out) {
351N/A out.writeShort(attr.local_variable_table.length);
45N/A for (LocalVariableTypeTable_attribute.Entry e: attr.local_variable_table)
45N/A writeLocalVariableTypeTableEntry(e, out);
45N/A return null;
45N/A }
45N/A
45N/A protected void writeLocalVariableTypeTableEntry(LocalVariableTypeTable_attribute.Entry entry, ClassOutputStream out) {
45N/A out.writeShort(entry.start_pc);
45N/A out.writeShort(entry.length);
45N/A out.writeShort(entry.name_index);
45N/A out.writeShort(entry.signature_index);
45N/A out.writeShort(entry.index);
45N/A }
45N/A
45N/A public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, ClassOutputStream out) {
45N/A annotationWriter.write(attr.annotations, out);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, ClassOutputStream out) {
45N/A annotationWriter.write(attr.annotations, out);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, ClassOutputStream out) {
45N/A out.writeByte(attr.parameter_annotations.length);
45N/A for (Annotation[] annos: attr.parameter_annotations)
45N/A annotationWriter.write(annos, out);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, ClassOutputStream out) {
45N/A out.writeByte(attr.parameter_annotations.length);
45N/A for (Annotation[] annos: attr.parameter_annotations)
45N/A annotationWriter.write(annos, out);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitSignature(Signature_attribute attr, ClassOutputStream out) {
45N/A out.writeShort(attr.signature_index);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, ClassOutputStream out) {
45N/A out.write(attr.debug_extension, 0, attr.debug_extension.length);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitSourceFile(SourceFile_attribute attr, ClassOutputStream out) {
45N/A out.writeShort(attr.sourcefile_index);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitSourceID(SourceID_attribute attr, ClassOutputStream out) {
45N/A out.writeShort(attr.sourceID_index);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitStackMap(StackMap_attribute attr, ClassOutputStream out) {
45N/A if (stackMapWriter == null)
45N/A stackMapWriter = new StackMapTableWriter();
45N/A
45N/A out.writeShort(attr.entries.length);
45N/A for (stack_map_frame f: attr.entries)
45N/A stackMapWriter.write(f, out);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitStackMapTable(StackMapTable_attribute attr, ClassOutputStream out) {
45N/A if (stackMapWriter == null)
45N/A stackMapWriter = new StackMapTableWriter();
45N/A
45N/A out.writeShort(attr.entries.length);
45N/A for (stack_map_frame f: attr.entries)
45N/A stackMapWriter.write(f, out);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitSynthetic(Synthetic_attribute attr, ClassOutputStream out) {
45N/A return null;
45N/A }
45N/A
45N/A protected void writeAccessFlags(AccessFlags flags, ClassOutputStream p) {
45N/A sharedOut.writeShort(flags.flags);
45N/A }
45N/A
45N/A protected StackMapTableWriter stackMapWriter;
45N/A }
45N/A
45N/A /**
45N/A * Writer for the frames of StackMap and StackMapTable attributes.
45N/A */
45N/A protected static class StackMapTableWriter
45N/A implements stack_map_frame.Visitor<Void,ClassOutputStream> {
45N/A
45N/A public void write(stack_map_frame frame, ClassOutputStream out) {
45N/A out.write(frame.frame_type);
45N/A frame.accept(this, out);
45N/A }
45N/A
45N/A public Void visit_same_frame(same_frame frame, ClassOutputStream p) {
45N/A return null;
45N/A }
45N/A
45N/A public Void visit_same_locals_1_stack_item_frame(same_locals_1_stack_item_frame frame, ClassOutputStream out) {
45N/A writeVerificationTypeInfo(frame.stack[0], out);
45N/A return null;
45N/A }
45N/A
45N/A public Void visit_same_locals_1_stack_item_frame_extended(same_locals_1_stack_item_frame_extended frame, ClassOutputStream out) {
45N/A out.writeShort(frame.offset_delta);
45N/A writeVerificationTypeInfo(frame.stack[0], out);
45N/A return null;
45N/A }
45N/A
45N/A public Void visit_chop_frame(chop_frame frame, ClassOutputStream out) {
45N/A out.writeShort(frame.offset_delta);
45N/A return null;
45N/A }
45N/A
45N/A public Void visit_same_frame_extended(same_frame_extended frame, ClassOutputStream out) {
45N/A out.writeShort(frame.offset_delta);
45N/A return null;
45N/A }
45N/A
45N/A public Void visit_append_frame(append_frame frame, ClassOutputStream out) {
45N/A out.writeShort(frame.offset_delta);
45N/A for (verification_type_info l: frame.locals)
45N/A writeVerificationTypeInfo(l, out);
45N/A return null;
45N/A }
45N/A
45N/A public Void visit_full_frame(full_frame frame, ClassOutputStream out) {
45N/A out.writeShort(frame.offset_delta);
45N/A out.writeShort(frame.locals.length);
45N/A for (verification_type_info l: frame.locals)
45N/A writeVerificationTypeInfo(l, out);
45N/A out.writeShort(frame.stack.length);
45N/A for (verification_type_info s: frame.stack)
45N/A writeVerificationTypeInfo(s, out);
45N/A return null;
45N/A }
45N/A
45N/A protected void writeVerificationTypeInfo(verification_type_info info,
45N/A ClassOutputStream out) {
45N/A out.write(info.tag);
45N/A switch (info.tag) {
45N/A case ITEM_Top:
45N/A case ITEM_Integer:
45N/A case ITEM_Float:
45N/A case ITEM_Long:
45N/A case ITEM_Double:
45N/A case ITEM_Null:
45N/A case ITEM_UninitializedThis:
45N/A break;
45N/A
45N/A case ITEM_Object:
45N/A Object_variable_info o = (Object_variable_info) info;
45N/A out.writeShort(o.cpool_index);
45N/A break;
45N/A
45N/A case ITEM_Uninitialized:
45N/A Uninitialized_variable_info u = (Uninitialized_variable_info) info;
45N/A out.writeShort(u.offset);
45N/A break;
45N/A
45N/A default:
45N/A throw new Error();
45N/A }
45N/A }
45N/A }
45N/A
45N/A /**
45N/A * Writer for annotations and the values they contain.
45N/A */
45N/A protected static class AnnotationWriter
45N/A implements Annotation.element_value.Visitor<Void,ClassOutputStream> {
45N/A public void write(Annotation[] annos, ClassOutputStream out) {
45N/A out.writeShort(annos.length);
45N/A for (Annotation anno: annos)
45N/A write(anno, out);
45N/A }
45N/A
45N/A public void write(Annotation anno, ClassOutputStream out) {
45N/A out.writeShort(anno.type_index);
45N/A out.writeShort(anno.element_value_pairs.length);
45N/A for (element_value_pair p: anno.element_value_pairs)
45N/A write(p, out);
45N/A }
45N/A
45N/A public void write(element_value_pair pair, ClassOutputStream out) {
45N/A out.writeShort(pair.element_name_index);
45N/A write(pair.value, out);
45N/A }
45N/A
45N/A public void write(element_value ev, ClassOutputStream out) {
45N/A out.writeByte(ev.tag);
45N/A ev.accept(this, out);
45N/A }
45N/A
45N/A public Void visitPrimitive(Primitive_element_value ev, ClassOutputStream out) {
45N/A out.writeShort(ev.const_value_index);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitEnum(Enum_element_value ev, ClassOutputStream out) {
45N/A out.writeShort(ev.type_name_index);
45N/A out.writeShort(ev.const_name_index);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitClass(Class_element_value ev, ClassOutputStream out) {
45N/A out.writeShort(ev.class_info_index);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitAnnotation(Annotation_element_value ev, ClassOutputStream out) {
45N/A write(ev.annotation_value, out);
45N/A return null;
45N/A }
45N/A
45N/A public Void visitArray(Array_element_value ev, ClassOutputStream out) {
45N/A out.writeShort(ev.num_values);
45N/A for (element_value v: ev.values)
45N/A write(v, out);
45N/A return null;
45N/A }
307N/A
45N/A }
45N/A}