javaapilister.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 1,112 行 · 第 1/3 页
JAVA
1,112 行
/* * @(#)JavaAPILister.java 1.11 06/10/10 * * Copyright 1990-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */import consts.*;import components.*;import util.*;import jcc.*;import vm.*;import java.lang.Integer;import java.io.BufferedReader;import java.io.EOFException;import java.io.FileOutputStream;import java.io.IOException;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.PrintStream;import java.io.StreamTokenizer;import java.util.Enumeration;import java.util.HashSet;import java.util.Hashtable;import java.util.LinkedList;import java.util.Set;import java.util.StringTokenizer;import java.util.Vector;public class JavaAPILister extends LinkerUtil { int verbosity = 0; String commandOptions; ClassFileFinder searchPath; ClassReader rdr; ClassnameFilter includeClasses; PrintStream memberOut = null; PrintStream classOut = null; String outName = JavaCodeCompact.getOutName(); String romOutName = outName + "MemberFilterData.c"; PrintStream romOut = null; /* 'minput' should be the 'mout' generated by JavaAPILister * when jar files (contains classes) are taken as the input. * 'minput' and 'mout' contains a list of visiable classes * and their members. When 'minput' is set, other arguments * such as 'input', 'mout' and 'cout' are ignored. */ String minput = null; /* * The classes from the input jar file can have the same name as the * ROMized CDC classes. Use a separate loader to keep track of the * classes from the input jar file. We don't want to mix them with the * ROMized classes. This is to make sure we obtian the member * information from input classes, not the ROMized classes. */ components.ClassLoader apiloader = new components.ClassLoader("apilister", null); private static String memberFileHeader[] = { "#", "# %"+"W% %"+"E%", // use constant expressions to fool SCCS "# List of visible class members", "#" }; private static String classFileHeader[] = { "#", "# %"+"W% %"+"E%", // use constant expressions to fool SCCS "# List of classes", "#" }; private boolean readFile( String fileName, Vector classesProcessed ){ if (rdr == null){ rdr = new ClassReader(0); } try { if (fileName.endsWith(".zip") || fileName.endsWith(".jar")){ rdr.readZip(fileName, classesProcessed); } else { rdr.readFile(fileName, classesProcessed); } } catch ( IOException e ){ System.out.println(Localizer.getString( "javacodecompact.could_not_read_file", fileName)); e.printStackTrace(); return false; } return true; } /* All classes read from the input jar file. Include excluded (non-visible), such as com.sun.* classes. */ Vector classesProcessed = new Vector(); /* All visible classes. Sorted by class typeid. */ LinkedList sortedClasses = new LinkedList(); /* ROMized CDC classes corresponding to the classes in 'sortedClasses' */ LinkedList sortedCVMClasses = new LinkedList(); private void addToIncludes( String pattern ){ if (includeClasses == null){ includeClasses = new ClassnameFilter(); } includeClasses.includeName(pattern); if (verbosity > 0){ System.err.print("Adding to include list: "); System.err.println(pattern); } } private boolean isClassIncluded(String classname){ if (includeClasses == null){ return true; } return includeClasses.accept(null, classname); } private static BufferedPrintStream openOutputFile(String name){ File outFile = new File(name); try { return new BufferedPrintStream( new FileOutputStream( outFile ) ); }catch(java.io.IOException e){ System.err.println("Could not open file "+name); return null; } } /* Process the command line options. The options should look like: * * -listapi:include=java/*,include=javax/*, * input=<jar1>:<jar2>,minput=<minput>,mout=<mout>,cout=<cout> * * 'include' - Visible packages * 'input' - Jar file containing classes * 'minput' - The class/member list ('mout' output) generated by * JavaAPILister when input jar files are given * 'mout' - A txt file containing class/member list extracted from * the input classes * 'cout' - A txt file containing only class list extracted from * the input classes * * If 'minput' exists, all other options are ignored. * * Following is examples of what the 'minput' and 'mout' txt file look * like: * * CLASS java/util/Stack * FIELDS * elementData:[Ljava/lang/Object; * elementCount:I * capacityIncrement:I * METHODS * <init>:()V * push:(Ljava/lang/Object;)Ljava/lang/Object; * pop:()Ljava/lang/Object; * peek:()Ljava/lang/Object; * empty:()Z * ... */ private boolean processOptions(String args) { boolean success = true; Vector classesThisRead = new Vector(); StringTokenizer options = new StringTokenizer(args.substring(9), ","); int num = options.countTokens(); int si; if ((si = args.indexOf("minput=")) != -1) { /* minput exists, ignore the rest of the arguments */ int ei = args.indexOf(',' , si); if (ei == -1) { minput = args.substring(si+7); } else { minput = args.substring(si+7, ei); } return success; } /* minput doesn't exist, process all arguments */ for (int i = 0; i < num; i++) { String s = options.nextToken(); if (s.startsWith("verbose=")) { if (s.substring(8).equals("true")) { verbosity++; } } else if (s.startsWith("include=")) { addToIncludes(s.substring(8)); } else if (s.startsWith("input=")) { String separator = System.getProperty("path.separator", ":"); StringTokenizer st = new StringTokenizer(s.substring(6), separator); int numOfInput = st.countTokens(); for (int j = 0; j < numOfInput; j++) { String f = st.nextToken(); classesThisRead.clear(); if (!readFile(f, classesThisRead)) { success = false; } classesProcessed.addAll(classesThisRead); ClassTable.enterClasses( classesThisRead.elements(), apiloader); } } else if (s.startsWith("mout=")) { memberOut = openOutputFile(s.substring(5)); if (memberOut == null) { // message already written success = false; } } else if (s.startsWith("cout=")) { classOut = openOutputFile(s.substring(5)); if (classOut == null){ // message already written success = false; } } } return success; } /*private void printHeader0(PrintStream out, String commentString) { out.println(commentString + " DO NOT EDIT. This file is auto-generated by JCC from"); out.println(commentString + " a fully ROMized build using following build options: "); out.println(commentString + ""); out.println(commentString + " CVM_INCLUDE_MIDP=true PCSL_DIR=<pcsl_dir>"); out.println(commentString + " MIDP_DIR=<midp_dir> J2ME_CLASSLIB=foundation"); out.println(commentString + " CVM_DUAL_STACK=true CVM_PRELOAD_LIB=true"); out.println(commentString + " CVM_MIDPFILTERINPUT=<cldc_classes_zip>"); out.println(commentString + " gen_member_filter"); out.println(commentString + ""); out.println(commentString + " The output files are generated/javavm/runtime/romjavaMemberFilterData.c,"); out.println(commentString + " lib/MIDPFilterConfig.txt and lib/MIDPPermittedClasses.txt."); out.println(commentString + " If CLDC API is changed, this file needs to be re-generated."); }*/ private void printHeader0(PrintStream out, String commentString) { out.println(commentString + " DO NOT EDIT. This file is auto-generated by JCC."); } private void printFileHeader(PrintStream out, String header[]){ int hLength = header.length; for (int i=0; i<hLength; i++){ out.println(header[i]); } out.println("#"); printHeader0(out, "#"); out.println("#"); } /* Write filter data into a .c file. Class data are sorted * by typeid. */ private void writeRomFileHeader(PrintStream out) { out.println("/*"); printHeader0(out, " *"); out.println(" * This file is a copy of the generated romjavaMemberFilterData.c."); out.println(" */"); out.println(); out.println("#include \"generated/javavm/runtime/romjava.h\""); out.println("#include \"javavm/include/dualstack_impl.h\""); out.println(""); } /* Find the ROMizer version of class member, so we can access the * member typeid. */ private ClassMemberInfo findROMMember(ClassInfo cdcClass, ClassMemberInfo[] cdccma, String membername, String membertype, boolean isMethod) { ClassMemberInfo cdccm = null; /* Search the ROMized class members to find a match */ for (int j = 0; j < cdccma.length; j++) { if (membername.equals(cdccma[j].name.string)) { if (isMethod) { if (membertype.equals(cdccma[j].type.string)) { // match return cdccma[j]; } } else { // match return cdccma[j]; } } } /* Search the super class of the ROMized class for the member */ ClassConstant supercc = cdcClass.superClass; if (supercc != null) { ClassInfo superClass = ClassTable.lookupClass(supercc.name.string); ClassMemberInfo supercma[] = isMethod ? ((ClassMemberInfo[])superClass.methods) : ((ClassMemberInfo[])superClass.fields); cdccm = findROMMember(superClass, supercma, membername, membertype, isMethod); if (cdccm != null) { return cdccm; } } /* search the interfaces */ int nInterfaces = cdcClass.interfaces.length; for (int i = 0; i < nInterfaces; i++) { ClassInfo interfaceClass = ClassTable.lookupClass( cdcClass.interfaces[i].name.string); ClassMemberInfo interfacecma[] = isMethod ? ((ClassMemberInfo[])interfaceClass.methods) : ((ClassMemberInfo[])interfaceClass.fields); cdccm = findROMMember(interfaceClass, interfacecma, membername, membertype, isMethod); if (cdccm != null) { return cdccm; } } return null; } /* * Replace members in the vector with the members from the * corresponding ROMized class. */ private void replaceMembers(ClassInfo thisClass, Vector members, boolean methods) { /* get the ROMized class */ ClassInfo cdcClass = ClassTable.lookupClass(thisClass.className); if (cdcClass != null) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?