FileDocCategorySizeDatePackage
MemberLoader.javaAPI DocphoneME MR2 API (J2ME)7595Wed May 02 17:59:48 BST 2007jcc

MemberLoader

public class MemberLoader extends Object

Fields Summary
String
fname
StreamTokenizer
in
ClassFileFinder
finder
ClassReader
rdr
Constructors Summary
public MemberLoader(ClassReader r, ClassFileFinder f)

	rdr = r;
	finder = f;
    
Methods Summary
private static voidcopyNonNull(ClassMemberInfo[] from, ClassMemberInfo[] to)

	    int n = from.length;
	    int j = 0;
	    for ( int i = 0; i < n; i++ ){
		if ( from[i] != null ){
		    from[i].index = j;
		    to[j++] = from[i];
		}
	    }
    
private intdeleteMembers(ClassMemberInfo[] mlist)

	if ( mlist == null || mlist.length == 0 )
	    return 0; // trivial case.
	int n = mlist.length;
	int ndeleted = 0;
	for ( int i = 0; i < n; i++ ){
	    if ( (mlist[i].flags&ClassMemberInfo.INCLUDE) == 0 ){
		mlist[i].index = -1; // obvious error value.
		mlist[i] = null;
		ndeleted+=1;
	    }
	}
	return ndeleted;
    
public voiddeleteUnwantedMembers(java.util.Vector classes)

	Enumeration e = classes.elements();
	while ( e.hasMoreElements() ){
	    ClassInfo ci = (ClassInfo) e.nextElement();
	    if ( (ci.flags&ClassInfo.INCLUDE_ALL) != 0 )
		continue; // a fully-loaded class.
	    loadMembers( ci );
	}
    
private ClassInfoenterClass(java.lang.String classname, java.util.Vector v)

	ClassInfo ce;
	classname = classname.intern();
	ce = components.ClassInfo.lookupClass( classname );
	if ( ce != null ) return ce;

	if ( rdr.readClass( classname, finder, v ) != 1 ){
	    //could not find anywhere.
	    System.err.println(Localizer.getString(
				   "memberloader.could_not_find_class", 
				    classname));
	    return null; // or worse...
	}
	ce = (ClassInfo)( v.lastElement() );
	//
	// we know that this was loaded on account of us.
	// unlike most classes, this one will start life
	// as empty, with no members assumed.
	ce.flags &= ~(ClassInfo.INCLUDE_ALL);
	ce.clearMemberFlags( ClassMemberInfo.INCLUDE );
	return ce;
    
private booleanenterMember(ClassInfo ce, java.lang.String name)

	if ( (ce.flags&ClassInfo.INCLUDE_ALL) != 0 ){
	    return true; // doesn't matter what we do anyway!
	}
	ClassMemberInfo t[];
	String sig;
	// determine if this is data or method by looking
	// at the signature, or lack thereof.
	int sigstart = name.indexOf( '(" );
	if ( sigstart == -1 ){
	    // this is data.
	    // too bad we cannot use the standard procedure
	    // that  components/FMIrefConstant.find() uses,
	    // but we cannot because the hash ID requires
	    // data type signature information, which we lack.
	    t = ce.fields;
	    sig = null;
	} else {
	    // this is code.
	    //
	    sig = name.substring( sigstart );
	    name = name.substring( 0, sigstart );
	    t = ce.methods;
	}
	int l = t.length;
	for ( int i = 0; i < l ; i++ ){
	    if ( t[i].name.string.equals( name ) ){
		if ( (sig == null) || sig.equals( t[i].type.string ) ){
		    t[i].flags |= ClassMemberInfo.INCLUDE;
		    return true; // done.
		}
	    }
	}
	System.err.println(Localizer.getString(
			       "memberloader.could_not_find_member",
			        ce.className, name));
	return false;
    
private voidloadMembers(ClassInfo ci)

	int ndeleted = deleteMembers( ci.methods );
	if ( ndeleted != 0 ){
	    int n = ci.methods.length;
	    MethodInfo newlist[] = new MethodInfo[ n-ndeleted ];
	    copyNonNull( ci.methods, newlist );
	    ci.methods = newlist;
	}
	ndeleted = deleteMembers( ci.fields );
	if ( ndeleted != 0 ){
	    int n = ci.fields.length;
	    FieldInfo newlist[] = new FieldInfo[ n-ndeleted ];
	    copyNonNull( ci.fields, newlist );
	    ci.fields = newlist;
	}
    
private voidoops(java.lang.String lmsg)

	String errmsg = Localizer.getString(
			    "memberloader.dependence_file_error_near_line", 
			     fname, Integer.toString(in.lineno()));
	if ( lmsg != null ){
	    errmsg += Localizer.getString(lmsg);
	}
	in = null; // when we bail, close the file.
	throw new DataFormatException( errmsg );
    
private voidopenStream(java.lang.String name)

	fname = name;
	in = new StreamTokenizer(
	    new java.io.BufferedInputStream(
		new java.io.FileInputStream( fname ) ) );
	in.resetSyntax();
	in.eolIsSignificant( true );
	in.whitespaceChars( 0, 0x20 );
	in.wordChars( '!", '~" );
	in.commentChar('#");
	in.ordinaryChar( '." );

    
public voidreadFromFile(java.lang.String fname, java.util.Vector classlist)

	int t;
	openStream(fname);
	while ( (t = in.nextToken() ) != StreamTokenizer.TT_EOF ){
	    /*
	     * Process a line of input. It may be empty
	     * or contain only a comment.
	     * Else there must be a class name.
	     * If the class name is followed by a .,
	     * then a member name follows. The name
	     * will include a signature, if a method is named.
	     * No signature is needed for data members.
	     */
	    if ( t == StreamTokenizer.TT_EOL )
		continue;
	    String className;
	    String memberName;
	    String sig;
	    if ( t != StreamTokenizer.TT_WORD )
		oops("memberloader.missing_classname");
	    className = in.sval;
	    ClassInfo ce = enterClass( className, classlist );
	    if ( (t=in.nextToken()) == StreamTokenizer.TT_EOL ){
		continue; // class name only
	    }
	    if ( t != '." ){
		oops( "memberloader.syntax_error" );
		continue;
	    }
	    if ( (t=in.nextToken()) != StreamTokenizer.TT_WORD ){
		oops("memberloader.malformed_member_name");
		continue;
	    }
	    memberName = in.sval;
	    /*
	     * Now that we've read the names, process it.
	     */
	    if ( ce != null )
		enterMember( ce, memberName );

	    if ( in.nextToken() != StreamTokenizer.TT_EOL )
		oops("memberloader.extra_material");
	}
	in = null; // close the file.