/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Write a ClassFile data structure to a file or stream.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*/
public class ClassWriter {
public ClassWriter() {
attributeWriter = new AttributeWriter();
constantPoolWriter = new ConstantPoolWriter();
out = new ClassOutputStream();
}
/**
* Write a ClassFile data structure to a file.
*/
try {
} finally {
}
}
/**
* Write a ClassFile data structure to a stream.
*/
write();
}
writeHeader();
writeFields();
writeMethods();
}
protected void writeHeader() {
}
}
}
protected void writeClassInfo() {
for (int i: interfaces)
out.writeShort(i);
}
}
protected void writeConstantPool() {
}
writeField(f);
}
}
writeMethod(m);
}
}
}
/**
* Subtype of ByteArrayOutputStream with the convenience methods of
* a DataOutputStream. Since ByteArrayOutputStream does not throw
* IOException, there are no exceptions from the additional
* convenience methods either,
*/
public ClassOutputStream() {
d = new DataOutputStream(this);
}
try {
} catch (IOException ignore) {
}
}
try {
d.writeShort(value);
} catch (IOException ignore) {
}
}
try {
} catch (IOException ignore) {
}
}
try {
} catch (IOException ignore) {
}
}
try {
d.writeFloat(value);
} catch (IOException ignore) {
}
}
try {
d.writeDouble(value);
} catch (IOException ignore) {
}
}
try {
} catch (IOException ignore) {
}
}
try {
super.writeTo(s);
} catch (IOException ignore) {
}
}
private DataOutputStream d;
}
/**
* Writer for the entries in the constant pool.
*/
protected static class ConstantPoolWriter
}
return 1;
}
return 2;
}
return 1;
}
return 1;
}
return 1;
}
public Integer visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, ClassOutputStream out) {
return 1;
}
return 1;
}
return 2;
}
return 1;
}
return 1;
}
return 1;
}
}
return 1;
}
return 1;
}
return 1;
}
}
/**
* Writer for the different types of attribute.
*/
for (Attribute a: attributes)
}
// Note: due to the use of shared resources, this method is not reentrant.
}
return null;
}
return null;
}
for (int i : bsm.bootstrap_arguments) {
out.writeShort(i);
}
}
return null;
}
return null;
}
protected void writeCharacterRangeTableEntry(CharacterRangeTable_attribute.Entry entry, ClassOutputStream out) {
}
return null;
}
protected void writeExceptionTableEntry(Code_attribute.Exception_data exception_data, ClassOutputStream out) {
}
return null;
}
return null;
}
return null;
}
return null;
}
for (int i: attr.exception_index_table)
out.writeShort(i);
return null;
}
return null;
}
}
return null;
}
protected void writeLineNumberTableEntry(LineNumberTable_attribute.Entry entry, ClassOutputStream out) {
}
return null;
}
protected void writeLocalVariableTableEntry(LocalVariableTable_attribute.Entry entry, ClassOutputStream out) {
}
public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, ClassOutputStream out) {
return null;
}
protected void writeLocalVariableTypeTableEntry(LocalVariableTypeTable_attribute.Entry entry, ClassOutputStream out) {
}
public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, ClassOutputStream out) {
return null;
}
public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, ClassOutputStream out) {
return null;
}
public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, ClassOutputStream out) {
return null;
}
public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, ClassOutputStream out) {
return null;
}
return null;
}
return null;
}
return null;
}
return null;
}
if (stackMapWriter == null)
stackMapWriter = new StackMapTableWriter();
return null;
}
if (stackMapWriter == null)
stackMapWriter = new StackMapTableWriter();
return null;
}
return null;
}
}
}
/**
* Writer for the frames of StackMap and StackMapTable attributes.
*/
protected static class StackMapTableWriter
}
return null;
}
public Void visit_same_locals_1_stack_item_frame(same_locals_1_stack_item_frame frame, ClassOutputStream out) {
return null;
}
public Void visit_same_locals_1_stack_item_frame_extended(same_locals_1_stack_item_frame_extended frame, ClassOutputStream out) {
return null;
}
return null;
}
return null;
}
return null;
}
return null;
}
case ITEM_Top:
case ITEM_Integer:
case ITEM_Float:
case ITEM_Long:
case ITEM_Double:
case ITEM_Null:
case ITEM_UninitializedThis:
break;
case ITEM_Object:
break;
case ITEM_Uninitialized:
break;
default:
throw new Error();
}
}
}
/**
* Writer for annotations and the values they contain.
*/
protected static class AnnotationWriter
}
}
}
}
return null;
}
return null;
}
return null;
}
return null;
}
return null;
}
}
}