📄 asmcontenthandler.java
字号:
OpcodeGroup.INSN_JUMP ) );
ASMContentHandler.OPCODES.put( "GOTO",
new Opcode( Opcodes.GOTO,
OpcodeGroup.INSN_JUMP ) );
ASMContentHandler.OPCODES.put( "JSR",
new Opcode( Opcodes.JSR,
OpcodeGroup.INSN_JUMP ) );
ASMContentHandler.OPCODES.put( "RET",
new Opcode( Opcodes.RET,
OpcodeGroup.INSN_VAR ) );
// OPCODES.put( "TABLESWITCH", new Opcode( TABLESWITCH,
// "visiTableSwitchInsn"));
// OPCODES.put( "LOOKUPSWITCH", new Opcode( LOOKUPSWITCH,
// "visitLookupSwitch"));
ASMContentHandler.OPCODES.put( "IRETURN",
new Opcode( Opcodes.IRETURN,
OpcodeGroup.INSN ) );
ASMContentHandler.OPCODES.put( "LRETURN",
new Opcode( Opcodes.LRETURN,
OpcodeGroup.INSN ) );
ASMContentHandler.OPCODES.put( "FRETURN",
new Opcode( Opcodes.FRETURN,
OpcodeGroup.INSN ) );
ASMContentHandler.OPCODES.put( "DRETURN",
new Opcode( Opcodes.DRETURN,
OpcodeGroup.INSN ) );
ASMContentHandler.OPCODES.put( "ARETURN",
new Opcode( Opcodes.ARETURN,
OpcodeGroup.INSN ) );
ASMContentHandler.OPCODES.put( "RETURN",
new Opcode( Opcodes.RETURN,
OpcodeGroup.INSN ) );
ASMContentHandler.OPCODES.put( "GETSTATIC",
new Opcode( Opcodes.GETSTATIC,
OpcodeGroup.INSN_FIELD ) );
ASMContentHandler.OPCODES.put( "PUTSTATIC",
new Opcode( Opcodes.PUTSTATIC,
OpcodeGroup.INSN_FIELD ) );
ASMContentHandler.OPCODES.put( "GETFIELD",
new Opcode( Opcodes.GETFIELD,
OpcodeGroup.INSN_FIELD ) );
ASMContentHandler.OPCODES.put( "PUTFIELD",
new Opcode( Opcodes.PUTFIELD,
OpcodeGroup.INSN_FIELD ) );
ASMContentHandler.OPCODES.put( "INVOKEVIRTUAL",
new Opcode( Opcodes.INVOKEVIRTUAL,
OpcodeGroup.INSN_METHOD ) );
ASMContentHandler.OPCODES.put( "INVOKESPECIAL",
new Opcode( Opcodes.INVOKESPECIAL,
OpcodeGroup.INSN_METHOD ) );
ASMContentHandler.OPCODES.put( "INVOKESTATIC",
new Opcode( Opcodes.INVOKESTATIC,
OpcodeGroup.INSN_METHOD ) );
ASMContentHandler.OPCODES.put( "INVOKEINTERFACE",
new Opcode( Opcodes.INVOKEINTERFACE,
OpcodeGroup.INSN_METHOD ) );
ASMContentHandler.OPCODES.put( "NEW",
new Opcode( Opcodes.NEW,
OpcodeGroup.INSN_TYPE ) );
ASMContentHandler.OPCODES.put( "NEWARRAY",
new Opcode( Opcodes.NEWARRAY,
OpcodeGroup.INSN_INT ) );
ASMContentHandler.OPCODES.put( "ANEWARRAY",
new Opcode( Opcodes.ANEWARRAY,
OpcodeGroup.INSN_TYPE ) );
ASMContentHandler.OPCODES.put( "ARRAYLENGTH",
new Opcode( Opcodes.ARRAYLENGTH,
OpcodeGroup.INSN ) );
ASMContentHandler.OPCODES.put( "ATHROW",
new Opcode( Opcodes.ATHROW,
OpcodeGroup.INSN ) );
ASMContentHandler.OPCODES.put( "CHECKCAST",
new Opcode( Opcodes.CHECKCAST,
OpcodeGroup.INSN_TYPE ) );
ASMContentHandler.OPCODES.put( "INSTANCEOF",
new Opcode( Opcodes.INSTANCEOF,
OpcodeGroup.INSN_TYPE ) );
ASMContentHandler.OPCODES.put( "MONITORENTER",
new Opcode( Opcodes.MONITORENTER,
OpcodeGroup.INSN ) );
ASMContentHandler.OPCODES.put( "MONITOREXIT",
new Opcode( Opcodes.MONITOREXIT,
OpcodeGroup.INSN ) );
ASMContentHandler.OPCODES.put( "MULTIANEWARRAY",
new Opcode( Opcodes.MULTIANEWARRAY,
OpcodeGroup.INSN_MULTIANEWARRAY ) );
ASMContentHandler.OPCODES.put( "IFNULL",
new Opcode( Opcodes.IFNULL,
OpcodeGroup.INSN_JUMP ) );
ASMContentHandler.OPCODES.put( "IFNONNULL",
new Opcode( Opcodes.IFNONNULL,
OpcodeGroup.INSN_JUMP ) );
}
/**
* Constructs a new {@link ASMContentHandler ASMContentHandler} object.
*
* @param os output stream to write generated class.
* @param computeMax <tt>true</tt> if the maximum stack size and the
* maximum number of local variables must be automatically computed.
* This value is passed to {@link ClassWriter ClassWriter} instance.
*/
public ASMContentHandler(final OutputStream os,
final boolean computeMax) {
this.os = os;
this.computeMax = computeMax;
}
/**
* Returns the bytecode of the class that was build with underneath class
* writer.
*
* @return the bytecode of the class that was build with underneath class
* writer or null if there are no classwriter created.
*/
public byte[] toByteArray() {
return this.cw == null ? null : this.cw.toByteArray();
}
/**
* Process notification of the start of an XML element being reached.
*
* @param ns - The Namespace URI, or the empty string if the element has no
* Namespace URI or if Namespace processing is not being performed.
* @param localName - The local name (without prefix), or the empty string
* if Namespace processing is not being performed.
* @param qName - The qualified name (with prefix), or the empty string if
* qualified names are not available.
* @param list - The attributes attached to the element. If there are no
* attributes, it shall be an empty Attributes object.
* @exception SAXException if a parsing error is to be reported
*/
public final void startElement(final String ns,
final String localName,
final String qName,
final Attributes list) throws SAXException {
// the actual element name is either in localName or qName, depending
// on whether the parser is namespace aware
String name = localName;
if ( name == null || name.length() < 1 ) {
name = qName;
}
// Compute the current matching rule
final StringBuffer sb = new StringBuffer( this.match );
if ( this.match.length() > 0 ) {
sb.append( '/' );
}
sb.append( name );
this.match = sb.toString();
// Fire "begin" events for all relevant rules
final Rule r = (Rule) this.RULES.match( this.match );
if ( r != null ) {
r.begin( name,
list );
}
}
/**
* Process notification of the end of an XML element being reached.
*
* @param ns - The Namespace URI, or the empty string if the element has no
* Namespace URI or if Namespace processing is not being performed.
* @param localName - The local name (without prefix), or the empty string
* if Namespace processing is not being performed.
* @param qName - The qualified XML 1.0 name (with prefix), or the empty
* string if qualified names are not available.
*
* @exception SAXException if a parsing error is to be reported
*/
public final void endElement(final String ns,
final String localName,
final String qName) throws SAXException {
// the actual element name is either in localName or qName, depending
// on whether the parser is namespace aware
String name = localName;
if ( name == null || name.length() < 1 ) {
name = qName;
}
// Fire "end" events for all relevant rules in reverse order
final Rule r = (Rule) this.RULES.match( this.match );
if ( r != null ) {
r.end( name );
}
// Recover the previous match expression
final int slash = this.match.lastIndexOf( '/' );
if ( slash >= 0 ) {
this.match = this.match.substring( 0,
slash );
} else {
this.match = "";
}
}
/**
* Process notification of the end of a document and write generated
* bytecode into output stream.
*
* @exception SAXException if parsing or writing error is to be reported.
*/
public final void endDocument() throws SAXException {
try {
this.os.write( this.cw.toByteArray() );
} catch ( final IOException ex ) {
throw new SAXException( ex.toString(),
ex );
}
}
/**
* Return the top object on the stack without removing it. If there are no
* objects on the stack, return <code>null</code>.
*
* @return the top object on the stack without removing it.
*/
final Object peek() {
return this.stack.size() == 0 ? null : this.stack.get( this.stack.size() - 1 );
}
/**
* Return the n'th object down the stack, where 0 is the top element and
* [getCount()-1] is the bottom element. If the specified index is out of
* range, return <code>null</code>.
*
* @param n Index of the desired element, where 0 is the top of the stack, 1
* is the next element down, and so on.
* @return the n'th object down the stack.
*/
final Object peek(final int n) {
return this.stack.size() < (n + 1) ? null : this.stack.get( n );
}
/**
* Pop the top object off of the stack, and return it. If there are no
* objects on the stack, return <code>null</code>.
*
* @return the top object off of the stack.
*/
final Object pop() {
return this.stack.size() == 0 ? null : this.stack.remove( this.stack.size() - 1 );
}
/**
* Push a new object onto the top of the object stack.
*
* @param object The new object
*/
final void push(final Object object) {
this.stack.add( object );
}
private static final class RuleSet {
private final Map rules = new HashMap();
private final List lpatterns = new ArrayList();
private final List rpatterns = new ArrayList();
public void add(final String path,
final Object rule) {
String pattern = path;
if ( path.startsWith( "*/" ) ) {
pattern = path.substring( 1 );
this.lpatterns.add( pattern );
} else if ( path.endsWith( "/*" ) ) {
pattern = path.substring( 0,
path.length() - 1 );
this.rpatterns.add( pattern );
}
this.rules.put( pattern,
rule );
}
public Object match(final String path) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -