Example usage for org.apache.commons.bcel6.classfile Utility methodSignatureReturnType

List of usage examples for org.apache.commons.bcel6.classfile Utility methodSignatureReturnType

Introduction

In this page you can find the example usage for org.apache.commons.bcel6.classfile Utility methodSignatureReturnType.

Prototype

public static String methodSignatureReturnType(String signature) throws ClassFormatException 

Source Link

Usage

From source file:ru.objective.jni.tasks.builders.AbstractBuilder.java

protected String getHeaderDeclarationMethod(MethodExportInfo info, Method method, boolean overloaded) {
    StringBuilder stringBuilder = new StringBuilder();
    String[] argumentTypes = Utility.methodSignatureArgumentTypes(method.getSignature());
    String name = info.name;/*from   w  ww.j  a  va 2s.c  om*/

    String methodReturnType = null;

    if (Utils.isConstructor(method)) {
        methodReturnType = "instancetype";

        if (name.equals("<init>"))
            name = "init";
    } else {
        if (Utils.isOccupiedWord(name)) {
            name = "_" + name;
        }

        methodReturnType = Utility.methodSignatureReturnType(method.getSignature()).toString();

        methodReturnType = Utils.getBasicType(methodReturnType);

        if (!Utils.isPrimitive(method.getReturnType())) {
            JavaClass typeJavaClass = OJNIClassLoader.getInstance()
                    .loadClass(method.getReturnType().toString());

            if (typeJavaClass != null && typeJavaClass.isInterface())
                methodReturnType = "id <" + getPrefix() + Utils.getShortClassName(methodReturnType) + ">";
            else
                methodReturnType = getPrefix() + Utils.getShortClassName(methodReturnType) + " *";
        }

        if (Utils.isArrayType(method.getReturnType()))
            methodReturnType = getStringArrayType(methodReturnType, (ArrayType) method.getReturnType());
        else
            methodReturnType = PrimitiveTypeConverter.convertToOBJCType(methodReturnType);
    }
    stringBuilder.append((method.isStatic() ? "+" : "-") + " " + "("
            + PrimitiveTypeConverter.convertToOBJCType(methodReturnType) + ")");

    String[] nameParameters = name.split(":");

    if (info.isCustom)
        overloaded = false;

    LocalVariableTable table = method.getLocalVariableTable();

    if (argumentTypes.length == 0)
        stringBuilder.append(name);

    for (int i = 0, var_index = (method.isStatic() ? 0 : 1); i < argumentTypes.length; i++, var_index++) {
        Type javaType = method.getArgumentTypes()[i];
        String type = argumentTypes[i];

        String variable_name = "";
        if (table == null) {
            variable_name = "arg" + var_index;
        } else {
            LocalVariable lv = table.getLocalVariable(var_index, 0);
            if (lv != null) {
                variable_name = lv.getName();
            }
        }

        if (javaType.equals(Type.LONG) || javaType.equals(Type.DOUBLE))
            var_index++;

        String nameParameter = (i < nameParameters.length ? nameParameters[i] : variable_name);

        type = Utils.getBasicType(type);

        String overloadedParameter = "";

        if (overloaded) {
            overloadedParameter = "With" + (i == 0 ? StringUtils.capitalize(variable_name) : "")
                    + Utils.getShortClassName(type);/*+ StringUtils.capitalize(utils.getShortClassName(type));*/
        }

        if (!Utils.isPrimitive(javaType)) {
            JavaClass argTypeJavaClass = OJNIClassLoader.getInstance().loadClass(javaType.toString());

            if (argTypeJavaClass != null && argTypeJavaClass.isInterface())
                type = "id <" + getPrefix() + Utils.getShortClassName(type) + ">";
            else
                type = getPrefix() + Utils.getShortClassName(type) + " *";
        }

        if (Utils.isArrayType(javaType)) {
            if (overloaded) {
                int dimensions = ((ArrayType) javaType).getDimensions();

                if (dimensions > 1)
                    overloadedParameter += dimensions + "dimArray";
                else
                    overloadedParameter += "Array";
            }
            type = getStringArrayType(type, (ArrayType) javaType);
        } else {
            type = PrimitiveTypeConverter.convertToOBJCType(type);
        }

        if (Utils.isOccupiedWord(variable_name)) {
            variable_name = "_" + variable_name;
        }

        stringBuilder.append(nameParameter + overloadedParameter + ":(" + type + ")" + variable_name + " ");
    }

    stringBuilder.append(";");

    return stringBuilder.toString();
}