Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import com.google.common.collect.BiMap;

public class Main {
    private static BiMap<String, String> smaliPrimitiveToJavaWrapper;
    private static BiMap<String, String> smaliPrimitiveToJavaName;

    public static boolean isPrimitiveOrWrapperType(String type) {
        return isPrimitiveType(type) || isWrapperType(type);
    }

    public static boolean isPrimitiveType(String type) {
        return smaliPrimitiveToJavaName.containsKey(getBaseClass(type));
    }

    public static boolean isWrapperType(String type) {
        return smaliWrapperToSmaliPrimitive(type) != null;
    }

    public static String getBaseClass(String className) {
        // Remove any array qualifiers, e.g. [[B (2d byte array) becomes B
        return className.replace("[", "");
    }

    public static String smaliWrapperToSmaliPrimitive(String type) {
        String javaType = smaliClassToJava(type);

        return smaliPrimitiveToJavaWrapper.inverse().get(javaType);
    }

    public static String smaliClassToJava(String className) {
        if (className.startsWith("[")) {
            return className.replaceAll("/", "\\.");
        }

        String javaName = smaliPrimitiveToJavaName.get(className);
        if (null != javaName) {
            // e.g. "I" -> "int"
            return javaName;
        }

        if (className.equals("?")) {
            // Probably lazy and didn't determine type.
            // This will probably result in a Class.forName exception.
            return className;
        }

        // Java doesn't like Lcom/package/class;, it wants "com.package.class"
        return className.substring(1, className.length() - 1).replaceAll("/", ".");
    }
}