javaapilister.java

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

JAVA
1,112
字号
            ClassMemberInfo cdccma[] = (methods) ? 	               ((ClassMemberInfo[])cdcClass.methods) :		       ((ClassMemberInfo[])cdcClass.fields);            int size = members.size();            for (int i = 0; i < size; i++) {                ClassMemberInfo cm = (ClassMemberInfo)(members.get(i));                ClassMemberInfo cdccm = findROMMember(		    cdcClass, cdccma, cm.name.string, cm.type.string, methods);                /* replace the member */                if (cdccm != null) {                members.set(i, cdccm);	        }	    }	}    }    private void    collectClassComponents(	Vector components,	ClassInfo thisClass,	Vector classesAlreadySeen,	boolean methods,	boolean superIsFinal,	boolean leafClass)    {	boolean classIsFinal;	int     permissionMask;	ClassMemberInfo cma[];        if (verbosity > 0){            String s = (methods) ? "methods" : "fields";            System.out.println("Collect " + s +                               " for " + thisClass.className);	}	// if this class has already been seen,	// don't go looking at it again.	if (classesAlreadySeen.contains(thisClass)){            if (verbosity > 0){                System.err.println(thisClass.className + "has already seen.");	    }	    return;	}	classesAlreadySeen.addElement(thisClass);	// First look at all the elements in this class	// and see if we want to add any of them. See if	// they have already been added.	permissionMask = Const.ACC_PUBLIC;	classIsFinal = superIsFinal || 	    ((thisClass.access & Const.ACC_FINAL) != 0);	if (!classIsFinal){	    permissionMask |= Const.ACC_PROTECTED;	}	cma = (methods) ? ((ClassMemberInfo[])thisClass.methods)			: ((ClassMemberInfo[])thisClass.fields);	if (cma != null){            int i;	    int nMembers = cma.length;            ClassMemberInfo cm;                        /* start collecting qualified members */	    for (i = 0; i < nMembers; i++){		cm = cma[i];		if ((cm.access & permissionMask) == 0)		    continue;		if (cm.name.string.equals("<clinit>"))		    continue;		if (!leafClass){		    // this is a superclass or interface.		    /* Bug 6589171.                     if (cm.isStaticMember()){			// subclasses don't inherit our statics			continue;		    }*/		    if (cm.name.string.equals("<init>")){			// subclasses don't inherit our constructors			continue;		    }		}		// this looks like a candidate.		// see if its already on the list.		ClassMemberInfo otherCm;		Enumeration componentsE = components.elements();		boolean doPrint = true;		while (componentsE.hasMoreElements()){		    otherCm = (ClassMemberInfo)componentsE.nextElement();		    if (!cm.name.string.equals(otherCm.name.string)){			// names differ.			// keep looking.			continue;		    }		    // names the same		    if (methods){			if (!cm.type.string.equals(otherCm.type.string)){			    // is a method and types are not the same.			    // methods override on name and type.			    // otherCm does not override this one.			    continue;			}		    }		    //		    // otherCm is a field with the same name		    // or a method with the same name and sig.		    // cm has been overridden and should not be		    // printed again.		    doPrint = false;		    break;		}		if (doPrint){		    // we want to include this one on the list.		    components.add(cm);                    if (verbosity > 0){                        System.out.println("\tFound member:  " + cm);	            }		}	    }	}	String otherName;	ClassInfo otherClass;	ClassConstant superConstant = thisClass.superClass;	// look at superclass        if ((thisClass.access & Const.ACC_INTERFACE) == 0) {	    if (superConstant != null){	        // recurse into superclass	        otherName = superConstant.name.string;	        if ((otherClass = ClassTable.lookupClass(otherName, apiloader))		    != null){		    collectClassComponents(components, otherClass,		        classesAlreadySeen, methods, classIsFinal, false);	        }	    }	}	// look at interfaces. This should only matter	// when the current class is an interface or abstract.	if (thisClass.interfaces != null){	    int nInterfaces = thisClass.interfaces.length;	    for (int i=0; i<nInterfaces; i++){		otherName = thisClass.interfaces[i].name.string;		if ((otherClass = ClassTable.lookupClass(otherName, apiloader))		    != null){		// recurse into interfaces		collectClassComponents(components, otherClass,		    classesAlreadySeen, methods, classIsFinal, false);		}	    }	}    }    private void    printVector(String title, Object m[]){	if (m.length == 0)	    return;	memberOut.println(title);	for (int i = 0; i < m.length; i++){	    ClassMemberInfo cm = (ClassMemberInfo)(m[i]);	    memberOut.print('\t');	    memberOut.print(cm.name.string);	    memberOut.print(':');	    memberOut.println(cm.type.string);	}    }    private void    setClassMembers(ClassInfo thisClass, Vector members,                    boolean methods)    {        if (methods) {            thisClass.methodtable = (MethodInfo[])members.toArray(new MethodInfo[0]);        } else {            thisClass.fieldtable = (FieldInfo[])members.toArray(new FieldInfo[0]);        }    }    private void    printClassComponents(ClassInfo thisClass)    {	Vector classesVisited;	Vector methods;        Vector fields;	// print fields	printVector("   FIELDS", thisClass.fieldtable);	// print methods	printVector("   METHODS", thisClass.methodtable);    }    private boolean    includedAndVisible(ClassInfo c){	String classname = c.className;	int access = c.access;	if (!isClassIncluded(classname)){	    return false;	}	if ((access & Const.ACC_PUBLIC) == 0){	    return false;	}	return true;    }    private void    printClassInfo( ClassInfo c ){	if (!includedAndVisible(c)){	    if (verbosity > 0){		System.err.print("Excluded class ");		System.err.println(c.className);	    }	    return;	}	memberOut.print("\nCLASS ");	memberOut.println(c.className);	printClassComponents(c);    }    private void    printClassName( ClassInfo c )    {	String name = c.className.replace('/','.');	classOut.println(name);    }    public void writeRomFilter(PrintStream out)    {        int i, j;        int nClasses = sortedClasses.size();        ClassInfo thisClass;        ClassInfo cdcClass;        CVMClass cvmClass;        String cName;        writeRomFileHeader(romOut);        /* first write all class member arrays */        for (i = 0; i < nClasses; i++) {            thisClass = (ClassInfo)sortedClasses.get(i);            cvmClass = (CVMClass)sortedCVMClasses.get(i);            cName = cvmClass.getNativeName();            FieldInfo fa[] = thisClass.fieldtable;            MethodInfo ma[] = thisClass.methodtable;            int typeid, nameid;            /* write the class's fields */            if (fa.length > 0) {                out.println("/* " + cName + " fields */");                out.println("CVMFieldTypeID " + cName + "_f[] = {");                for (j = 0; j < fa.length; j++) {                    FieldInfo f = fa[j];                    typeid = CVMDataType.parseSignature((f.type).toUTF());                    nameid = CVMMemberNameEntry.lookupEnter((f.name).toUTF());                    out.println("\tRAW_TYPEID(0x" + Integer.toHexString(nameid) +                                ", 0x" + Integer.toHexString(typeid) + "), ");	        }                out.println("};");	    }            /* write the class' methods */	    if (ma.length > 0) {                out.println("/* " + cName + " methods */");                out.println("CVMMethodTypeID " + cName + "_m[] = {");                for (j = 0; j < ma.length; j++) {                    MethodInfo m = ma[j];                    CVMMethodInfo cm = (CVMMethodInfo)m.vmMethodInfo;                    typeid = cm.sigType.entryNo;                    nameid = CVMMemberNameEntry.lookupEnter(                                    (cm.method.name).toUTF());                    out.println("\tRAW_TYPEID(0x" + Integer.toHexString(nameid) +                                ", 0x" + Integer.toHexString(typeid) + "), ");	        }                out.println("};");	    }        }        /* write CVMClassRestrictions data struct */        out.println("\n/* The dual stack member filter. */");	if (nClasses != 0) {	    out.println("struct CVMClassRestrictionElement cre[] = {");	    for (i = 0; i < nClasses; i++) {		thisClass = (ClassInfo)sortedClasses.get(i);		cvmClass = (CVMClass)sortedCVMClasses.get(i);		cName = cvmClass.getNativeName();		/* class typeid */                out.print("{0x" + Integer.toHexString(cvmClass.getClassId()) +                          ", ");		/* number of methods */		out.print(thisClass.methodtable.length + ", ");		/* number of fields */		out.print(thisClass.fieldtable.length + ", ");		/* method table */		if (thisClass.methodtable.length == 0) {		    out.print("NULL /* " + cName + "_m */, ");		} else {		    out.print(cName + "_m, ");		}		/* field table */		if (thisClass.fieldtable.length == 0) {		    out.println("NULL /* " + cName + "_f */},");		} else {		    out.println(cName + "_f},");		}	    }	    out.println("};");	    	    /* write CVMClassRestrictions data struct */	    out.print("const struct CVMClassRestrictions CVMdualStackMemberFilter = {");	    out.print(nClasses + ", ");	    out.println("cre};");	} else {	    out.println("const struct CVMClassRestrictions CVMdualStackMemberFilter = {0, NULL};");	}        out.flush();    }    private void writeMemberFile()    {        if (memberOut == null) {            /* mout is not set. Nothing to do here. */            return;        }        int nClasses = classesProcessed.size();        printFileHeader(memberOut, memberFileHeader);        for (int i = 0; i < nClasses; i++) {            ClassInfo c = (ClassInfo)classesProcessed.get(i);            if (!includedAndVisible(c)) {                continue; /* excluded. Skip this class. */            }            memberOut.print("\nCLASS ");	    memberOut.println(c.className);            printClassComponents(c);	}        memberOut.flush();    }    private void writeClassFile()    {        if (classOut != null){	    printFileHeader(classOut, classFileHeader);	    int nClasses = classesProcessed.size();	    for (int i = 0; i < nClasses; i++){                ClassInfo c = (ClassInfo)classesProcessed.get(i);                if (!includedAndVisible(c)) {                    continue; /* excluded. Skip this class. */                }		printClassName(c);	    }	    classOut.flush();	}    }    /*     * Collect class members and store them in 'fieldtable' and     * 'methodtable'.     */    private void processClasses()    {        if (minput != null) {            /*             * Parse the minput and create ClassInfo for each             * class in the list.             */            parseMInput(minput);            return;	}        /*         * The classes are from a input jar file. Process

⌨️ 快捷键说明

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