📄 asmcontenthandler.java
字号:
public final void end(final String element) {
final Map vals = (Map) pop();
final int version = ((Integer) vals.get( "version" )).intValue();
final int access = getAccess( (String) vals.get( "access" ) );
final String name = (String) vals.get( "name" );
final String signature = (String) vals.get( "signature" );
final String parent = (String) vals.get( "parent" );
final List infs = (List) vals.get( "interfaces" );
final String[] interfaces = (String[]) infs.toArray( new String[infs.size()] );
ASMContentHandler.this.cw.visit( version,
access,
name,
signature,
parent,
interfaces );
push( ASMContentHandler.this.cw );
}
}
/**
* OuterClassRule
*/
private final class OuterClassRule extends Rule {
public final void begin(final String element,
final Attributes attrs) {
final String owner = attrs.getValue( "owner" );
final String name = attrs.getValue( "name" );
final String desc = attrs.getValue( "desc" );
ASMContentHandler.this.cw.visitOuterClass( owner,
name,
desc );
}
}
/**
* InnerClassRule
*/
private final class InnerClassRule extends Rule {
public final void begin(final String element,
final Attributes attrs) {
final int access = getAccess( attrs.getValue( "access" ) );
final String name = attrs.getValue( "name" );
final String outerName = attrs.getValue( "outerName" );
final String innerName = attrs.getValue( "innerName" );
ASMContentHandler.this.cw.visitInnerClass( name,
outerName,
innerName,
access );
}
}
/**
* FieldRule
*/
private final class FieldRule extends Rule {
public final void begin(final String element,
final Attributes attrs) {
final int access = getAccess( attrs.getValue( "access" ) );
final String name = attrs.getValue( "name" );
final String signature = attrs.getValue( "signature" );
final String desc = attrs.getValue( "desc" );
final Object value = getValue( desc,
attrs.getValue( "value" ) );
push( ASMContentHandler.this.cw.visitField( access,
name,
desc,
signature,
value ) );
}
public void end(final String name) {
((FieldVisitor) pop()).visitEnd();
}
}
/**
* MethodRule
*/
private final class MethodRule extends Rule {
public final void begin(final String name,
final Attributes attrs) {
ASMContentHandler.this.labels = new HashMap();
final Map vals = new HashMap();
vals.put( "access",
attrs.getValue( "access" ) );
vals.put( "name",
attrs.getValue( "name" ) );
vals.put( "desc",
attrs.getValue( "desc" ) );
vals.put( "signature",
attrs.getValue( "signature" ) );
vals.put( "exceptions",
new ArrayList() );
push( vals );
// values will be extracted in ExceptionsRule.end();
}
public final void end(final String name) {
((MethodVisitor) pop()).visitEnd();
ASMContentHandler.this.labels = null;
}
}
/**
* ExceptionRule
*/
private final class ExceptionRule extends Rule {
public final void begin(final String name,
final Attributes attrs) {
((List) ((Map) peek()).get( "exceptions" )).add( attrs.getValue( "name" ) );
}
}
/**
* ExceptionsRule
*/
private final class ExceptionsRule extends Rule {
public final void end(final String element) {
final Map vals = (Map) pop();
final int access = getAccess( (String) vals.get( "access" ) );
final String name = (String) vals.get( "name" );
final String desc = (String) vals.get( "desc" );
final String signature = (String) vals.get( "signature" );
final List excs = (List) vals.get( "exceptions" );
final String[] exceptions = (String[]) excs.toArray( new String[excs.size()] );
push( ASMContentHandler.this.cw.visitMethod( access,
name,
desc,
signature,
exceptions ) );
}
}
/**
* TableSwitchRule
*/
private class TableSwitchRule extends Rule {
public final void begin(final String name,
final Attributes attrs) {
final Map vals = new HashMap();
vals.put( "min",
attrs.getValue( "min" ) );
vals.put( "max",
attrs.getValue( "max" ) );
vals.put( "dflt",
attrs.getValue( "dflt" ) );
vals.put( "labels",
new ArrayList() );
push( vals );
}
public final void end(final String name) {
final Map vals = (Map) pop();
final int min = Integer.parseInt( (String) vals.get( "min" ) );
final int max = Integer.parseInt( (String) vals.get( "max" ) );
final Label dflt = getLabel( vals.get( "dflt" ) );
final List lbls = (List) vals.get( "labels" );
final Label[] labels = (Label[]) lbls.toArray( new Label[lbls.size()] );
getCodeVisitor().visitTableSwitchInsn( min,
max,
dflt,
labels );
}
}
/**
* TableSwitchLabelRule
*/
private final class TableSwitchLabelRule extends Rule {
public final void begin(final String name,
final Attributes attrs) {
((List) ((Map) peek()).get( "labels" )).add( getLabel( attrs.getValue( "name" ) ) );
}
}
/**
* LookupSwitchRule
*/
private final class LookupSwitchRule extends Rule {
public final void begin(final String name,
final Attributes attrs) {
final Map vals = new HashMap();
vals.put( "dflt",
attrs.getValue( "dflt" ) );
vals.put( "labels",
new ArrayList() );
vals.put( "keys",
new ArrayList() );
push( vals );
}
public final void end(final String name) {
final Map vals = (Map) pop();
final Label dflt = getLabel( vals.get( "dflt" ) );
final List keyList = (List) vals.get( "keys" );
final List lbls = (List) vals.get( "labels" );
final Label[] labels = (Label[]) lbls.toArray( new Label[lbls.size()] );
final int[] keys = new int[keyList.size()];
for ( int i = 0; i < keys.length; i++ ) {
keys[i] = Integer.parseInt( (String) keyList.get( i ) );
}
getCodeVisitor().visitLookupSwitchInsn( dflt,
keys,
labels );
}
}
/**
* LookupSwitchLabelRule
*/
private final class LookupSwitchLabelRule extends Rule {
public final void begin(final String name,
final Attributes attrs) {
final Map vals = (Map) peek();
((List) vals.get( "labels" )).add( getLabel( attrs.getValue( "name" ) ) );
((List) vals.get( "keys" )).add( attrs.getValue( "key" ) );
}
}
/**
* LabelRule
*/
private final class LabelRule extends Rule {
public final void begin(final String name,
final Attributes attrs) {
getCodeVisitor().visitLabel( getLabel( attrs.getValue( "name" ) ) );
}
}
/**
* TryCatchRule
*/
private final class TryCatchRule extends Rule {
public final void begin(final String name,
final Attributes attrs) {
final Label start = getLabel( attrs.getValue( "start" ) );
final Label end = getLabel( attrs.getValue( "end" ) );
final Label handler = getLabel( attrs.getValue( "handler" ) );
final String type = attrs.getValue( "type" );
getCodeVisitor().visitTryCatchBlock( start,
end,
handler,
type );
}
}
/**
* LineNumberRule
*/
private final class LineNumb
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -