SAXCodeAdapterpublic final class SAXCodeAdapter extends Object implements CodeVisitorA {@link oracle.toplink.libraries.asm.CodeVisitor CodeVisitor} that generates SAX 2.0
events from the visited code. |
Fields Summary |
---|
private ContentHandler | h | private Map | labelNames |
Constructors Summary |
---|
public SAXCodeAdapter(ContentHandler h)Constructs a new {@link SAXCodeAdapter SAXCodeAdapter} object.
this.h = h;
labelNames = new HashMap();
|
Methods Summary |
---|
private final void | addElement(java.lang.String name, org.xml.sax.Attributes attrs)
addStart( name, attrs);
addEnd( name);
| private final void | addEnd(java.lang.String name)
try {
h.endElement( "", name, name);
} catch( SAXException ex) {
throw new RuntimeException( ex.toString());
}
| private final void | addStart(java.lang.String name, org.xml.sax.Attributes attrs)
try {
h.startElement( "", name, name, attrs);
} catch( SAXException ex) {
throw new RuntimeException( ex.toString());
}
| private final java.lang.String | getLabel(oracle.toplink.libraries.asm.Label label)
String name = (String) labelNames.get( label);
if( name==null) {
name = Integer.toString( labelNames.size());
labelNames.put( label, name);
}
return name;
| public final void | visitAttribute(oracle.toplink.libraries.asm.Attribute attr)
// TODO Auto-generated SAXCodeAdapter.visitAttribute
| public final void | visitFieldInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String desc)
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute( "", "owner", "owner", "", owner);
attrs.addAttribute( "", "name", "name", "", name);
attrs.addAttribute( "", "desc", "desc", "", desc);
addElement( PrintCodeVisitor.OPCODES[ opcode], attrs);
| public final void | visitIincInsn(int var, int increment)
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute( "", "var", "var", "", Integer.toString( var));
attrs.addAttribute( "", "inc", "inc", "", Integer.toString( increment));
addElement( PrintCodeVisitor.OPCODES[ Constants.IINC], attrs);
| public final void | visitInsn(int opcode)
addElement( PrintCodeVisitor.OPCODES[ opcode], new AttributesImpl());
| public final void | visitIntInsn(int opcode, int operand)
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute( "", "value", "value", "", Integer.toString( operand));
addElement( PrintCodeVisitor.OPCODES[ opcode], attrs);
| public final void | visitJumpInsn(int opcode, oracle.toplink.libraries.asm.Label label)
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute( "", "label", "label", "", getLabel( label));
addElement( PrintCodeVisitor.OPCODES[ opcode], attrs);
| public final void | visitLabel(oracle.toplink.libraries.asm.Label label)
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute( "", "name", "name", "", getLabel( label));
addElement( "Label", attrs);
| public final void | visitLdcInsn(java.lang.Object cst)
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute( "", "cst", "cst", "", SAXClassAdapter.encode( cst.toString()));
attrs.addAttribute( "", "desc", "desc", "", Type.getDescriptor( cst.getClass()));
addElement( PrintCodeVisitor.OPCODES[ Constants.LDC], attrs);
| public final void | visitLineNumber(int line, oracle.toplink.libraries.asm.Label start)
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute( "", "line", "line", "", Integer.toString( line));
attrs.addAttribute( "", "start", "start", "", getLabel( start));
addElement( "LineNumber", attrs);
| public final void | visitLocalVariable(java.lang.String name, java.lang.String desc, oracle.toplink.libraries.asm.Label start, oracle.toplink.libraries.asm.Label end, int index)
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute( "", "name", "name", "", name);
attrs.addAttribute( "", "desc", "desc", "", desc);
attrs.addAttribute( "", "start", "start", "", getLabel( start));
attrs.addAttribute( "", "end", "end", "", getLabel( end));
attrs.addAttribute( "", "var", "var", "", Integer.toString( index));
addElement( "LocalVar", attrs);
| public final void | visitLookupSwitchInsn(oracle.toplink.libraries.asm.Label dflt, int[] keys, oracle.toplink.libraries.asm.Label[] labels)
AttributesImpl att = new AttributesImpl();
att.addAttribute( "", "dflt", "dflt", "", getLabel( dflt));
String o = PrintCodeVisitor.OPCODES[ Constants.LOOKUPSWITCH];
addStart( o, att);
for( int i = 0; i < labels.length; i++) {
AttributesImpl att2 = new AttributesImpl();
att2.addAttribute( "", "name", "name", "", getLabel( labels[ i]));
att2.addAttribute( "", "key", "key", "", Integer.toString( keys[ i]));
addElement( "label", att2);
}
addEnd( o);
| public final void | visitMaxs(int maxStack, int maxLocals)
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute( "", "maxStack", "maxStack", "", Integer.toString( maxStack));
attrs.addAttribute( "", "maxLocals", "maxLocals", "", Integer.toString( maxLocals));
addElement( "Max", attrs);
addEnd( "code");
addEnd( "method");
// TODO ensure it it is ok to close method element here
| public final void | visitMethodInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String desc)
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute( "", "owner", "owner", "", owner);
attrs.addAttribute( "", "name", "name", "", name);
attrs.addAttribute( "", "desc", "desc", "", desc);
addElement( PrintCodeVisitor.OPCODES[ opcode], attrs);
| public final void | visitMultiANewArrayInsn(java.lang.String desc, int dims)
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute( "", "desc", "desc", "", desc);
attrs.addAttribute( "", "dims", "dims", "", Integer.toString( dims));
addElement( PrintCodeVisitor.OPCODES[ Constants.MULTIANEWARRAY], attrs);
| public final void | visitTableSwitchInsn(int min, int max, oracle.toplink.libraries.asm.Label dflt, oracle.toplink.libraries.asm.Label[] labels)
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute( "", "min", "min", "", Integer.toString( min));
attrs.addAttribute( "", "max", "max", "", Integer.toString( max));
attrs.addAttribute( "", "dflt", "dflt", "", getLabel( dflt));
String o = PrintCodeVisitor.OPCODES[ Constants.TABLESWITCH];
addStart( o, attrs);
for( int i = 0; i < labels.length; i++) {
AttributesImpl att2 = new AttributesImpl();
att2.addAttribute( "", "name", "name", "", getLabel( labels[ i]));
addElement( "label", att2);
}
addEnd( o);
| public final void | visitTryCatchBlock(oracle.toplink.libraries.asm.Label start, oracle.toplink.libraries.asm.Label end, oracle.toplink.libraries.asm.Label handler, java.lang.String type)
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute( "", "start", "start", "", getLabel( start));
attrs.addAttribute( "", "end", "end", "", getLabel( end));
attrs.addAttribute( "", "handler", "handler", "", getLabel( handler));
if( type!=null) attrs.addAttribute( "", "type", "type", "", type);
addElement( "TryCatch", attrs);
| public final void | visitTypeInsn(int opcode, java.lang.String desc)
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute( "", "desc", "desc", "", desc);
addElement( PrintCodeVisitor.OPCODES[ opcode], attrs);
| public final void | visitVarInsn(int opcode, int var)
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute( "", "var", "var", "", Integer.toString( var));
addElement( PrintCodeVisitor.OPCODES[ opcode], attrs);
|
|