FileDocCategorySizeDatePackage
SignatureIterator.javaAPI DocJ2ME CLDC 1.15433Wed Feb 05 15:56:04 GMT 2003util

SignatureIterator

public abstract class SignatureIterator extends Object

Fields Summary
protected String
sig
private int
sigStart
private int
cur
private int
end
private int
arrayDepth
public boolean
isSingleton
protected boolean
isReturnType
Constructors Summary
public SignatureIterator(String sig, int start, int end)

    this.sig = sig;
    this.sigStart = cur = start;
    this.end = end;
    isSingleton = sig.charAt( start ) != Const.SIGC_METHOD;
    
public SignatureIterator(String sig)

    this( sig, 0, sig.length()-1);
    
Methods Summary
public java.lang.StringclassName(int startpos, int endpos)

    return sig.substring( startpos+1, endpos );
    
private intdelimitClassname()

    int endpos = sig.indexOf( Const.SIGC_ENDCLASS, cur );
    if ( (endpos < 0 ) || (endpos > end ) )
        throw new DataFormatException( "unending class name");
    return endpos;
    
public abstract voiddo_array(int arrayDepth, int subTypeStart, int subTypeEnd)

public voiddo_boolean()

    do_scalar( Const.SIGC_BOOLEAN );
    
public voiddo_byte()

    do_scalar( Const.SIGC_BYTE );
    
public voiddo_char()

    do_scalar( Const.SIGC_CHAR );
    
public voiddo_double()

    do_scalar( Const.SIGC_DOUBLE );
    
public voiddo_float()

    do_scalar( Const.SIGC_FLOAT );
    
public voiddo_int()

    do_scalar( Const.SIGC_INT );
    
public voiddo_long()

    do_scalar( Const.SIGC_LONG );
    
public abstract voiddo_object(int subTypeStart, int subTypeEnd)

public voiddo_scalar(char c)

    return;
    
public voiddo_short()

    do_scalar( Const.SIGC_SHORT );
    
public voiddo_void()

    do_scalar( Const.SIGC_VOID );
    
public booleanisMethod()

 return !isSingleton; 
public static booleanisPrimitiveType(java.lang.String sig)

    char c = sig.charAt(0);
    return ( (c!=Const.SIGC_METHOD) && (c!=Const.SIGC_ARRAY) && (c!=Const.SIGC_CLASS) );
    
public voiditerate()

    if ( isSingleton ){
        // trivial case.
        isReturnType = false;
        cur = sigStart;
        next( sig.charAt(cur++) );
    } else {
        iterate_parameters();
        iterate_returntype();
    }
    
public voiditerate_parameters()

    cur = sigStart;
    if ( isSingleton )
        throw new DataFormatException(sig.substring(cur-1, end)+" is not a method signature");
    cur += 1;
    isReturnType = false;
    char c;
    while ((c=sig.charAt(cur++) ) != Const.SIGC_ENDMETHOD ){
        if ( cur > end ){
        throw new DataFormatException( "unterminated parameter list");
        }
        next( c );
    }
    
public voiditerate_returntype()

    if ( isSingleton )
        throw new DataFormatException(sig.substring(sigStart, end)+" is not a method signature");
    int endpos = sig.indexOf( Const.SIGC_ENDMETHOD, sigStart );
    isReturnType = true;
    if ( (endpos < 0 ) || (endpos > end ) )
        throw new DataFormatException( "unterminated parameter list");
    cur = endpos+1;
    next( sig.charAt(cur++) );
    
private voidnext(char c)

    switch (c){
    case Const.SIGC_BOOLEAN:
        do_boolean(); return;
    case Const.SIGC_BYTE:
        do_byte(); return;
    case Const.SIGC_CHAR:
        do_char(); return;
    case Const.SIGC_SHORT:
        do_short(); return;
    case Const.SIGC_INT:
        do_int(); return;
    case Const.SIGC_FLOAT:
        do_float(); return;
    case Const.SIGC_LONG:
        do_long(); return;
    case Const.SIGC_DOUBLE:
        do_double(); return;
    case Const.SIGC_VOID:
        do_void();
        return;

    case Const.SIGC_CLASS:
        int startClassName = cur-1;
        int endClassName = delimitClassname( );
        cur = endClassName+1;
        do_object( startClassName, endClassName );
        return;

    case Const.SIGC_ARRAY:
        arrayDepth = 0;
        cur -= 1;
        do {
        arrayDepth += 1;
        }while ((cur<=end) && ((c=sig.charAt(++cur)) == Const.SIGC_ARRAY));
        if ( cur > end )
        throw new DataFormatException( "array of nothing");
        int startBaseType = cur;
        int endBaseType;
        // now isolate at the base type.
        if ( c == Const.SIGC_CLASS ){
        endBaseType = delimitClassname( );
        } else {
        endBaseType = startBaseType;
        }
        cur = endBaseType+1;
        do_array( arrayDepth, startBaseType, endBaseType );
        return;

    case Const.SIGC_METHOD:
        // cannot happen here!
    default:
        throw new DataFormatException( "unparseable signature: " + sig);
    }