javaapilister.java

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

JAVA
1,112
字号
         * classes and collect visiable members.         */        int num = classesProcessed.size();        for (int i = 0; i < num; i++) {            ClassInfo thisClass = (ClassInfo)classesProcessed.get(i);            if (!includedAndVisible(thisClass)){	        if (verbosity > 0){		    continue; /* skip excluded class */	        }	    }            /* collect fields */            Vector fields = new Vector();            collectClassComponents(fields, thisClass, new Vector(), 			           false, false, true);            /* replace the fields with the ROMized version in order             * get the typeid info. */            replaceMembers(thisClass, fields, false);            /* set 'fieldtable' */            setClassMembers(thisClass, fields, false);            /* collect methods */            Vector methods = new Vector();            collectClassComponents(methods, thisClass, new Vector(), 			           true, false, true);            /* replace the methods with ROMized verison in order             * to get the typeid info. */            replaceMembers(thisClass, methods, true);            /* set 'methodtable' */            setClassMembers(thisClass, methods, true);	}    }    /*     * Sort classes in 'classesProcessed' Vector by typeid, and add them     * to 'sortedClasses' LinkedList. Only visible classes are added to     * 'sortedClasses'. Also add the corresponding internal VM class to      * 'sortedCVMClasses' in the same order.     */    private boolean sortClasses()    {        int nClasses = classesProcessed.size();        for (int i = 0; i < nClasses; i++) {            ClassInfo thisClass = (ClassInfo)classesProcessed.get(i);            if (!includedAndVisible(thisClass)) {                continue; /* excluded. Skip this class. */            }            ClassInfo cdcClass;            CVMClass cvmClass;            int id;            int nSortedClasses;            int j;            cdcClass = ClassTable.lookupClass(thisClass.className);            if (cdcClass == null) {                sortedClasses.clear();                sortedCVMClasses.clear();                return false;	    }            cvmClass = (CVMClass)cdcClass.vmClass;            id = cvmClass.getClassId();            nSortedClasses = sortedCVMClasses.size();            for (j = 0; j < nSortedClasses; j++) {                if (id < ((CVMClass)sortedCVMClasses.get(j)).getClassId()) {                    break; /* found location */		}            }            /* add to the sorted linked lists */            sortedClasses.add(j, thisClass);            sortedCVMClasses.add(j, cvmClass);	}        return true;    }    // keywords in easy-to-manipulate integer form    private static final int NOKEY = 0;    private static final int CLASS = 1;    private static final int FIELDS = 2;    private static final int METHODS = 3;    private static Hashtable keywords = new Hashtable();    static {        keywords.put("",        new Integer(NOKEY));        keywords.put("CLASS",   new Integer(CLASS));        keywords.put("FIELDS",  new Integer(FIELDS));        keywords.put("METHODS", new Integer(METHODS));    }    /* Get the integer form of the keyword */    private static int keyword(String word) {	Integer n = (Integer)keywords.get(word);        if (n != null) {            return n.intValue();        } else {	    return NOKEY;        }    }    /* Get the next word from the 'in' stream */    private String    nextWord(StreamTokenizer in) throws Exception{	int token = in.nextToken();	if (token == in.TT_EOF){	    throw new EOFException("EOF");	}	if (token != in.TT_WORD){	    throw new Exception("token type");	}	return in.sval;    }    private int    expecting(StreamTokenizer in, int token1, int token2, int token3)                                                throws Exception{	int key;	key = keyword(nextWord(in));	if (key != token1 && key != token2 && key != token3){	    throw new Exception("token value ".concat(in.sval));	}	return key;    }    static private void    printStringArray(String name, String val[]){	if (val == null || val.length == 0)	    return;	System.out.println(name);	int l = val.length;	for(int i=0; i<l; i++){	    System.out.print('\t');	    System.out.println(val[i]);	}    }    /*     * Parse the input class and member list. Create a ClassInfo     * for the corresponding class.      */    private void    parseClass(StreamTokenizer in) throws Exception {	String classname = null;	String word = null;	int    keyword;	int    token;	LinkedList methods = new LinkedList();	LinkedList fields = new LinkedList();	try{	    // parse CLASS and classname	    expecting(in, CLASS, -1, -1);	    classname = nextWord(in);	    while(true){		// parse FIELDS or METHODS		keyword = expecting(in, FIELDS, METHODS, CLASS);		LinkedList thislist;		if (keyword == CLASS){		    // beginning of next class signals the end of this one.		    in.pushBack();		    break;		}		thislist = (keyword == FIELDS)? fields : methods;		while(true){		    String memberName = nextWord(in);		    // see if this name is a keyword.		    // since the memberNames, if properly formed,		    // must contain :, there should be no danger of		    // confusion.		    keyword = keyword(memberName);		    if (keyword != NOKEY){			in.pushBack();			break;		    }		    // make sure we have our :		    if (memberName.indexOf(':') == -1){			throw new Exception("format error in ".concat(memberName));		    }		    thislist.add(memberName);		}	    }	}finally{	    if (classname != null){		// here, using empty as a prototype for String[]                String empty[] = new String[0];		String methodstrings[] = (String[])methods.toArray(empty);		String fieldstrings[] = (String[])fields.toArray(empty);		if (verbosity > 0){		    System.out.print("CLASS ");		    System.out.println(classname);		    printStringArray("    FIELDS", fieldstrings);		    printStringArray("    METHODS", methodstrings);		}                enterClassInfo(classname, methodstrings, fieldstrings);	    }	}    }    /*     * 'ci' is the ClassInfo created for a class name in the minput.     * 'cdcClass' is the corresponding ROMized class.  For each member     * in the 'members' array, find the ClassMemberInfo     * from the ROMized 'cdcClass'. Set the methodtable (or     * fieldtable) of 'ci' with the ClassMemberInfo vector.     */    private void enterMemberInfo(ClassInfo ci, ClassInfo cdcClass,                                 String members[], boolean isMethod) {        int length = members.length;        Vector mv = new Vector();        ClassMemberInfo cdcma[] = (isMethod) ?	               ((ClassMemberInfo[])cdcClass.methods) :		       ((ClassMemberInfo[])cdcClass.fields);        for (int i = 0; i < length; i++) {            int idx = members[i].indexOf(':');            String membername, membertype;            membername = members[i].substring(0, idx);            membertype = members[i].substring(idx + 1);            ClassMemberInfo f = findROMMember(                cdcClass, cdcma, membername, membertype, isMethod);            mv.add(f);        }        setClassMembers(ci, mv, isMethod);    }    /* Create a new ClassInfo and add it to te 'classesProcessed' vector. */    private void enterClassInfo(String classname,                                 String methods[],                                String fields[])                                throws ClassNotFoundException    {        ClassInfo cdcClass = ClassTable.lookupClass(classname);        if (cdcClass == null) {            /*             * The ROMized class doesn't exist. This probably is not             * a fully ROMized build, and we only support ROMized build.             * Remove all classes from the 'classesProcessed' vector             * and bail out.             */            classesProcessed.removeAllElements();            throw new ClassNotFoundException("Can't find ROMized " + classname);        }        /* Create the ClassInfo, which only contains className,           methods and fields information that we care about.	 */        ClassInfo ci = new ClassInfo(false);        ci.className = classname;        ci.access = Const.ACC_PUBLIC;        /* enter fields info */        enterMemberInfo(ci, cdcClass, fields, false);        /* process methods */        enterMemberInfo(ci, cdcClass, methods, true);        /* add the class to the 'classesProcessed' vector */        classesProcessed.add(ci);    }    /*     * Parse the 'minput'. Create ClassInfo for each class in     * list. For each class member, find the ClassMemberInfo     * from the corresponding ROMized class and set the ClassInfo's     * methodtable and fieldtable with the collected ClassMemberInfo.     */    private void parseMInput(String minput) {        try {            FileReader inFile = new FileReader(minput);            StreamTokenizer in = new StreamTokenizer(new BufferedReader(inFile));            in.commentChar('#');   	    in.slashSlashComments(false);	    in.eolIsSignificant(false);	    in.wordChars('a','z');	    in.wordChars('A','[');	    in.wordChars('0','9');	    in.wordChars('<','<'); // appears in name <init>	    in.wordChars('>','>');	    in.wordChars('_','_');	    in.wordChars(':',':'); // make special separator wordChar 	    in.wordChars(';',';'); // make all parts of a signature wordChar	    in.wordChars('(',')');	    in.wordChars('/','/'); // make name component separator wordChar	    in.whitespaceChars(' ',' '); // ignore space	    in.whitespaceChars('\t','\t'); // ignore tabs            try{	        while(true){		    parseClass(in);	        }  	    }catch(EOFException e){	        // normal termination. do nothing            }catch(ClassNotFoundException e) {                return;            }catch(IOException e){	        e.printStackTrace();                return;            }catch(Exception e){                e.printStackTrace();                return;            }        } catch (IOException e) {            e.printStackTrace();	}    }    public boolean process( String clist ) throws Exception {        if (clist != null) {	    commandOptions = clist;	    if (! processOptions( clist )){	        // malformed command-line argument or file read error	        return false;	    }        }        if (minput != null || memberOut != null) {            /*	     * Process classes and collect visible members. We use             * the 'fieldtable' and 'methodtable' to store collected             * members.             */            processClasses();            /*             * Sort classes in typeid order             */            sortClasses();            /*             * Write filter data into .c file             */            romOut =  openOutputFile(romOutName);            writeRomFilter(romOut);            /* Add .c file to romjavaList */            FileWriter listOut = new FileWriter(outName + "List", true);            listOut.write(romOutName, 0, romOutName.length());            listOut.close();	    /*	     * Write the member .txt file.	     */	    writeMemberFile();        }	/*	 * Now if a classlist output is specified do it too.	 */	writeClassFile();	return true;    }    public static void main( String clist[] ){	boolean success;	try {	    try {		success = new JavaAPILister().process( clist[0] );	    }finally{		System.out.flush();		System.err.flush();	    }	}catch (Throwable t){	    success = false;	    t.printStackTrace();	}	if (!success){	    // process threw error or failed	    System.exit(1);	}	return;    }}

⌨️ 快捷键说明

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