📄 traceclassvisitor.java
字号:
// if enclosing name is null, so why should we show this info?
if ( name != null ) {
this.buf.append( ' ' ).append( name ).append( ' ' );
} else {
this.buf.append( ' ' );
}
appendDescriptor( TraceAbstractVisitor.METHOD_DESCRIPTOR,
desc );
this.buf.append( '\n' );
this.text.add( this.buf.toString() );
if ( this.cv != null ) {
this.cv.visitOuterClass( owner,
name,
desc );
}
}
public AnnotationVisitor visitAnnotation(final String desc,
final boolean visible) {
this.text.add( "\n" );
final AnnotationVisitor tav = super.visitAnnotation( desc,
visible );
if ( this.cv != null ) {
((TraceAnnotationVisitor) tav).av = this.cv.visitAnnotation( desc,
visible );
}
return tav;
}
public void visitAttribute(final Attribute attr) {
this.text.add( "\n" );
super.visitAttribute( attr );
if ( this.cv != null ) {
this.cv.visitAttribute( attr );
}
}
public void visitInnerClass(final String name,
final String outerName,
final String innerName,
final int access) {
this.buf.setLength( 0 );
this.buf.append( this.tab ).append( "// access flags " ).append( access & ~Opcodes.ACC_SUPER ).append( '\n' );
this.buf.append( this.tab );
appendAccess( access );
this.buf.append( "INNERCLASS " );
if ( (access & Opcodes.ACC_ENUM) != 0 ) {
this.buf.append( "enum " );
}
appendDescriptor( TraceAbstractVisitor.INTERNAL_NAME,
name );
this.buf.append( ' ' );
appendDescriptor( TraceAbstractVisitor.INTERNAL_NAME,
outerName );
this.buf.append( ' ' );
appendDescriptor( TraceAbstractVisitor.INTERNAL_NAME,
innerName );
this.buf.append( '\n' );
this.text.add( this.buf.toString() );
if ( this.cv != null ) {
this.cv.visitInnerClass( name,
outerName,
innerName,
access );
}
}
public FieldVisitor visitField(final int access,
final String name,
final String desc,
final String signature,
final Object value) {
this.buf.setLength( 0 );
this.buf.append( '\n' );
if ( (access & Opcodes.ACC_DEPRECATED) != 0 ) {
this.buf.append( this.tab ).append( "// DEPRECATED\n" );
}
this.buf.append( this.tab ).append( "// access flags " ).append( access ).append( '\n' );
if ( signature != null ) {
this.buf.append( this.tab );
appendDescriptor( TraceAbstractVisitor.FIELD_SIGNATURE,
signature );
final TraceSignatureVisitor sv = new TraceSignatureVisitor( 0 );
final SignatureReader r = new SignatureReader( signature );
r.acceptType( sv );
this.buf.append( this.tab ).append( "// declaration: " ).append( sv.getDeclaration() ).append( '\n' );
}
this.buf.append( this.tab );
appendAccess( access );
if ( (access & Opcodes.ACC_ENUM) != 0 ) {
this.buf.append( "enum " );
}
appendDescriptor( TraceAbstractVisitor.FIELD_DESCRIPTOR,
desc );
this.buf.append( ' ' ).append( name );
if ( value != null ) {
this.buf.append( " = " );
if ( value instanceof String ) {
this.buf.append( "\"" ).append( value ).append( "\"" );
} else {
this.buf.append( value );
}
}
this.buf.append( '\n' );
this.text.add( this.buf.toString() );
final TraceFieldVisitor tav = createTraceFieldVisitor();
this.text.add( tav.getText() );
if ( this.cv != null ) {
tav.fv = this.cv.visitField( access,
name,
desc,
signature,
value );
}
return tav;
}
public MethodVisitor visitMethod(final int access,
final String name,
final String desc,
final String signature,
final String[] exceptions) {
this.buf.setLength( 0 );
this.buf.append( '\n' );
if ( (access & Opcodes.ACC_DEPRECATED) != 0 ) {
this.buf.append( this.tab ).append( "// DEPRECATED\n" );
}
this.buf.append( this.tab ).append( "// access flags " ).append( access ).append( '\n' );
this.buf.append( this.tab );
appendDescriptor( TraceAbstractVisitor.METHOD_SIGNATURE,
signature );
if ( signature != null ) {
final TraceSignatureVisitor v = new TraceSignatureVisitor( 0 );
final SignatureReader r = new SignatureReader( signature );
r.accept( v );
final String genericDecl = v.getDeclaration();
final String genericReturn = v.getReturnType();
final String genericExceptions = v.getExceptions();
this.buf.append( this.tab ).append( "// declaration: " ).append( genericReturn ).append( ' ' ).append( name ).append( genericDecl );
if ( genericExceptions != null ) {
this.buf.append( " throws " ).append( genericExceptions );
}
this.buf.append( '\n' );
}
appendAccess( access );
if ( (access & Opcodes.ACC_NATIVE) != 0 ) {
this.buf.append( "native " );
}
if ( (access & Opcodes.ACC_VARARGS) != 0 ) {
this.buf.append( "varargs " );
}
if ( (access & Opcodes.ACC_BRIDGE) != 0 ) {
this.buf.append( "bridge " );
}
this.buf.append( name );
appendDescriptor( TraceAbstractVisitor.METHOD_DESCRIPTOR,
desc );
if ( exceptions != null && exceptions.length > 0 ) {
this.buf.append( " throws " );
for ( int i = 0; i < exceptions.length; ++i ) {
appendDescriptor( TraceAbstractVisitor.INTERNAL_NAME,
exceptions[i] );
this.buf.append( ' ' );
}
}
this.buf.append( '\n' );
this.text.add( this.buf.toString() );
final TraceMethodVisitor tcv = createTraceMethodVisitor();
this.text.add( tcv.getText() );
if ( this.cv != null ) {
tcv.mv = this.cv.visitMethod( access,
name,
desc,
signature,
exceptions );
}
return tcv;
}
public void visitEnd() {
this.text.add( "}\n" );
printList( this.pw,
this.text );
this.pw.flush();
if ( this.cv != null ) {
this.cv.visitEnd();
}
}
// ------------------------------------------------------------------------
// Utility methods
// ------------------------------------------------------------------------
protected TraceFieldVisitor createTraceFieldVisitor() {
return new TraceFieldVisitor();
}
protected TraceMethodVisitor createTraceMethodVisitor() {
return new TraceMethodVisitor();
}
/**
* Appends a string representation of the given access modifiers to {@link
* #buf buf}.
*
* @param access some access modifiers.
*/
private void appendAccess(final int access) {
if ( (access & Opcodes.ACC_PUBLIC) != 0 ) {
this.buf.append( "public " );
}
if ( (access & Opcodes.ACC_PRIVATE) != 0 ) {
this.buf.append( "private " );
}
if ( (access & Opcodes.ACC_PROTECTED) != 0 ) {
this.buf.append( "protected " );
}
if ( (access & Opcodes.ACC_FINAL) != 0 ) {
this.buf.append( "final " );
}
if ( (access & Opcodes.ACC_STATIC) != 0 ) {
this.buf.append( "static " );
}
if ( (access & Opcodes.ACC_SYNCHRONIZED) != 0 ) {
this.buf.append( "synchronized " );
}
if ( (access & Opcodes.ACC_VOLATILE) != 0 ) {
this.buf.append( "volatile " );
}
if ( (access & Opcodes.ACC_TRANSIENT) != 0 ) {
this.buf.append( "transient " );
}
// if ((access & Constants.ACC_NATIVE) != 0) {
// buf.append("native ");
// }
if ( (access & Opcodes.ACC_ABSTRACT) != 0 ) {
this.buf.append( "abstract " );
}
if ( (access & Opcodes.ACC_STRICT) != 0 ) {
this.buf.append( "strictfp " );
}
if ( (access & Opcodes.ACC_SYNTHETIC) != 0 ) {
this.buf.append( "synthetic " );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -