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; }
public static String getSQLType(BType value) { int tag = value.getTag(); switch (tag) { case TypeTags.INT_TAG: return Constants.SQLDataTypes.BIGINT; case TypeTags.STRING_TAG: return Constants.SQLDataTypes.VARCHAR; case TypeTags.FLOAT_TAG: return Constants.SQLDataTypes.DOUBLE; case TypeTags.BOOLEAN_TAG: return Constants.SQLDataTypes.BOOLEAN; default: throw new BallerinaException( "unsupported data type as direct value for sql operation, use sql:Parameter: " + value.getName()); } }
/** * Returns the system property which corresponds to the given key. * * @param key system property key * @return system property as a {@link BValue} or {@code BTypes.typeString.getZeroValue()} if the property does not * exist. */ public static BValue getSystemProperty(String key) { String value = System.getProperty(key); if (value == null) { return BTypes.typeString.getZeroValue(); } return new BString(value); }
/** * This method is for use as the first check in checking for cast/assignability for two types. * Checks whether the source type is the same as the target type or if the target type is any type, and if true * the return value would be true. * * @param rhsType the source type - the type (of the value) being cast/assigned * @param lhsType the target type against which cast/assignability is checked * @return true if the lhsType is any or is the same as rhsType */ private static boolean isSameOrAnyType(BType rhsType, BType lhsType) { return (lhsType.getTag() == TypeTags.ANY_TAG && rhsType.getTag() != TypeTags.ERROR_TAG) || rhsType .equals(lhsType); }
/** * Get full service name with the package path. * * @param serviceInfoType service info type * @return full qualified service name */ private static String getFullServiceName(BType serviceInfoType) { return serviceInfoType.getPackagePath().equals(PACKAGE_SEPARATOR) ? serviceInfoType.getName() : serviceInfoType.getPackagePath() + PACKAGE_SEPARATOR + serviceInfoType.getName(); }
private static String getBTypeListAsString(BType[] typeNames) { StringBuffer br = new StringBuffer(); int i = 0; for (BType type : typeNames) { br.append(type.getName()); if (++i < typeNames.length) { br.append(","); } } return br.toString(); }
public BValueArray(BType type) { if (type.getTag() == TypeTags.INT_TAG) { intValues = (long[]) newArrayInstance(Long.TYPE); setArrayElementType(type); } else if (type.getTag() == TypeTags.BOOLEAN_TAG) { booleanValues = (int[]) newArrayInstance(Integer.TYPE); setArrayElementType(type); } else if (type.getTag() == TypeTags.BYTE_TAG) { byteValues = (byte[]) newArrayInstance(Byte.TYPE); setArrayElementType(type); } else if (type.getTag() == TypeTags.FLOAT_TAG) { floatValues = (double[]) newArrayInstance(Double.TYPE); setArrayElementType(type); } else if (type.getTag() == TypeTags.STRING_TAG) { stringValues = (String[]) newArrayInstance(String.class); Arrays.fill(stringValues, BLangConstants.STRING_EMPTY_VALUE); } else { super.arrayType = type; if (type.getTag() == TypeTags.ARRAY_TAG) { BArrayType arrayType = (BArrayType) type; this.elementType = arrayType.getElementType(); Arrays.fill(refValues, arrayType.getElementType().getZeroValue()); } else if (type.getTag() == TypeTags.TUPLE_TAG) { BTupleType tupleType = (BTupleType) type; this.size = maxArraySize = tupleType.getTupleTypes().size(); AtomicInteger counter = new AtomicInteger(0); tupleType.getTupleTypes().forEach(memType ->
@Override public String stringValue() { return typeValue.toString(); }
public boolean equals(Object obj) { if (obj instanceof BType) { BType other = (BType) obj; boolean namesEqual = this.typeName.equals(other.getName()); // If both package paths are null or both package paths are not null, // then check their names. If not return false if (this.pkgPath == null && other.getPackagePath() == null) { return namesEqual; } else if (this.pkgPath != null && other.getPackagePath() != null) { return this.pkgPath.equals(other.getPackagePath()) && namesEqual; } } return false; }
public static boolean isRequestStruct(BMap<String, BValue> struct) { return struct.getType().getName().equals(REQUEST); }
@Override public int hashCode() { return Objects.hash(type.toString()); }
private static boolean isSameType(BType rhsType, BType lhsType) { // First check whether both references points to the same object. if (rhsType == lhsType || rhsType.equals(lhsType)) { return true; } if (rhsType.getTag() == lhsType.getTag() && rhsType.getTag() == TypeTags.ARRAY_TAG) { return checkArrayEquivalent(rhsType, lhsType); } // TODO Support function types, json/map constrained types etc. if (rhsType.getTag() == TypeTags.MAP_TAG && lhsType.getTag() == TypeTags.MAP_TAG) { return lhsType.equals(rhsType); } return false; }
private static boolean isSimpleBasicType(BType type) { return type.getTag() < TypeTags.JSON_TAG; }
@Override public void execute(Context context) { BValue entityBody = context.getRefArgument(0); Checksum checksum = new CRC32(); byte[] bytes; long checksumVal; BType argType = entityBody.getType(); if (argType == BTypes.typeJSON || argType == BTypes.typeXML || argType == BTypes.typeString) { // TODO: Look at the possibility of making the encoding configurable bytes = entityBody.stringValue().getBytes(StandardCharsets.UTF_8); } else if (argType.getTag() == TypeTags.ARRAY_TAG && ((BArrayType) argType).getElementType().getTag() == TypeTags.BYTE_TAG) { bytes = ((BValueArray) entityBody).getBytes(); } else { throw new BallerinaException( "failed to generate hash: unsupported data type: " + entityBody.getType().getName()); } checksum.update(bytes, 0, bytes.length); checksumVal = checksum.getValue(); context.setReturnValues(new BString(Long.toHexString(checksumVal))); } }
public static String getFullServiceName(ServiceInfo serviceInfo) { BType serviceInfoType = serviceInfo.getType(); return serviceInfoType.getPackagePath().equals(PACKAGE_SEPARATOR) ? serviceInfoType.getName() : serviceInfoType.getPackagePath() + PACKAGE_SEPARATOR + serviceInfoType.getName(); }
private static boolean isResponseStruct(BMap<String, BValue> struct) { return struct.getType().getName().equals(HttpConstants.RESPONSE); }
@Override public int hashCode() { return super.toString().hashCode(); }