Java Type Convert typeToTyperef(Class type)

Here you can find the source of typeToTyperef(Class type)

Description

Converts type to type ref.

License

Open Source License

Declaration

public static String typeToTyperef(Class type) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w  ww  .  j a  v a2 s.c o m
     * Converts type to type ref.
     */
    public static String typeToTyperef(Class type) {
        if (type.isArray() == false) {
            if (type.isPrimitive() == false) {
                return 'L' + typeToSignature(type) + ';';
            }
            if (type == int.class) {
                return "I";
            }
            if (type == long.class) {
                return "J";
            }
            if (type == boolean.class) {
                return "Z";
            }
            if (type == double.class) {
                return "D";
            }
            if (type == float.class) {
                return "F";
            }
            if (type == short.class) {
                return "S";
            }
            if (type == void.class) {
                return "V";
            }
            if (type == byte.class) {
                return "B";
            }
            if (type == char.class) {
                return "C";
            }
        }

        return type.getName();
    }

    /**
     * Converts class name ("foo.Bar") to signature ("foo/bar").
     */
    public static String typeToSignature(String className) {
        return className.replace('.', '/');
    }

    /**
     * Converts class name ("foo.Bar") to asm name ("foo/bar").
     */
    public static String typeToSignature(Class type) {
        return type.getName().replace('.', '/');
    }
}

Related

  1. typeToSignature(String type)
  2. typeToSimpleName(String typeName)
  3. TypeToString(int typeNum)
  4. typeToString(Object o)
  5. typeToTag(String TheType)
  6. typeToUnboxedType(Class type)
  7. typeToVMSignature(final String type)