public static String mangleMethod(MethodDoc method, RootDoc root, ClassDoc clazz,
                                      int mtype) {
        StringBuffer result = new StringBuffer(100);
        result.append("Java_");

        if (mtype == Mangle.Type.METHOD_JDK_1) {
            result.append(mangle(clazz.qualifiedName(), Mangle.Type.CLASS));
            result.append('_');
            result.append(mangle(method.name(),
                                 Mangle.Type.FIELD));
            result.append("_stub");
            return result.toString();
        }

        /* JNI */
        result.append(mangle(getInnerQualifiedName(clazz), Mangle.Type.JNI));
        result.append('_');
        result.append(mangle(method.name(),
                             Mangle.Type.JNI));
        if (mtype == Mangle.Type.METHOD_JNI_LONG) {
            result.append("__");
            String typesig = method.signature();
            TypeSignature newTypeSig = new TypeSignature(root);
            String sig = newTypeSig.getTypeSignature(typesig,  method.returnType());
            sig = sig.substring(1);
            sig = sig.substring(0, sig.lastIndexOf(')'));
            sig = sig.replace('/', '.');
            result.append(mangle(sig, Mangle.Type.JNI));
        }

        return result.toString();
    }