PageRenderTime 67ms CodeModel.GetById 64ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/bsh/commands/javap.bsh

#
Unknown | 62 lines | 54 code | 8 blank | 0 comment | 0 complexity | cb8ec40d069d7684cfb4873148f71360 MD5 | raw file
 1/**
 2	Print the public fields and methods of the specified class (output similar 
 3	to the JDK javap command).
 4	<p/>
 5	If the argument is a string it is considered to be a class name.  If the
 6	argument is an object, the class of the object is used.  If the arg is a
 7	class, the class is used.  If the argument is a class identifier, the class
 8	identified by the class identifier will be used. e.g.  If the argument is
 9	the empty string an error will be printed.
10	<p/>
11	<pre>
12	// equivalent
13	javap( java.util.Date ); // class identifier
14	javap( java.util.Date.class ); // class
15	javap( "java.util.Date" ); // String name of class
16	javap( new java.util.Date() ); // instance of class
17	</pre>
18
19	@method void javap( String | Object | Class | ClassIdentifier )
20*/
21
22bsh.help.javap= "usage: javap( value )";
23
24import bsh.ClassIdentifier;
25import java.lang.reflect.Modifier;
26
27javap( Object o ) 
28{
29	Class clas;
30	if ( o instanceof ClassIdentifier )
31		clas = this.caller.namespace.identifierToClass(o);
32	else if ( o instanceof String )
33	{
34		if ( o.length() < 1 ) {
35			error("javap: Empty class name.");
36			return;
37		}
38		clas = this.caller.namespace.getClass((String)o);
39	} else if ( o instanceof Class )
40		clas = o;
41	else 
42		clas = o.getClass();
43	
44	print( "Class "+clas+" extends " +clas.getSuperclass() );
45
46	this.methods=clas.getDeclaredMethods();
47	//print("------------- Methods ----------------");
48	for(int i=0; i<methods.length; i++) {
49		this.m = methods[i];
50		if ( Modifier.isPublic( m.getModifiers() ) )
51			print( m );
52	}
53
54	//print("------------- Fields ----------------");
55	this.fields=clas.getDeclaredFields();
56	for(int i=0; i<fields.length; i++) {
57		this.f = fields[i];
58		if ( Modifier.isPublic( f.getModifiers() ) )
59			print( f );
60	}
61}
62