public static BType fromString(String typeName) { if (typeName.endsWith("[]")) { String elementTypeName = typeName.substring(0, typeName.length() - 2); BType elemType = fromString(elementTypeName); return new BArrayType(elemType); } return getTypeFromName(typeName); } }
private static boolean isDeepStampingRequiredForMap(BType sourceType) { BType constrainedType = ((BMapType) sourceType).getConstrainedType(); if (constrainedType != null) { if (BTypes.isValueType(constrainedType)) { return false; } else if (constrainedType instanceof BMapType) { return isDeepStampingRequiredForMap(constrainedType); } return true; } return true; }
@Override public BType getBuiltinRefType(String typeName) { return BTypes.getTypeFromName(typeName); }
@Override public BType getRefType(char typeChar, String pkgId, String typeName) { if (typeName.isEmpty()) { return null; } PackageInfo packageInfoOfType; if (pkgId != null) { packageInfoOfType = getPackageInfo(pkgId); } else { packageInfoOfType = packageInfo; } switch (typeChar) { case 'X': return BTypes.typeAnyService; default: TypeDefInfo typeDefInfo = packageInfoOfType.getTypeDefInfo(typeName); if (typeDefInfo != null) { return typeDefInfo.typeInfo.getType(); } return BTypes.getTypeFromName(typeName); } }
private static boolean isDeepStampingRequiredForArray(BType sourceType) { BType elementType = ((BArrayType) sourceType).getElementType(); if (elementType != null) { if (BTypes.isValueType(elementType)) { return false; } else if (elementType instanceof BArrayType) { return isDeepStampingRequiredForArray(elementType); } return true; } return true; }
case TypeTags.TYPEDESC_TAG: try { return new BTypeDescValue(getTypeFromName(value)); } catch (IllegalStateException e) { throw new BLangUsageException("invalid argument '" + value + "', unsupported/unknown typedesc "
private static boolean checkIsLikeArrayType(BValue sourceValue, BArrayType targetType) { if (!(sourceValue instanceof BValueArray)) { return false; } BValueArray source = (BValueArray) sourceValue; if (BTypes.isValueType(source.elementType)) { return checkIsType(source.elementType, targetType.getElementType(), new ArrayList<>()); } BType arrayElementType = targetType.getElementType(); BRefType<?>[] arrayValues = source.getValues(); for (int i = 0; i < ((BValueArray) sourceValue).size(); i++) { if (!checkIsLikeType(arrayValues[i], arrayElementType)) { return false; } } return true; }
private static boolean checkIsLikeTupleType(BValue sourceValue, BTupleType targetType) { if (!(sourceValue instanceof BValueArray)) { return false; } BValueArray source = (BValueArray) sourceValue; if (source.size() != targetType.getTupleTypes().size()) { return false; } if (BTypes.isValueType(source.elementType)) { int bound = (int) source.size(); for (int i = 0; i < bound; i++) { if (!checkIsType(source.elementType, targetType.getTupleTypes().get(i), new ArrayList<>())) { return false; } } return true; } int bound = (int) source.size(); for (int i = 0; i < bound; i++) { if (!checkIsLikeType(source.getRefValue(i), targetType.getTupleTypes().get(i))) { return false; } } return true; }
private static void handleConvertBuildInMethod(Strand strand, StackFrame sf, int[] operands) { int i = operands[0]; int cpIndex = operands[1]; int j = operands[2]; TypeRefCPEntry typeRefCPEntry = (TypeRefCPEntry) sf.constPool[cpIndex]; BRefType bRefTypeValue = sf.refRegs[i]; if (bRefTypeValue == null) { sf.refRegs[j] = null; return; } int targetTag = typeRefCPEntry.getType().getTag(); try { if (BTypes.isValueType(bRefTypeValue.getType())) { convertValueTypes(strand, sf, j, typeRefCPEntry, bRefTypeValue, targetTag); return; } if (targetTag == TypeTags.STRING_TAG) { sf.refRegs[j] = new BString(bRefTypeValue.toString()); return; } handleTypeConversionError(strand, sf, j, bRefTypeValue.getType(), typeRefCPEntry.getType()); } catch (RuntimeException e) { handleTypeConversionError(strand, sf, j, bRefTypeValue.getType(), typeRefCPEntry.getType()); } }
private static boolean checkIsLikeJSONType(BValue sourceValue, BJSONType targetType) { if (targetType.getConstrainedType() != null) { return checkIsLikeType(sourceValue, targetType.getConstrainedType()); } else if (sourceValue.getType().getTag() == TypeTags.ARRAY_TAG) { BValueArray source = (BValueArray) sourceValue; if (BTypes.isValueType(source.elementType)) { return checkIsType(source.elementType, targetType, new ArrayList<>()); } BRefType<?>[] arrayValues = source.getValues(); for (int i = 0; i < ((BValueArray) sourceValue).size(); i++) { if (!checkIsLikeType(arrayValues[i], targetType)) { return false; } } } else if (sourceValue.getType().getTag() == TypeTags.MAP_TAG) { for (BValue value : ((BMap) sourceValue).values()) { if (!checkIsLikeType(value, targetType)) { return false; } } } else if (sourceValue.getType().getTag() == TypeTags.RECORD_TYPE_TAG) { for (Object object : ((BMap) sourceValue).getMap().values()) { if (!checkIsLikeType((BValue) object, targetType)) { return false; } } } return true; }
if (mapVal == null && BTypes.isValueType(fieldType)) { throw BLangExceptionHelper.getRuntimeException( RuntimeErrors.INCOMPATIBLE_FIELD_TYPE_FOR_CASTING, key, fieldType, null);