@Override public BType getConstrainedType(char typeChar, BType constraint) { switch (typeChar) { case 'J': if (constraint == null) { return BTypes.typeJSON; } return new BJSONType(constraint); case 'D': if (constraint == null) { return BTypes.typeTable; } return new BTableType(constraint); case 'M': if (constraint == null || constraint == BTypes.typeAny) { return BTypes.typeMap; } return new BMapType(constraint); case 'H': return new BStreamType(constraint); case 'G': case 'T': case 'X': case 'Q': default: return constraint; } }
if (targetType.getConstrainedType() != null) { if (sourceType.getTag() != TypeTags.JSON_TAG) { return false; BType constraintType = ((BJSONType) sourceType).getConstrainedType(); if (constraintType == null) { return false; return checkIsType(constraintType, targetType.getConstrainedType(), unresolvedTypes); case TypeTags.JSON_TAG: return targetType.getConstrainedType() == null; case TypeTags.ARRAY_TAG:
if (targetType.getConstrainedType() == null) { for (Entry<String, BValue> structField : map.getMap().entrySet()) { String key = structField.getKey(); if (!BVM.checkCast(map, targetType.getConstrainedType())) { throw BLangExceptionHelper.getRuntimeException(RuntimeErrors.INCOMPATIBLE_TYPE, targetType, map.getType()); ((BStructureType) targetType.getConstrainedType()).getFields().entrySet()) { String key = fieldEntry.getKey(); BValue value = map.get(key);
private static boolean checkJSONEquivalency(BValue json, BJSONType sourceType, BJSONType targetType, List<TypePair> unresolvedTypes) { BRecordType sourceConstrainedType = (BRecordType) sourceType.getConstrainedType(); BRecordType targetConstrainedType = (BRecordType) targetType.getConstrainedType();
@Override public void stamp(BType type) { if (type.getTag() == TypeTags.JSON_TAG) { if (((BJSONType) type).getConstrainedType() != null) { this.stamp(((BJSONType) type).getConstrainedType()); } else { type = BVM.resolveMatchingTypeForUnion(this, type);
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; }
case TypeTags.JSON_TAG: if (((BJSONType) targetType).getConstrainedType() == null && getElementType(sourceType).getTag() == TypeTags.JSON_TAG) { return true;
return checkCastByType(((BMapType) rhsType).getConstrainedType(), lhsType, unresolvedTypes); case TypeTags.ARRAY_TAG: if (((BJSONType) lhsType).getConstrainedType() != null) { return false;