Search in sources :

Example 6 with ProgramFileFormatException

use of org.ballerinalang.util.exceptions.ProgramFileFormatException in project ballerina by ballerina-lang.

the class ProgramFileReader method getBTypeFromDescriptor.

private BType getBTypeFromDescriptor(String desc) {
    char ch = desc.charAt(0);
    switch(ch) {
        case 'I':
            return BTypes.typeInt;
        case 'F':
            return BTypes.typeFloat;
        case 'S':
            return BTypes.typeString;
        case 'B':
            return BTypes.typeBoolean;
        case 'Y':
            return BTypes.typeDesc;
        case 'L':
            return BTypes.typeBlob;
        case 'A':
            return BTypes.typeAny;
        case 'R':
            return BTypes.getTypeFromName(desc.substring(1, desc.length() - 1));
        case 'M':
            BType constrainedType = getBTypeFromDescriptor(desc.substring(1));
            if (constrainedType == BTypes.typeAny) {
                return BTypes.typeMap;
            } else {
                return new BMapType(constrainedType);
            }
        case 'C':
        case 'X':
        case 'J':
        case 'T':
        case 'E':
        case 'H':
        case 'Z':
        case 'D':
            String typeName = desc.substring(1, desc.length() - 1);
            String[] parts = typeName.split(":");
            if (parts.length == 1) {
                if (ch == 'J') {
                    return BTypes.typeJSON;
                } else if (ch == 'D') {
                    return BTypes.typeTable;
                } else if (ch == 'H') {
                    // TODO:CHECK
                    return BTypes.typeStream;
                }
            }
            String pkgPath = parts[0];
            String name = parts[1];
            PackageInfo packageInfoOfType = programFile.getPackageInfo(pkgPath);
            if (ch == 'J') {
                return new BJSONType(packageInfoOfType.getStructInfo(name).getType());
            } else if (ch == 'C') {
                return packageInfoOfType.getConnectorInfo(name).getType();
            } else if (ch == 'X') {
                return packageInfoOfType.getServiceInfo(name).getType();
            } else if (ch == 'D') {
                return new BTableType(packageInfoOfType.getStructInfo(name).getType());
            } else if (ch == 'H') {
                return new BStreamType(packageInfoOfType.getStructInfo(name).getType());
            } else if (ch == 'E') {
                return packageInfoOfType.getEnumInfo(name).getType();
            } else {
                return packageInfoOfType.getStructInfo(name).getType();
            }
        case '[':
            BType elemType = getBTypeFromDescriptor(desc.substring(1));
            return new BArrayType(elemType);
        case 'U':
            // TODO : Fix this for type casting.
            return new BFunctionType();
        case 'O':
        case 'P':
            Stack<BType> typeStack = new Stack<BType>();
            createBTypeFromSig(desc.toCharArray(), 0, typeStack, null);
            return typeStack.pop();
        case 'N':
            return BTypes.typeNull;
        default:
            throw new ProgramFileFormatException("unsupported base type char: " + ch);
    }
}
Also used : BArrayType(org.ballerinalang.model.types.BArrayType) BJSONType(org.ballerinalang.model.types.BJSONType) BFunctionType(org.ballerinalang.model.types.BFunctionType) ProgramFileFormatException(org.ballerinalang.util.exceptions.ProgramFileFormatException) BStreamType(org.ballerinalang.model.types.BStreamType) Stack(java.util.Stack) BMapType(org.ballerinalang.model.types.BMapType) BType(org.ballerinalang.model.types.BType) BTableType(org.ballerinalang.model.types.BTableType)

Aggregations

ProgramFileFormatException (org.ballerinalang.util.exceptions.ProgramFileFormatException)6 UTF8CPEntry (org.ballerinalang.util.codegen.cpentries.UTF8CPEntry)4 BType (org.ballerinalang.model.types.BType)3 BArrayType (org.ballerinalang.model.types.BArrayType)2 BFunctionType (org.ballerinalang.model.types.BFunctionType)2 BJSONType (org.ballerinalang.model.types.BJSONType)2 BMapType (org.ballerinalang.model.types.BMapType)2 BStreamType (org.ballerinalang.model.types.BStreamType)2 BTableType (org.ballerinalang.model.types.BTableType)2 ActionRefCPEntry (org.ballerinalang.util.codegen.cpentries.ActionRefCPEntry)2 FloatCPEntry (org.ballerinalang.util.codegen.cpentries.FloatCPEntry)2 ForkJoinCPEntry (org.ballerinalang.util.codegen.cpentries.ForkJoinCPEntry)2 FunctionRefCPEntry (org.ballerinalang.util.codegen.cpentries.FunctionRefCPEntry)2 IntegerCPEntry (org.ballerinalang.util.codegen.cpentries.IntegerCPEntry)2 StructureRefCPEntry (org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry)2 TransformerRefCPEntry (org.ballerinalang.util.codegen.cpentries.TransformerRefCPEntry)2 TypeRefCPEntry (org.ballerinalang.util.codegen.cpentries.TypeRefCPEntry)2 WorkerDataChannelRefCPEntry (org.ballerinalang.util.codegen.cpentries.WorkerDataChannelRefCPEntry)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1