Search in sources :

Example 1 with BLangUnionTypeNode

use of org.wso2.ballerinalang.compiler.tree.types.BLangUnionTypeNode in project ballerina by ballerina-lang.

the class SymbolResolver method visit.

public void visit(BLangUnionTypeNode unionTypeNode) {
    Set<BType> memberTypes = unionTypeNode.memberTypeNodes.stream().map(memTypeNode -> resolveTypeNode(memTypeNode, env)).flatMap(memBType -> memBType.tag == TypeTags.UNION ? ((BUnionType) memBType).memberTypes.stream() : Stream.of(memBType)).collect(Collectors.toSet());
    resultType = new BUnionType(null, memberTypes, memberTypes.contains(symTable.nullType));
}
Also used : BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BTupleType(org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType) BMapType(org.wso2.ballerinalang.compiler.semantics.model.types.BMapType) BLangTupleTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangTupleTypeNode) Lists(org.wso2.ballerinalang.util.Lists) BLangBuiltInRefTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) BLangValueType(org.wso2.ballerinalang.compiler.tree.types.BLangValueType) OperatorKind(org.ballerinalang.model.tree.OperatorKind) Flag(org.ballerinalang.model.elements.Flag) Map(java.util.Map) SymbolKind(org.ballerinalang.model.symbols.SymbolKind) BOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol) Names(org.wso2.ballerinalang.compiler.util.Names) EnumSet(java.util.EnumSet) BLangDiagnosticLog(org.wso2.ballerinalang.compiler.util.diagnotic.BLangDiagnosticLog) BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) BLangArrayType(org.wso2.ballerinalang.compiler.tree.types.BLangArrayType) BLangUnionTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangUnionTypeNode) TypeKind(org.ballerinalang.model.types.TypeKind) BConversionOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) NOT_FOUND_ENTRY(org.wso2.ballerinalang.compiler.semantics.model.Scope.NOT_FOUND_ENTRY) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) Stream(java.util.stream.Stream) InstructionCodes(org.wso2.ballerinalang.programfile.InstructionCodes) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType) BStreamType(org.wso2.ballerinalang.compiler.semantics.model.types.BStreamType) HashMap(java.util.HashMap) BLangNodeVisitor(org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor) ArrayList(java.util.ArrayList) TypeTags(org.wso2.ballerinalang.compiler.util.TypeTags) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) BLangConstrainedType(org.wso2.ballerinalang.compiler.tree.types.BLangConstrainedType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BFutureType(org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BArrayType(org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) BJSONType(org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) BLangFunctionTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangFunctionTypeNode) Name(org.wso2.ballerinalang.compiler.util.Name) ScopeEntry(org.wso2.ballerinalang.compiler.semantics.model.Scope.ScopeEntry) SymTag(org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag) DiagnosticCode(org.ballerinalang.util.diagnostic.DiagnosticCode) BTableType(org.wso2.ballerinalang.compiler.semantics.model.types.BTableType) BLangType(org.wso2.ballerinalang.compiler.tree.types.BLangType) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType)

Example 2 with BLangUnionTypeNode

use of org.wso2.ballerinalang.compiler.tree.types.BLangUnionTypeNode in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addUnionType.

public void addUnionType(DiagnosticPos pos, Set<Whitespace> ws) {
    BLangType rhsTypeNode = (BLangType) this.typeNodeStack.pop();
    BLangType lhsTypeNode = (BLangType) this.typeNodeStack.pop();
    BLangUnionTypeNode unionTypeNode;
    if (rhsTypeNode.getKind() == NodeKind.UNION_TYPE_NODE) {
        unionTypeNode = (BLangUnionTypeNode) rhsTypeNode;
        unionTypeNode.memberTypeNodes.add(0, lhsTypeNode);
        this.typeNodeStack.push(unionTypeNode);
        return;
    } else {
        unionTypeNode = (BLangUnionTypeNode) TreeBuilder.createUnionTypeNode();
        unionTypeNode.memberTypeNodes.add(lhsTypeNode);
        unionTypeNode.memberTypeNodes.add(rhsTypeNode);
    }
    unionTypeNode.pos = pos;
    unionTypeNode.addWS(ws);
    this.typeNodeStack.push(unionTypeNode);
}
Also used : BLangUnionTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangUnionTypeNode) BLangType(org.wso2.ballerinalang.compiler.tree.types.BLangType)

Aggregations

BLangType (org.wso2.ballerinalang.compiler.tree.types.BLangType)2 BLangUnionTypeNode (org.wso2.ballerinalang.compiler.tree.types.BLangUnionTypeNode)2 ArrayList (java.util.ArrayList)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Flag (org.ballerinalang.model.elements.Flag)1 SymbolKind (org.ballerinalang.model.symbols.SymbolKind)1 OperatorKind (org.ballerinalang.model.tree.OperatorKind)1 TypeKind (org.ballerinalang.model.types.TypeKind)1 DiagnosticCode (org.ballerinalang.util.diagnostic.DiagnosticCode)1 Scope (org.wso2.ballerinalang.compiler.semantics.model.Scope)1 NOT_FOUND_ENTRY (org.wso2.ballerinalang.compiler.semantics.model.Scope.NOT_FOUND_ENTRY)1 ScopeEntry (org.wso2.ballerinalang.compiler.semantics.model.Scope.ScopeEntry)1