Search in sources :

Example 1 with BLangXMLSequenceLiteral

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLSequenceLiteral in project ballerina by ballerina-lang.

the class Desugar method getInitExpr.

private BLangExpression getInitExpr(BType type) {
    // Don't need to create an empty init expressions if the type allows null.
    if (type.isNullable()) {
        return null;
    }
    switch(type.tag) {
        case TypeTags.INT:
        case TypeTags.FLOAT:
        case TypeTags.BOOLEAN:
        case TypeTags.STRING:
        case TypeTags.BLOB:
            // Int, float, boolean, string, blob types will get default values from VM side.
            break;
        case TypeTags.JSON:
            return new BLangJSONLiteral(new ArrayList<>(), type);
        case TypeTags.XML:
            return new BLangXMLSequenceLiteral(type);
        case TypeTags.TABLE:
            return new BLangTableLiteral(type);
        case TypeTags.STREAM:
            return new BLangStreamLiteral(type, null);
        case TypeTags.MAP:
            return new BLangMapLiteral(new ArrayList<>(), type);
        case TypeTags.STRUCT:
            if (((BStructSymbol) type.tsymbol).isObject) {
                return new BLangTypeInit();
            }
            return new BLangStructLiteral(new ArrayList<>(), type);
        case TypeTags.ARRAY:
            BLangArrayLiteral array = new BLangArrayLiteral();
            array.exprs = new ArrayList<>();
            array.type = type;
            return rewriteExpr(array);
        default:
            break;
    }
    return null;
}
Also used : BLangTypeInit(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeInit) BLangStructLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangStructLiteral) BLangXMLSequenceLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLSequenceLiteral) BLangStreamLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangStreamLiteral) BLangMapLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangMapLiteral) BLangArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral) BLangJSONLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangJSONLiteral) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) BLangTableLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangTableLiteral)

Aggregations

BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)1 BLangArrayLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral)1 BLangJSONLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangJSONLiteral)1 BLangMapLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangMapLiteral)1 BLangStreamLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangStreamLiteral)1 BLangStructLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangStructLiteral)1 BLangTableLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangTableLiteral)1 BLangTypeInit (org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeInit)1 BLangXMLSequenceLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLSequenceLiteral)1