Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.LinkedList;
import java.util.List;

import com.google.common.collect.BiMap;

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

    public static String javaClassToSmali(Class<?> klazz) {
        return javaClassToSmali(klazz.getName());
    }

    public static List<String> javaClassToSmali(Class<?>[] classes) {
        List<String> smaliNames = new LinkedList<String>();
        for (Class<?> klazz : classes) {
            smaliNames.add(javaClassToSmali(klazz));
        }

        return smaliNames;
    }

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

        String javaName = smaliPrimitiveToJavaName.inverse().get(className);
        if (null != javaName) {
            return javaName;
        }

        if (className.endsWith(";") || (1 == className.length())) {
            // Already Smali format
            return className;
        }

        return "L" + className.replaceAll("\\.", "/") + ";";
    }
}