Search in sources :

Example 11 with BLangNode

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

the class ServiceContextItemSorter method sortItems.

@Override
public void sortItems(TextDocumentServiceContext ctx, List<CompletionItem> completionItems) {
    BLangNode previousNode = ctx.get(CompletionKeys.PREVIOUS_NODE_KEY);
    /*
        Remove the statement type completion type. When the going through the parser
        rule contexts such as typeNameContext, we add the statements as well.
        Sorters are responsible for to the next level of such filtering.
         */
    this.removeCompletionsByType(new ArrayList<>(Collections.singletonList(ItemResolverConstants.STATEMENT_TYPE)), completionItems);
    if (previousNode == null) {
        this.populateWhenCursorBeforeOrAfterEp(completionItems);
    } else if (previousNode instanceof BLangVariableDef) {
        // BType bLangType = ((BLangVariableDef) previousNode).var.type;
        // if (bLangType instanceof BEndpointType) {
        // this.populateWhenCursorBeforeOrAfterEp(completionItems);
        // } else {
        this.setPriorities(completionItems);
        CompletionItem resItem = this.getResourceSnippet();
        resItem.setSortText(Priority.PRIORITY160.toString());
        completionItems.add(resItem);
    // }
    } else if (previousNode instanceof BLangResource) {
        completionItems.clear();
        completionItems.add(this.getResourceSnippet());
    }
}
Also used : BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) CompletionItem(org.eclipse.lsp4j.CompletionItem) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)

Example 12 with BLangNode

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

the class SymbolEnter method defineNode.

public void defineNode(BLangNode node, SymbolEnv env) {
    SymbolEnv prevEnv = this.env;
    this.env = env;
    node.accept(this);
    this.env = prevEnv;
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 13 with BLangNode

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

the class TaintAnalyzer method visit.

public void visit(BLangPackage pkgNode) {
    if (pkgNode.completedPhases.contains(CompilerPhase.TAINT_ANALYZE)) {
        return;
    }
    SymbolEnv pkgEnv = symTable.pkgEnvMap.get(pkgNode.symbol);
    SymbolEnv prevPkgEnv = this.currPkgEnv;
    this.currPkgEnv = pkgEnv;
    this.env = pkgEnv;
    pkgNode.imports.forEach(impPkgNode -> impPkgNode.accept(this));
    pkgNode.topLevelNodes.forEach(e -> ((BLangNode) e).accept(this));
    // Do table generation for blocked invokables after all the import packages are scanned.
    if (this.mainPkgEnv.equals(pkgEnv)) {
        initialAnalysisComplete = true;
        resolveBlockedInvokable();
        initialAnalysisComplete = false;
    }
    this.currPkgEnv = prevPkgEnv;
    pkgNode.completedPhases.add(CompilerPhase.TAINT_ANALYZE);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 14 with BLangNode

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

the class CodeAnalyzer method visit.

@Override
public void visit(BLangPackage pkgNode) {
    if (pkgNode.completedPhases.contains(CompilerPhase.CODE_ANALYZE)) {
        return;
    }
    SymbolEnv pkgEnv = symTable.pkgEnvMap.get(pkgNode.symbol);
    pkgNode.imports.forEach(impPkgNode -> analyzeNode(impPkgNode, pkgEnv));
    pkgNode.topLevelNodes.forEach(topLevelNode -> analyzeNode((BLangNode) topLevelNode, pkgEnv));
    pkgNode.completedPhases.add(CompilerPhase.CODE_ANALYZE);
}
Also used : BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 15 with BLangNode

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

the class Types method checkForeachTypes.

List<BType> checkForeachTypes(BLangNode collection, int variableSize) {
    BType collectionType = collection.type;
    List<BType> errorTypes;
    int maxSupportedTypes;
    switch(collectionType.tag) {
        case TypeTags.ARRAY:
            BArrayType bArrayType = (BArrayType) collectionType;
            if (variableSize == 1) {
                return Lists.of(bArrayType.eType);
            } else if (variableSize == 2) {
                return Lists.of(symTable.intType, bArrayType.eType);
            } else {
                maxSupportedTypes = 2;
                errorTypes = Lists.of(symTable.intType, bArrayType.eType);
            }
            break;
        case TypeTags.MAP:
            BMapType bMapType = (BMapType) collectionType;
            if (variableSize == 1) {
                return Lists.of(bMapType.constraint);
            } else if (variableSize == 2) {
                return Lists.of(symTable.stringType, bMapType.constraint);
            } else {
                maxSupportedTypes = 2;
                errorTypes = Lists.of(symTable.stringType, bMapType.constraint);
            }
            break;
        case TypeTags.JSON:
            if (variableSize == 1) {
                return Lists.of(symTable.jsonType);
            } else {
                maxSupportedTypes = 1;
                errorTypes = Lists.of(symTable.jsonType);
            }
            break;
        case TypeTags.XML:
            if (variableSize == 1) {
                return Lists.of(symTable.xmlType);
            } else if (variableSize == 2) {
                return Lists.of(symTable.intType, symTable.xmlType);
            } else {
                maxSupportedTypes = 2;
                errorTypes = Lists.of(symTable.intType, symTable.xmlType);
            }
            break;
        case TypeTags.TABLE:
            BTableType tableType = (BTableType) collectionType;
            if (variableSize == 1) {
                return Lists.of(tableType.constraint);
            } else {
                maxSupportedTypes = 1;
                errorTypes = Lists.of(tableType.constraint);
            }
            break;
        case TypeTags.ERROR:
            return Collections.nCopies(variableSize, symTable.errType);
        default:
            dlog.error(collection.pos, DiagnosticCode.ITERABLE_NOT_SUPPORTED_COLLECTION, collectionType);
            return Collections.nCopies(variableSize, symTable.errType);
    }
    dlog.error(collection.pos, DiagnosticCode.ITERABLE_TOO_MANY_VARIABLES, collectionType);
    errorTypes.addAll(Collections.nCopies(variableSize - maxSupportedTypes, symTable.errType));
    return errorTypes;
}
Also used : BMapType(org.wso2.ballerinalang.compiler.semantics.model.types.BMapType) BArrayType(org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BTableType(org.wso2.ballerinalang.compiler.semantics.model.types.BTableType)

Aggregations

BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)17 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)13 ArrayList (java.util.ArrayList)7 CompletionItem (org.eclipse.lsp4j.CompletionItem)7 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)7 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)5 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)5 List (java.util.List)4 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)4 TextDocumentServiceContext (org.ballerinalang.langserver.TextDocumentServiceContext)3 BLangAction (org.wso2.ballerinalang.compiler.tree.BLangAction)3 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)3 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)3 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)3 Arrays (java.util.Arrays)2 Map (java.util.Map)2 Stack (java.util.Stack)2 Collectors (java.util.stream.Collectors)2 Token (org.antlr.v4.runtime.Token)2 TokenStream (org.antlr.v4.runtime.TokenStream)2