javamemberdepend.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 807 行 · 第 1/2 页

JAVA
807
字号
	/* Ignore array */	if (str.startsWith("["))	    return;	int index = str.indexOf('.');        if (index > 0)            System.out.println(str.substring(0, index) + ".class");        else            System.out.println(str + ".class");	Enumeration e = node.dependsOn();        while ( e.hasMoreElements() ){            DependenceArc a = (DependenceArc)(e.nextElement());            Object mn = a.to().name();            str = (String) mn.toString();	    if (str.startsWith("["))		continue;	    index = str.indexOf('.');	    if (index > 0)                System.out.println(str.substring(0, index) + ".class");	    else	        System.out.println(str + ".class");	}     }           private void showOne( String classname ){	MemberDependenceNode mdn;	ClassEntry c = stringToClass( classname.replace('.', '/') );	mdn = c.lookupMember( staticInitializerName+staticInitializerSig );	if (mdn != null)	    printDependences(mdn);		Enumeration members = c.members();        if ( members != null ){            while ( members.hasMoreElements() ){                mdn = (MemberDependenceNode)(members.nextElement() );		printDependences(mdn);	    }	}     }     private void showAll() {        analyzer.analyzeAllDependences();        Enumeration e = analyzer.allNodes();        int nClasses = 0;         while ( e.hasMoreElements()){            DependenceNode node = (DependenceNode)(e.nextElement());            printDependences( node );            nClasses++;        }        System.out.println("TOTAL OF "+nClasses+" CLASSES");     }     private void showClassList() {        analyzer.analyzeAllDependences();        Enumeration e = analyzer.allNodes();        while ( e.hasMoreElements()){            DependenceNode node = (DependenceNode)(e.nextElement());            printClassList( node );        }     }    private void showPath( String srcmembername, String destmembername ){	MemberDependenceNode src = stringToNode( srcmembername );	MemberDependenceNode dest = stringToNode( destmembername );	if ( src.state() != DependenceNode.ANALYZED ){	    System.err.println( srcmembername+" not part of graph");	    return;	}	if ( dest.state() != DependenceNode.ANALYZED ){	    System.err.println( destmembername+" not part of graph");	    return;	}	clearUserFlags( PathComponent.INSET );	Set tipset = new Set();	PathComponent r = new PathComponent( null, src );	tipset.addElement( r );	for ( int i = 0; i < 50; i++ ){	    Set newtips = new Set();	    Enumeration newGrowth = tipset.elements();	    while ( newGrowth.hasMoreElements() ){		PathComponent t = (PathComponent)(newGrowth.nextElement() );		if ( t.link.state() == DependenceNode.UNANALYZED ){		    System.err.println("Potential path element unanalyzed: "+t.link.name() );		} else {		    t.grow( newtips );		}	    }	    if ( newtips.size() == 0 ){		// exhaused the space without finding it.		System.out.println("No path from "+srcmembername+" to "+destmembername );		return;	    }	    // now see if we got to our destination.	    newGrowth = newtips.elements();	    boolean foundDest = false;	    while ( newGrowth.hasMoreElements() ){		PathComponent t = (PathComponent)(newGrowth.nextElement() );		if ( t.link == dest ){		    t.print( System.out );		    System.out.println();		    foundDest = true;		}		t.link.flags |= PathComponent.INSET;	    }	    if ( foundDest ){		return;	    }	    // round and round.	    tipset = newtips;	}	System.out.println("Path from "+srcmembername+" to "+destmembername+" is too long" );    }    private void printList( java.io.PrintStream o, Vector elementList ){	printFlaggedList( o, elementList, ANY );     }    private void printFlaggedList( java.io.PrintStream o, Vector elementList, int flagmask ){	if ( elementList == null ) {	    o.println("	<nothing>");	    return;	}	Enumeration loadlist = elementList.elements();	while ( loadlist.hasMoreElements() ){	    DependenceNode thing = (DependenceNode)(loadlist.nextElement());	    if ( (thing.flags&flagmask) != 0 ){		o.println( thing.name() );	    }	}	o.flush();    }    private void processArgs( String args[] ){	for ( int i = 0; i < args.length; i++ ){	    String a = args[i];	    /*	     * -classpath is common to all uses of	     * dependence analysis. The argument is a	     * :-separated list of places to look for	     * class files. This can include jar/zip files	     * and directories. This can be given multiple	     * times, and is cumulative.	     */	    if ( a.equals("-classpath") ){		finder.addToSearchPath( args[++i] );		continue;	    }	    /*	     * -exclude is common to all uses of dependence	     * analysis. The argument is a full class name,	     * for a class which is not to be analysed	     * (except for the names it exports and	     * superclass relationships). If the last 	     * component of the name is '*', then this	     * represents a whole package to be excluded.	     */	    if ( a.equals("-exclude") ){		excludeClass( args[++i] );		continue;	    }	    /*	     * -f filename	     * to name a file containing more commands.	     * It is used mostly for including canned	     * sequences of commands, such as those naming	     * all the classes required by the implementation.	     * They are processed in order, immediately.	     */	    if ( a.equals("-f" ) ){		String filename = args[++i];		try {		    String newargs[] = parseOptionFile( filename );		    processArgs( newargs ); // just call us recursively.		} catch ( java.io.IOException ioe ){		    System.out.println(			Localizer.getString("javafilter.could_not_process", 			filename)		    );		    ioe.printStackTrace();		    hadError = true;		}		continue;	    }	    /*	     * -v increases verbosity.	     */	    if ( a.equals("-v" ) ){		verbosity += 1;		continue;	    }	    /*	     * -nativelist filename	     * to have the names of all native methods included	     * written on the named file.	     */	    if ( a.equals("-nativelist") ){		try {		    nativelist = new BufferedPrintStream( new FileOutputStream( args[++i] ) );		} catch ( Exception e ){		    System.err.println(			Localizer.getString("javafilter.cannot_open_nativelist", args[i])		    );		    hadError = true;		}		continue;	    }	    /*	     * Dependence loading.	     *     -load full-member-name to specify a member.	     */	    if ( a.equals("-load") ){		membersToLoad.addElement( args[++i] );		continue;	    }	    /*	     *    -new full-class-name 	     *    -new full-class-name(sig)V	     * 		A shorthand for naming constructors	     *		-load full-class-name.<init>()V or	     *		-load full-class-name.<init>(sig)V	     */	    if ( a.equals("-new") ){		constructorsToLoad.addElement( args[++i] );		continue;	    }	    /*	     *    -main full-class-name is shorthand for	     *		-load full-class-name.main(Ljava/lang/String;)V	     */	    if ( a.equals("-main") ){		membersToLoad.addElement( args[++i] + "." + mainName + mainSig  );		continue;	    }	    /*	     *     -loadClass full-class-name to specify all	     *			members of a class.	     */	    if ( a.equals("-loadClass") ){		classesToLoad.addElement( args[++i] );		continue;	    }	    /*	     *	   -interface full-class-name to specify a	     *		contract that must be honored by	     *		subclasses of the named class or	     *		implementors of an interface.	     */	    if ( a.equals("-interface") ){		interfaceClasses.addElement( args[++i] );		continue;	    }	    /*	     *	    -wholeClass full-class-name or	     *	    -wholeClass packagename.*	     *		load the whole class.	     */	    if ( a.equals("-wholeClass") ){		allClassMembers( args[++i] );		continue;	    }	    /*	     *	    -wholeData full-class-name or	     *	    -wholeData packagename.*	     *		load all the data.	     */	    if ( a.equals("-wholeData") ){		allClassData( args[++i] );		continue;	    }	    /*	     *	-dependence full-member-name verb full-member-name	     *	To describe to the program dependences that it 	     *	cannot be understood. Chiefly to describe	     *	dependences from native-code methods, which cannot	     *	otherwise be analysed. "verb" is one of:	     *	    reads	     *	    writes	     *	    calls	     *	    classRef, in which case the 3rd operand is actually	     *		a full-class-name	     */	    if ( a.equals("-dependence") ){		dependences.addElement(		    new DependenceRelation( args[++i], args[++i], args[++i] )		);		continue;	    }		    if ( a.equals("-help")) {		printUsage();	        break;	    }	    if ( a.equals("-listSignatureDepend")) {		analyzer.useSignatureDependence(true);		continue;	    }			    /*	     * -path a z	     * To show the how a dependes on z. Prints all dependence chains of the	     * shortest length. Probably does not deal in overloading issues, yet.	     */	    if ( a.equals("-path") ){		paths.addElement( new PathPair( args[++i], args[++i] ) );		continue;	    }	    if ( a.equals("-showAll")) {		details = true;		continue;	    }	    if ( a.equals("-showClassList")) {		classlistonly = true;		continue;	    }		    if ( a.equals("-showDirect") ) {		showClasses.addElement( args[++i] );		break;	    }	    System.out.println(Localizer.getString("javafilter.command_not_recognized", args[i]));	    hadError = true;	}    }    private void printUsage() {	System.out.println("printUsage");    }    private Vector interfaceClasses;    private Vector dependences;    private Vector membersToLoad;    private Vector constructorsToLoad;    private Vector classesToLoad;    private Vector paths;    private Vector showClasses;    private boolean process( String args[] ){	interfaceClasses = new Vector();	dependences = new Vector();	membersToLoad = new Vector();	constructorsToLoad = new Vector();	classesToLoad = new Vector();	paths = new Vector();	showClasses = new Vector();	processArgs( args );	if ( ! hadError )	    doLoad();	/* showPath must do after the nodes are analyzed. */	Enumeration p = paths.elements();	if ( (! hadError) && ( p!=null) ){	    while (p.hasMoreElements() ){		PathPair pp  = (PathPair)(p.nextElement());		showPath( pp.src, pp.dest );	    }	}	p = showClasses.elements();	if ( (! hadError) && ( p!=null) ){            while (p.hasMoreElements() ){		showOne((String)p.nextElement());            }        }	if (details)	    showAll();	if (classlistonly) 	    showClassList();	return hadError;    }    public static void main( String args[] ){	boolean fail = (new JavaMemberDepend().process( args ));	if ( fail ){	    System.exit( 1 );	}    }    class NeverAccept extends util.ClassnameFilter{        public boolean accept( java.io.File dir, String className ){            return false;        }    }    class PathPair {        String src;        String dest;        PathPair( String s, String d ){            src = s;            dest = d;        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?