Search in sources :

Example 6 with BTypeSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol in project ballerina by ballerina-lang.

the class SymbolEnter method visit.

@Override
public void visit(BLangStruct structNode) {
    BSymbol structSymbol = Symbols.createStructSymbol(Flags.asMask(structNode.flagSet), names.fromIdNode(structNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
    structNode.symbol = structSymbol;
    // Create struct type
    structNode.symbol.type = new BStructType((BTypeSymbol) structNode.symbol);
    defineSymbol(structNode.pos, structSymbol);
}
Also used : BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)

Example 7 with BTypeSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol in project ballerina by ballerina-lang.

the class SymbolEnter method visit.

@Override
public void visit(BLangObject objectNode) {
    BSymbol objectSymbol = Symbols.createObjectSymbol(Flags.asMask(objectNode.flagSet), names.fromIdNode(objectNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
    objectNode.symbol = objectSymbol;
    // Create struct type
    objectNode.symbol.type = new BStructType((BTypeSymbol) objectNode.symbol);
    defineSymbol(objectNode.pos, objectSymbol);
}
Also used : BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)

Example 8 with BTypeSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol in project ballerina by ballerina-lang.

the class SymbolEnter method visit.

@Override
public void visit(BLangEnum enumNode) {
    BTypeSymbol enumSymbol = Symbols.createEnumSymbol(Flags.asMask(enumNode.flagSet), names.fromIdNode(enumNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
    enumNode.symbol = enumSymbol;
    defineSymbol(enumNode.pos, enumSymbol);
    BEnumType enumType = new BEnumType(enumSymbol, null);
    enumSymbol.type = enumType;
    SymbolEnv enumEnv = SymbolEnv.createPkgLevelSymbolEnv(enumNode, enumSymbol.scope, this.env);
    for (int i = 0; i < enumNode.enumerators.size(); i++) {
        BLangEnumerator enumerator = enumNode.enumerators.get(i);
        BVarSymbol enumeratorSymbol = new BVarSymbol(Flags.PUBLIC, names.fromIdNode(enumerator.name), enumSymbol.pkgID, enumType, enumSymbol);
        enumeratorSymbol.docTag = DocTag.FIELD;
        enumerator.symbol = enumeratorSymbol;
        if (symResolver.checkForUniqueSymbol(enumerator.pos, enumEnv, enumeratorSymbol, enumeratorSymbol.tag)) {
            enumEnv.scope.define(enumeratorSymbol.name, enumeratorSymbol);
        }
    }
}
Also used : BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangEnumerator(org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BEnumType(org.wso2.ballerinalang.compiler.semantics.model.types.BEnumType)

Example 9 with BTypeSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol in project ballerina by ballerina-lang.

the class ParserRuleVariableDefinitionStatementContextResolver method resolveItems.

@Override
@SuppressWarnings("unchecked")
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
    ArrayList<CompletionItem> completionItems = new ArrayList<>();
    PackageActionFunctionAndTypesFilter actionFunctionTypeFilter = new PackageActionFunctionAndTypesFilter();
    ConnectorInitExpressionItemFilter connectorInitItemFilter = new ConnectorInitExpressionItemFilter();
    // action invocation or worker invocation
    if (isInvocationOrFieldAccess(completionContext)) {
        ArrayList<SymbolInfo> actionAndFunctions = new ArrayList<>();
        actionAndFunctions.addAll(actionFunctionTypeFilter.filterItems(completionContext));
        this.populateCompletionItemList(actionAndFunctions, completionItems);
    } else {
        // Fill completions if user is writing a connector init
        List<SymbolInfo> filteredConnectorInitSuggestions = connectorInitItemFilter.filterItems(completionContext);
        if (!filteredConnectorInitSuggestions.isEmpty()) {
            populateCompletionItemList(filteredConnectorInitSuggestions, completionItems);
        }
        // Add the create keyword
        CompletionItem createKeyword = new CompletionItem();
        createKeyword.setInsertText(Snippet.CREATE_KEYWORD_SNIPPET.toString());
        createKeyword.setLabel(ItemResolverConstants.CREATE_KEYWORD);
        createKeyword.setDetail(ItemResolverConstants.KEYWORD_TYPE);
        List<SymbolInfo> filteredList = completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY).stream().filter(symbolInfo -> {
            BSymbol bSymbol = symbolInfo.getScopeEntry().symbol;
            SymbolKind symbolKind = bSymbol.kind;
            // Here we return false if the BType is not either a package symbol or ENUM
            return !((bSymbol instanceof BTypeSymbol) && !(bSymbol instanceof BPackageSymbol || SymbolKind.ENUM.equals(symbolKind)));
        }).collect(Collectors.toList());
        // Remove the functions without a receiver symbol
        filteredList.removeIf(symbolInfo -> {
            BSymbol bSymbol = symbolInfo.getScopeEntry().symbol;
            return bSymbol instanceof BInvokableSymbol && ((BInvokableSymbol) bSymbol).receiverSymbol != null;
        });
        populateCompletionItemList(filteredList, completionItems);
        completionItems.add(createKeyword);
    }
    Class sorterKey = completionContext.get(DocumentServiceKeys.PARSER_RULE_CONTEXT_KEY).getClass();
    CompletionItemSorter itemSorter = ItemSorters.getSorterByClass(sorterKey);
    itemSorter.sortItems(completionContext, completionItems);
    return completionItems;
}
Also used : ConnectorInitExpressionItemFilter(org.ballerinalang.langserver.completions.util.filters.ConnectorInitExpressionItemFilter) CompletionItemSorter(org.ballerinalang.langserver.completions.util.sorters.CompletionItemSorter) TextDocumentServiceContext(org.ballerinalang.langserver.TextDocumentServiceContext) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) ItemResolverConstants(org.ballerinalang.langserver.completions.util.ItemResolverConstants) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) ItemSorters(org.ballerinalang.langserver.completions.util.sorters.ItemSorters) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) CompletionItem(org.eclipse.lsp4j.CompletionItem) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) List(java.util.List) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo) Snippet(org.ballerinalang.langserver.completions.util.Snippet) SymbolKind(org.ballerinalang.model.symbols.SymbolKind) CompletionKeys(org.ballerinalang.langserver.completions.CompletionKeys) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) AbstractItemResolver(org.ballerinalang.langserver.completions.resolvers.AbstractItemResolver) PackageActionFunctionAndTypesFilter(org.ballerinalang.langserver.completions.util.filters.PackageActionFunctionAndTypesFilter) DocumentServiceKeys(org.ballerinalang.langserver.DocumentServiceKeys) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) SymbolKind(org.ballerinalang.model.symbols.SymbolKind) ArrayList(java.util.ArrayList) CompletionItemSorter(org.ballerinalang.langserver.completions.util.sorters.CompletionItemSorter) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) ConnectorInitExpressionItemFilter(org.ballerinalang.langserver.completions.util.filters.ConnectorInitExpressionItemFilter) PackageActionFunctionAndTypesFilter(org.ballerinalang.langserver.completions.util.filters.PackageActionFunctionAndTypesFilter) CompletionItem(org.eclipse.lsp4j.CompletionItem)

Example 10 with BTypeSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol in project ballerina by ballerina-lang.

the class PackageActionFunctionAndTypesFilter method getActionsFunctionsAndTypes.

/**
 * Get the actions, functions and types.
 * @param completionContext     Text Document Service context (Completion Context)
 * @param delimiterIndex        delimiter index (index of either . or :)
 * @return {@link ArrayList}    List of filtered symbol info
 */
private ArrayList<SymbolInfo> getActionsFunctionsAndTypes(TextDocumentServiceContext completionContext, int delimiterIndex) {
    ArrayList<SymbolInfo> actionFunctionList = new ArrayList<>();
    TokenStream tokenStream = completionContext.get(DocumentServiceKeys.TOKEN_STREAM_KEY);
    List<SymbolInfo> symbols = completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY);
    String packageName = tokenStream.get(delimiterIndex - 1).getText();
    // Extract the package symbol
    SymbolInfo packageSymbolInfo = symbols.stream().filter(item -> {
        Scope.ScopeEntry scopeEntry = item.getScopeEntry();
        return item.getSymbolName().equals(packageName) && scopeEntry.symbol instanceof BPackageSymbol;
    }).findFirst().orElse(null);
    if (packageSymbolInfo != null) {
        Scope.ScopeEntry packageEntry = packageSymbolInfo.getScopeEntry();
        SymbolInfo symbolInfo = new SymbolInfo(packageSymbolInfo.getSymbolName(), packageEntry);
        symbolInfo.getScopeEntry().symbol.scope.entries.forEach((name, value) -> {
            if ((value.symbol instanceof BInvokableSymbol && ((BInvokableSymbol) value.symbol).receiverSymbol == null) || (value.symbol instanceof BTypeSymbol && !(value.symbol instanceof BPackageSymbol))) {
                actionFunctionList.add(new SymbolInfo(name.toString(), value));
            }
        });
    }
    return actionFunctionList;
}
Also used : BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) TokenStream(org.antlr.v4.runtime.TokenStream) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) ArrayList(java.util.ArrayList) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo)

Aggregations

BTypeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)13 ArrayList (java.util.ArrayList)7 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)6 SymbolInfo (org.ballerinalang.langserver.completions.SymbolInfo)5 List (java.util.List)4 CompletionItem (org.eclipse.lsp4j.CompletionItem)4 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)4 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)4 BStructType (org.wso2.ballerinalang.compiler.semantics.model.types.BStructType)4 Collectors (java.util.stream.Collectors)3 TokenStream (org.antlr.v4.runtime.TokenStream)3 DocumentServiceKeys (org.ballerinalang.langserver.DocumentServiceKeys)3 TextDocumentServiceContext (org.ballerinalang.langserver.TextDocumentServiceContext)3 CompletionKeys (org.ballerinalang.langserver.completions.CompletionKeys)3 ItemResolverConstants (org.ballerinalang.langserver.completions.util.ItemResolverConstants)3 BJSONType (org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType)3 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)3 Arrays (java.util.Arrays)2 Token (org.antlr.v4.runtime.Token)2 UtilSymbolKeys (org.ballerinalang.langserver.common.UtilSymbolKeys)2