Java class browser

xiaoxiao2021-03-06  44

Package treeroot.reflect;

import java.util.List; public interface Node {int CLASS = 0x10000; int INTERFACE = 0x01000; int CONSTRUCTOR = 0x00100; int METHOD = 0x00010; int FIELD = 0x00001; void setChilds (List childs); boolean hasChild (); List getChilds (); String getName (); string getdetail (); int gettype (); // in order to sort int getorder ();} package treueot.reflect;

Import treeroot.reflect.Node; import java.util.list; import java.lang.reflect.Method;

Public class methodnode implements node {private int order; private method m) {this (m, 0);} public methodnode (Method M, int order) {this.m = m; this.order = Order }

/ ** * Method setchilds * * * @Param parm1 * * / public void setchilds (List parm1) {throw new unsupportedOperationException ("MothodNode Has No Child!"); // Todo: add your code heren}

/ ** * method Haschild * * * @Return * * / public boolean haschild () {return false; // Todo: add your code here}

/ ** * method getchilds * * * @Return * * / public list getchilds () {throw new unsupportedOperationException ("MothodNode Has No Child!"); // Todo: add your code here}

/ ** * method getname * * * @Return * * / public string getName () {return m.getname () helper.getParams (getDetail ()); // Todo: add your code here}

/ ** * Method getDetail * * * @return * * / public string getdetail () {return m.toString (); // Todo: add your code here}

/ ** * Method gettype * * * @return * * / public int gettype () {Return Method; // Todo: add your code here}

/ ** * method getorder * * * @Return * * / public int getorder () {returno {returno: add your code here} public string toString ()} packet. import treeroot.reflect.Node; import java.util.List; import java.lang.reflect *;. public class InterfaceNode implements Node {private class c; private int order; private List childs; public InterfaceNode (class c) {this ( C, 0);} public interfaceEnode (Class C, int Order) {if (! C.ISinterface ()) {throw new runtimeException ("Interfabenode Must Accept A Interface!");} this.c = C; this.order = Order;} / ** * @Param parm1 * * / public void setchilds (list parm1) {this.childs = parm1; // Todo: add your code here}

/ ** * method Haschild * * * @return * * / public boolean Haschild () {return (childs! = Null) && (childs.size ()> 0); // Todo: add your code here}

/ ** * Method getChilds * * * @return * * / public list getchilds () {return childs; // Todo: add your code here}

/ ** * method getname * * * @return * * / public string getName () {return c.getname (); // Todo: add your code heren

/ ** * method toString * * * @Return * * / public string toString () {return " getname () " "; // Todo: add Your code here}

/ ** * Method getDetail * * * @Return * * / public string getdetail () {stringbuffer sb = new stringbuffer (C.GETMODIFIERS ()); sb.append (c.getname ()); Class [] INTERS = C.GETINTERFACES (); IF (IF ("IMplements"); for (INT i = 0; I

Import treeroot.reflect.Node; import java.util.list; import java.lang.reflect.Modifier; import java.lang.reflect.field;

public class FieldNode implements Node {private int order; private int mode; private Field field; public FieldNode (Field field) {this (field, 0);} public FieldNode (Field field, int order) {this.field = field; this .order = order;} / ** * Method setChilds * * * @param parm1 * * / public void setChilds (List parm1) {throw new UnsupportedOperationException ( "Field can hava Child Nodes!"); // TODO: Add your code Here}

/ ** * method Haschild * * * @Return * * / public boolean haschild () {return false; // Todo: add your code here}

. / ** * Method getChilds * * * @return * * / public List getChilds () {// you should call the hasChild () to test throw new UnsupportedOperationException ( "Field can hava Child Nodes!"); // TODO: Add your code here}

/ ** * method getname * * * @Return * * / public string getName () {return field.getname (); // Todo: add your code here}

/ ** * method getDetail * * * @return * * / public string getdetail () {returni: add your code here} / ** * method gettype * * * @return * * / Public int gettype () {return field;} public integral;} public string toString ()}}}}}}.

Import treeroot.reflect.Node; import java.util.list; import java.lang.reflect.constructor; import java.lang.reflect.Modifier;

public class ConstructorNode implements Node {private Constructor con; private int order; public ConstructorNode (Constructor con) {this (con, 0);} public ConstructorNode (Constructor con, int order) {this.con = con; this.order = order ;} / ** * Method setChilds * * * @param parm1 * * / public void setChilds (List parm1) {throw new UnsupportedOperationException ( "ConstructorNode has no child!"); // TODO: Add your code here}

/ ** * method Haschild * * * @Return * * / public boolean haschild () {return false; // Todo: add your code here}

/ ** * method getchilds * * * @return * * / public list getchilds () {throw new unsupportedOperationException ("constructornode has no child!); // Todo: add your code here}

/ ** * method getname * * * @Return * * / public string getName () {return con.getname () helper.getParams (getdetail ()); // Todo: add your code here}

/ ** * Method getDetail * * * @return * * / public string getdetail () {returncon.tostring (); // Todo: add your code here}

/ ** * method gettype * * * @Return * * / public int gettype () {return constructor; // Todo: add your code here}

/ ** * method getorder * * * @Return * * / public int getorder () {returno {returno: add your code here} public string toString ()} packet. import treeroot.reflect.Node; import java.util.List; import java.lang.reflect *;. public class ClassNode implements Node {private class c; private int order; private List childs; public ClassNode (class c) {this ( C, 0);} public classnode (class c, int order) {if (c.isinterface () || c.isArray () || c.isprimitive ()) {throw new runtimeException ("ClassNode Must Accept A Class! ");} This.c = C; this.order = order;} / ** * method setchilds * * * @Param parm1 * * / public void setchilds (list parm1) {this.childs = parm1; // Todo: Add your code here}

/ ** * method Haschild * * * @return * * / public boolean Haschild () {return (childs! = Null) && (childs.size ()> 0); // Todo: add your code here}

/ ** * Method getChilds * * * @return * * / public list getchilds () {return childs; // Todo: add your code here}

/ ** * method getname * * * @return * * / public string getName () {return c.getname (); // Todo: add your code heren

/ ** * method toString * * * @Return * * / public string toString () {return " " getName () " "; // Todo: add Your code here}

/ ** * Method getDetail * * * @return * * / public string getdetail () {stringbuffer sb = new stringbuffer (c. getModifiers ())); sb.append (""); sb.append ( C.GETNAME ()); class superclass = c.getsuperclass (); if (superclass! = null) {sb.append ("extends"); sb.append (superclass.getname ());} class [] inters = C.GetInterfaces (); if (INTERS.LENGTH> 0) {sb.Append ("IMplements"); for (int i = 0; i

Class helper {static string getParams (String s) {Return S.Substring (S.Indexof ('), sindexof (') ') 1);}} package treeroot.reflect;

Import java.util. *; import java.lang.reflect. *; public class classmeta {public static node getClassTree (Class C) {// node root; if (c.isinterface ()) {root = new interface ()) {root = new interface ()) {root = new interfabenode (c) } Else {root = new classnode (c);} list childs = new arraylist (); // add super class as first node, if the class if object.class, break review. // Only Class Has The Superclass.

Class superClass = c.getSuperclass (); if (superClass = null!) Childs.add (getClassTree (superClass)); // add the inteferaces // Class or Interface must have the Interfaces Class [] inters = c.getInterfaces () For (int i = 0; i

Import javax.swing.tree.defaultmutabletreenode; import javax.swing.tree.defaulttreemodel; import javax.swing.jscrollpane;

public class ClassViewer extends JPanel {JTree tree; DefaultTreeModel model; JPanel detail = new JPanel (); JLabel lbl = new JLabel ( "the Detail Message"); private DefaultMutableTreeNode getRoot (Node node) {DefaultMutableTreeNode root = new DefaultMutableTreeNode (node); IF (node.haschild ()) {list childs = node.getchilds (); for (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-75448.html

New Post(0)