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);
}
}
Aggregations