APISonar


org.wso2.ballerinalang.compiler.util.TypeTags.JSON

> org > wso2 > ballerinalang > compiler > util > TypeTags > JSON
org APIs wso2 APIs ballerinalang APIs compiler APIs util APIs TypeTags APIs JSON APIs

Example 1
public boolean isJSONContext(BType type) {
        if (type.tag == TypeTags.UNION) {
            return ((BUnionType) type).getMemberTypes().stream().anyMatch(memType -> memType.tag == TypeTags.JSON);
        }
        return type.tag == TypeTags.JSON;
    }
Example 2
private static void validateDataBindingParam(BLangFunction resource, List<BLangSimpleVariable> paramDetails,
                                                 DiagnosticLog dlog) {
        BType paramType = paramDetails.get(1).type;
        int paramTypeTag = paramType.tag;
        if (paramTypeTag != TypeTags.STRING && paramTypeTag != TypeTags.JSON &&
                paramTypeTag != TypeTags.XML && paramTypeTag != TypeTags.RECORD &&
                paramTypeTag != TypeTags.FLOAT && paramTypeTag != TypeTags.INT
                && validateArrayType(paramType)) {
            dlog.logDiagnostic(Diagnostic.Kind.ERROR, resource.pos, INVALID_RESOURCE_SIGNATURE_FOR
                    + resource.getName().getValue() + RESOURCE_IN_SERVICE +
                    ": The second parameter can only be an int, float, string, json, xml, byte[] or a record type");
        }
    }
Example 3
private boolean isJSONAssignableType(BType type) {
        int typeTag = getElementType(type).tag;
        return typeTag <= TypeTags.BOOLEAN || typeTag == TypeTags.JSON;
    }
Example 4
private BLangExpression getDefaultValueExpr(BLangAccessExpression expr) {
        BType type = expr.type;
        switch (type.tag) {
            case TypeTags.JSON:
                if (expr.getKind() == NodeKind.INDEX_BASED_ACCESS_EXPR &&
                        ((BLangIndexBasedAccess) expr).indexExpr.type.tag == TypeTags.INT) {
                    return new BLangJSONArrayLiteral(new ArrayList<>(), type);
                }
                return new BLangJSONLiteral(new ArrayList<>(), type);
            case TypeTags.MAP:
                return new BLangMapLiteral(new ArrayList<>(), type);
            default:
                throw new IllegalStateException();
        }
    }
Example 5
private BType checkTypeForIndexBasedAccess(BLangIndexBasedAccess indexBasedAccessExpr, BType actualType) {
        // index based map/record access always returns a nil-able type
        if (actualType.tag == TypeTags.ANY || actualType.tag == TypeTags.JSON) {
            return actualType;
        }

        if (indexBasedAccessExpr.leafNode && indexBasedAccessExpr.lhsVar) {
            return actualType;
        }

        BUnionType type = new BUnionType(null, new LinkedHashSet<>(getTypesList(actualType)), true);
        type.memberTypes.add(symTable.nilType);
        return type;
    }
Example 6
public void visit(BLangArrayLiteral arrayLiteral) {
        arrayLiteral.exprs = rewriteExprs(arrayLiteral.exprs);

        if (arrayLiteral.type.tag == TypeTags.JSON) {
            result = new BLangJSONArrayLiteral(arrayLiteral.exprs, new BArrayType(arrayLiteral.type));
            return;
        } else if (getElementType(arrayLiteral.type).tag == TypeTags.JSON) {
            result = new BLangJSONArrayLiteral(arrayLiteral.exprs, arrayLiteral.type);
            return;
        }
        result = arrayLiteral;
    }
Example 7
private boolean safeNavigateLHS(BLangExpression expr) {
        if (expr.getKind() != NodeKind.FIELD_BASED_ACCESS_EXPR && expr.getKind() != NodeKind.FIELD_BASED_ACCESS_EXPR) {
            return false;
        }

        BLangAccessExpression accessExpr = (BLangAccessExpression) expr;
        if (accessExpr.expr.type.tag == TypeTags.JSON) {
            return accessExpr.expr.type.isNullable();
        }

        return safeNavigateLHS(accessExpr.expr);
    }
Example 8
private boolean jsonEqualityIntersectionExists(BJSONType jsonType, Set<BType> typeSet) {
        if (typeSet.stream().anyMatch(rhsMemberType -> rhsMemberType.tag == TypeTags.JSON ||
                rhsMemberType.tag == TypeTags.STRING || rhsMemberType.tag == TypeTags.INT ||
                rhsMemberType.tag == TypeTags.FLOAT || rhsMemberType.tag == TypeTags.BOOLEAN ||
                rhsMemberType.tag == TypeTags.NIL)) {
            return true;
        }

        // We only reach here, if unconstrained and at this point it is guaranteed that the map/record is anydata
        if (typeSet.stream().anyMatch(typeToCheck -> typeToCheck.tag == TypeTags.MAP ||
                typeToCheck.tag == TypeTags.RECORD)) {
            return true;
        }
        return false;
    }
Example 9
private BType getTypeOfIndexBasedAccessExpr(BType bType) {
        switch (bType.tag) {
            case TypeTags.ARRAY:
            case TypeTags.JSON:
            case TypeTags.MAP:
            case TypeTags.OBJECT:
            case TypeTags.RECORD:
            case TypeTags.TUPLE:
            case TypeTags.XML:
                return bType;
            default:
                // If its any other type return the any|error.
                return BUnionType.create(null, symTable.anyType, symTable.errorType);
        }
    }
Example 10
private boolean isNilable(BLangAccessExpression accessExpr, BType actualType) {
        BType parentType = accessExpr.expr.type;
        if (parentType.isNullable() && parentType.tag != TypeTags.JSON) {
            return true;
        }

        // Check whether this is a map access by index. If so, null is a possible return type.
        if (parentType.tag != TypeTags.MAP) {
            return false;
        }

        // TODO: make map access with index, returns nullable type
        // return accessExpr.getKind() == NodeKind.INDEX_BASED_ACCESS_EXPR;
        return false;
    }
Example 11
public void visit(BLangConstrainedType constrainedTypeNode) {
        BType type = resolveTypeNode(constrainedTypeNode.type, env);
        BType constraintType = resolveTypeNode(constrainedTypeNode.constraint, env);
        if (type.tag == TypeTags.TABLE) {
            resultType = new BTableType(TypeTags.TABLE, constraintType, type.tsymbol);
        } else {
            if (!types.checkStructToJSONCompatibility(constraintType) && constraintType != symTable.errType) {
                dlog.error(constrainedTypeNode.pos, DiagnosticCode.INCOMPATIBLE_TYPE_CONSTRAINT, type, constraintType);
                resultType = symTable.errType;
                return;
            }
            resultType = new BJSONType(TypeTags.JSON, constraintType, type.tsymbol);
        }
    }