📄 checkmethodadapter.java
字号:
return new CheckAnnotationAdapter( this.mv.visitParameterAnnotation( parameter,
desc,
visible ) );
}
public void visitAttribute(final Attribute attr) {
checkEndMethod();
if ( attr == null ) {
throw new IllegalArgumentException( "Invalid attribute (must not be null)" );
}
this.mv.visitAttribute( attr );
}
public void visitCode() {
this.startCode = true;
this.mv.visitCode();
}
public void visitInsn(final int opcode) {
checkStartCode();
checkEndCode();
checkOpcode( opcode,
0 );
this.mv.visitInsn( opcode );
}
public void visitIntInsn(final int opcode,
final int operand) {
checkStartCode();
checkEndCode();
checkOpcode( opcode,
1 );
switch ( opcode ) {
case Opcodes.BIPUSH :
checkSignedByte( operand,
"Invalid operand" );
break;
case Opcodes.SIPUSH :
checkSignedShort( operand,
"Invalid operand" );
break;
// case Constants.NEWARRAY:
default :
if ( operand < Opcodes.T_BOOLEAN || operand > Opcodes.T_LONG ) {
throw new IllegalArgumentException( "Invalid operand (must be an array type code T_...): " + operand );
}
}
this.mv.visitIntInsn( opcode,
operand );
}
public void visitVarInsn(final int opcode,
final int var) {
checkStartCode();
checkEndCode();
checkOpcode( opcode,
2 );
checkUnsignedShort( var,
"Invalid variable index" );
this.mv.visitVarInsn( opcode,
var );
}
public void visitTypeInsn(final int opcode,
final String desc) {
checkStartCode();
checkEndCode();
checkOpcode( opcode,
3 );
if ( desc != null && desc.length() > 0 && desc.charAt( 0 ) == '[' ) {
checkDesc( desc,
false );
} else {
checkInternalName( desc,
"type" );
}
if ( opcode == Opcodes.NEW && desc.charAt( 0 ) == '[' ) {
throw new IllegalArgumentException( "NEW cannot be used to create arrays: " + desc );
}
this.mv.visitTypeInsn( opcode,
desc );
}
public void visitFieldInsn(final int opcode,
final String owner,
final String name,
final String desc) {
checkStartCode();
checkEndCode();
checkOpcode( opcode,
4 );
checkInternalName( owner,
"owner" );
checkIdentifier( name,
"name" );
checkDesc( desc,
false );
this.mv.visitFieldInsn( opcode,
owner,
name,
desc );
}
public void visitMethodInsn(final int opcode,
final String owner,
final String name,
final String desc) {
checkStartCode();
checkEndCode();
checkOpcode( opcode,
5 );
checkMethodIdentifier( name,
"name" );
if ( !name.equals( "clone" ) ) {
// In JDK1.5, clone method can be called on array class descriptors
checkInternalName( owner,
"owner" );
}
checkMethodDesc( desc );
this.mv.visitMethodInsn( opcode,
owner,
name,
desc );
}
public void visitJumpInsn(final int opcode,
final Label label) {
checkStartCode();
checkEndCode();
checkOpcode( opcode,
6 );
checkLabel( label,
false,
"label" );
this.mv.visitJumpInsn( opcode,
label );
}
public void visitLabel(final Label label) {
checkStartCode();
checkEndCode();
checkLabel( label,
false,
"label" );
if ( this.labels.get( label ) != null ) {
throw new IllegalArgumentException( "Already visited label" );
} else {
this.labels.put( label,
new Integer( this.labels.size() ) );
}
this.mv.visitLabel( label );
}
public void visitLdcInsn(final Object cst) {
checkStartCode();
checkEndCode();
if ( !(cst instanceof Type) ) {
checkConstant( cst );
}
this.mv.visitLdcInsn( cst );
}
public void visitIincInsn(final int var,
final int increment) {
checkStartCode();
checkEndCode();
checkUnsignedShort( var,
"Invalid variable index" );
checkSignedShort( increment,
"Invalid increment" );
this.mv.visitIincInsn( var,
increment );
}
public void visitTableSwitchInsn(final int min,
final int max,
final Label dflt,
final Label labels[]) {
checkStartCode();
checkEndCode();
if ( max < min ) {
throw new IllegalArgumentException( "Max = " + max + " must be greater than or equal to min = " + min );
}
checkLabel( dflt,
false,
"default label" );
if ( labels == null || labels.length != max - min + 1 ) {
throw new IllegalArgumentException( "There must be max - min + 1 labels" );
}
for ( int i = 0; i < labels.length; ++i ) {
checkLabel( labels[i],
false,
"label at index " + i );
}
this.mv.visitTableSwitchInsn( min,
max,
dflt,
labels );
}
public void visitLookupSwitchInsn(final Label dflt,
final int keys[],
final Label labels[]) {
checkEndCode();
checkStartCode();
checkLabel( dflt,
false,
"default label" );
if ( keys == null || labels == null || keys.length != labels.length ) {
throw new IllegalArgumentException( "There must be the same number of keys and labels" );
}
for ( int i = 0; i < labels.length; ++i ) {
checkLabel( labels[i],
false,
"label at index " + i );
}
this.mv.visitLookupSwitchInsn( dflt,
keys,
labels );
}
public void visitMultiANewArrayInsn(final String desc,
final int dims) {
checkStartCode();
checkEndCode();
checkDesc( desc,
false );
if ( desc.charAt( 0 ) != '[' ) {
throw new IllegalArgumentException( "Invalid descriptor (must be an array type descriptor): " + desc );
}
if ( dims < 1 ) {
throw new IllegalArgumentException( "Invalid dimensions (must be greater than 0): " + dims );
}
if ( dims > desc.lastIndexOf( '[' ) + 1 ) {
throw new IllegalArgumentException( "Invalid dimensions (must not be greater than dims(desc)): " + dims );
}
this.mv.visitMultiANewArrayInsn( desc,
dims );
}
public void visitTryCatchBlock(final Label start,
final Label end,
final Label handler,
final String type) {
checkStartCode();
checkEndCode();
if ( type != null ) {
checkInternalName( type,
"type" );
}
this.mv.visitTryCatchBlock( start,
end,
handler,
type );
}
public void visitLocalVariable(final String name,
final String desc,
final String signature,
final Label start,
final Label end,
final int index) {
checkStartCode();
checkEndCode();
checkIdentifier( name,
"name" );
checkDesc( desc,
false );
checkLabel( start,
true,
"start label" );
checkLabel( end,
true,
"end label" );
checkUnsignedShort( index,
"Invalid variable index" );
final int s = ((Integer) this.labels.get( start )).intValue();
final int e = ((Integer) this.labels.get( end )).intValue();
if ( e < s ) {
throw new IllegalArgumentException( "Invalid start and end labels (end must be greater than start)" );
}
this.mv.visitLocalVariable( name,
desc,
signature,
start,
end,
index );
}
public void visitLineNumber(final int line,
final Label start) {
checkStartCode();
checkEndCode();
checkUnsignedShort( line,
"Invalid line number" );
checkLabel( start,
true,
"start label" );
this.mv.visitLineNumber( line,
start );
}
public void visitMaxs(final int maxStack,
final int maxLocals) {
checkStartCode();
checkEndCode();
this.endCode = true;
checkUnsignedShort( maxStack,
"Invalid max stack" );
checkUnsignedShort( maxLocals,
"Invalid max locals" );
this.mv.visitMaxs( maxStack,
maxLocals );
}
public void visitEnd() {
checkEndMethod();
this.endMethod = true;
this.mv.visitEnd();
}
// -------------------------------------------------------------------------
/**
* Checks that the visitCode method has been called.
*/
void checkStartCode() {
if ( !this.startCode ) {
throw new IllegalStateException( "Cannot visit instructions before visitCode has been called." );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -