protected boolean isNonNilReturnable() { // All functions are now considered as returnable. So in here, what we check is whether the function actually // returns a value other than nil. if (this.responseTypes.length == 1 && this.responseTypes[0].getTag() == TypeTags.NULL_TAG) { return false; } return this.responseTypes.length > 0; }
private static boolean checkIsFiniteType(BType sourceType, BFiniteType targetType, List<TypePair> unresolvedTypes) { if (sourceType.getTag() != TypeTags.FINITE_TYPE_TAG) { return false; } BFiniteType sourceFiniteType = (BFiniteType) sourceType; if (sourceFiniteType.valueSpace.size() != targetType.valueSpace.size()) { return false; } return sourceFiniteType.valueSpace.stream().allMatch(value -> targetType.valueSpace.contains(value)); }
/** * Check whether provided JSON object is a JSON Array. * * @param json JSON to execute array condition. * @return returns true if provided JSON is a JSON Array. */ public static boolean isJSONArray(BValue json) { if (json == null) { return false; } return json.getType().getTag() == TypeTags.ARRAY_TAG; }
private static boolean checkTableConstraints(BType sourceConstraint, BType targetConstraint, List<TypePair> unresolvedTypes) { // handle unconstrained tables returned by actions if (sourceConstraint == null) { if (targetConstraint.getTag() == TypeTags.RECORD_TYPE_TAG) { BRecordType targetConstrRecord = (BRecordType) targetConstraint; return !targetConstrRecord.sealed && targetConstrRecord.restFieldType == BTypes.typeAnydata; } return false; } return checkIsType(sourceConstraint, targetConstraint, unresolvedTypes); }
private BType retrieveNonNilType(List<BType> members) { if (members.size() != 2) { throw new BallerinaException(UNASSIGNABLE_UNIONTYPE_EXCEPTION); } if (members.get(0).getTag() == TypeTags.NULL_TAG) { return members.get(1); } else if (members.get(1).getTag() == TypeTags.NULL_TAG) { return members.get(0); } else { throw new BallerinaException(UNASSIGNABLE_UNIONTYPE_EXCEPTION); } }
@Override public void stamp(BType type) { if (type.getTag() == TypeTags.ANYDATA_TAG) { type = BVM.resolveMatchingTypeForUnion(this, type); } this.type = type; }
public void subscribe(InputHandler inputHandler) { if (constraintType.getTag() != TypeTags.OBJECT_TYPE_TAG && constraintType.getTag() != TypeTags.RECORD_TYPE_TAG) { throw new BallerinaException("Streaming Support is only available with streams accepting objects"); } String queueName = String.valueOf(UUID.randomUUID()); brokerInstance.addSubscription(topicName, new InternalStreamSubscriber(topicName, queueName, inputHandler)); }
private void handleDateValue(BMap<String, BValue> bStruct, String fieldName, java.util.Date date, BType fieldType) { int fieldTypeTag = fieldType.getTag(); if (fieldTypeTag == TypeTags.UNION_TAG) { handleMappingDateValueToUnionType(fieldType, bStruct, fieldName, date); } else { handleMappingDateValueToNonUnionType(date, fieldTypeTag, bStruct, fieldName); } }
private static BType getElementType(BType type) { if (type.getTag() != TypeTags.ARRAY_TAG) { return type; } return getElementType(((BArrayType) type).getElementType()); }
private static void checkTransactionCoordinatorError(BValue value, String errMsg) { if (value.getType().getTag() == TypeTags.ERROR_TAG) { throw new BallerinaException(errMsg + ((BError) value).reason); } }
/** * Remove a field from JSON. Has no effect if the JSON if not object types or if the given field doesn't exists. * * @param json JSON object * @param fieldName Name of the field to remove */ public static void remove(BValue json, String fieldName) { if (json == null || json.getType().getTag() != TypeTags.JSON_TAG) { return; } ((BMap<String, ?>) json).remove(fieldName); }
private void validatePathParam(List<ParamDetail> paramDetails) { for (ParamDetail param : paramDetails) { int varTag = param.getVarType().getTag(); if (varTag != TypeTags.STRING_TAG && varTag != TypeTags.INT_TAG && varTag != TypeTags.BOOLEAN_TAG && varTag != TypeTags.FLOAT_TAG) { throw new BallerinaConnectorException("incompatible resource signature parameter type"); } paramCount++; } this.pathParams = paramDetails; }
private static boolean checkIsFutureType(BType sourceType, BFutureType targetType, List<TypePair> unresolvedTypes) { if (sourceType.getTag() != TypeTags.FUTURE_TAG) { return false; } return checkContraints(((BFutureType) sourceType).getConstrainedType(), targetType.getConstrainedType(), unresolvedTypes); }
public void add(long index, int value) { if (elementType.getTag() == TypeTags.INT_TAG) { add(index, (long) value); return; } handleFrozenArrayValue(); prepareForAdd(index, booleanValues.length); booleanValues[(int) index] = value; }
private static boolean checkIsTableType(BType sourceType, BTableType targetType, List<TypePair> unresolvedTypes) { if (sourceType.getTag() != TypeTags.TABLE_TAG) { return false; } return checkTableConstraints(((BTableType) sourceType).getConstrainedType(), targetType.getConstrainedType(), unresolvedTypes); }
/** * This will validate given BValue is an BError and then convert it into * Ballerina exception. This method will be used to validate module life cycle methods. * * @value BValue to be validated. */ private static void validateInvocationError(BValue value) { if (value != null && value.getType().getTag() == TypeTags.ERROR_TAG) { throw new BLangRuntimeException("error: " + BLangVMErrors.getPrintableStackTrace((BError) value)); } } }
private static boolean checkIsMapType(BType sourceType, BMapType targetType, List<TypePair> unresolvedTypes) { if (sourceType.getTag() != TypeTags.MAP_TAG) { return false; } return checkContraints(((BMapType) sourceType).getConstrainedType(), targetType.getConstrainedType(), unresolvedTypes); }
public static Service getServiceFromType(ProgramFile programFile, BValue value) { if (value == null || value.getType().getTag() != TypeTags.SERVICE_TAG) { throw new BallerinaConnectorException("Can't get service reference"); } return getService(programFile, (BMap) value); }
private static boolean checkIsArrayType(BType sourceType, BArrayType targetType, List<TypePair> unresolvedTypes) { if (sourceType.getTag() != TypeTags.ARRAY_TAG) { return false; } BArrayType sourceArrayType = (BArrayType) sourceType; if (sourceArrayType.getState() != targetType.getState() || sourceArrayType.getSize() != targetType.getSize()) { return false; } return checkIsType(sourceArrayType.getElementType(), targetType.getElementType(), unresolvedTypes); }