FileDocCategorySizeDatePackage
Descriptors.javaAPI DocAndroid 1.5 API7975Wed May 06 22:41:16 BST 2009com.vladium.util

Descriptors

public abstract class Descriptors extends Object
author
Vlad Roubtsov, (C) 2003

Fields Summary
public static final char
JAVA_NAME_SEPARATOR
public static final char
VM_NAME_SEPARATOR
private static final boolean
RENAME_INNER_CLASSES
Constructors Summary
private Descriptors()

Methods Summary
public static java.lang.Stringcombine(java.lang.String packageName, java.lang.String name, char separator)

    
                
    
        if ((name == null) || (name.length () == 0))
            throw new IllegalArgumentException ("null or empty input: name");
            
        if ((packageName == null) || (packageName.length () == 0))
            return name;
        else
            return new StringBuffer (packageName).append (separator).append (name).toString ();
    
public static java.lang.StringcombineJavaName(java.lang.String packageName, java.lang.String name)

        return combine (packageName, name, JAVA_NAME_SEPARATOR);
    
public static java.lang.StringcombineVMName(java.lang.String packageName, java.lang.String name)

        return combine (packageName, name, VM_NAME_SEPARATOR);
    
public static java.lang.StringjavaNameToVMName(java.lang.String javaName)
Converts a Java package/class name to how it would be represented in the VM.

Example:


javaNameToVMName("java.lang.Object") = "java/lang/Object"

see
#vmNameToJavaName

        if (javaName == null) return null;
        
        return javaName.replace ('.", '/");
    
public static java.lang.StringmethodVMNameToJavaName(java.lang.String className, java.lang.String methodVMName, java.lang.String descriptor, boolean renameInits, boolean shortTypeNames, boolean appendReturnType)
NOTE: With 'shortTypeNames'=true the output is potentially lossy (truncates package name) and can result in method signature collisions in very rare circumstances (e.g., java.awt.List = java.util.List).

Return type info is also lost.

return
method name (signature), no package prefix, no return type

        final StringBuffer out = new StringBuffer ();
        
        if (renameInits)
        {
            if (IClassDefConstants.CLINIT_NAME.equals (methodVMName))
                return "<static initializer>";
            else if (IClassDefConstants.INIT_NAME.equals (methodVMName))
                out.append (className);
            else
                out.append (methodVMName);
        }
        else
        {
            if (IClassDefConstants.CLINIT_NAME.equals (methodVMName))
                return IClassDefConstants.CLINIT_NAME;
            else
                out.append (methodVMName);
        }
        
        final char [] chars = descriptor.toCharArray ();
        int end;
        
        out.append (" (");
        {
            for (end = chars.length; chars [-- end] != ')"; );
            
            for (int start = 1; start < end; )
            {
                if (start > 1) out.append (", ");
                start = typeDescriptorToJavaName (chars, start, shortTypeNames, out);
            }
        }        
        
        if (appendReturnType)
        {
            out.append ("): ");
            
            typeDescriptorToJavaName (chars, end + 1, shortTypeNames, out);
        }
        else
        {
            out.append (')");
        }
        
        return out.toString ();
    
private static inttypeDescriptorToJavaName(char[] descriptor, int start, boolean shortTypeNames, java.lang.StringBuffer out)

        int dims;
        for (dims = 0; descriptor [start] == '["; ++ dims, ++ start);
        
        char c = descriptor [start ++]; 
        switch (c)
        {
            case 'L":
            {
                if (shortTypeNames)
                {
                    int lastSlash = -1;
                    for (int s = start; descriptor [s] != ';"; ++ s)
                    {
                        if (descriptor [s] == '/") lastSlash = s;
                    }
                    
                    for (start = lastSlash > 0 ? lastSlash + 1 : start; descriptor [start] != ';"; ++ start)
                    {
                        c = descriptor [start];
                        if (RENAME_INNER_CLASSES)
                            out.append (c != '$" ? c : '.");
                        else
                            out.append (c);
                    }                        
                }
                else
                {
                    for (; descriptor [start] != ';"; ++ start)
                    {
                        c = descriptor [start];
                        out.append (c != '/" ? c : '.");
                    }
                }
                
                ++ start;
            }
            break;
            
            case 'B": out.append ("byte"); break;
            case 'C": out.append ("char"); break;
            case 'D": out.append ("double"); break;
            case 'F": out.append ("float"); break;
            case 'I": out.append ("int"); break;
            case 'J": out.append ("long"); break;
            case 'S": out.append ("short"); break;
            case 'Z": out.append ("boolean"); break;
            
            case 'V": out.append ("void"); break;
            
            default:          
                throw new IllegalStateException ("unknown type descriptor element: " + c);
                
        } // end of switch
        
        if (dims > 0)
        {
            out.append (' ");
            for (int d = 0; d < dims; ++ d) out.append ("[]");
        }
        
        return start;
    
public static java.lang.StringvmNameToJavaName(java.lang.String vmName)
Converts a JVM package/class name to how it would be represented in Java.

Example:


vmNameToJavaName("java/lang/Object") = "java.lang.Object"

see
#javaNameToVMName

        if (vmName == null) return null;
        
        return vmName.replace ('/", '.");