Search in sources :

Example 46 with BVarSymbol

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

the class Desugar method visit.

public void visit(BLangTransformer transformerNode) {
    addTransformerReturn(transformerNode);
    SymbolEnv tranEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerNode.symbol.scope, env);
    transformerNode.body = rewrite(transformerNode.body, tranEnv);
    addArgInitExpr(transformerNode, transformerNode.retParams.get(0));
    BInvokableSymbol transformerSymbol = transformerNode.symbol;
    List<BVarSymbol> params = transformerSymbol.params;
    params.add(0, transformerNode.source.symbol);
    BInvokableType transformerType = (BInvokableType) transformerSymbol.type;
    transformerType.paramTypes.add(0, transformerNode.source.type);
    result = transformerNode;
}
Also used : BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Example 47 with BVarSymbol

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

the class EndpointDesugar method generateServiceRegistered.

private BLangBlockStmt generateServiceRegistered(BEndpointVarSymbol endpoint, BLangService service, SymbolEnv env, BSymbol encSymbol, BSymbol varEncSymbol) {
    final DiagnosticPos pos = service.pos;
    final String epName = endpoint.name.value;
    BLangBlockStmt temp = new BLangBlockStmt();
    final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.type);
    final Name name = endpoint.name;
    epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, name, SymTag.VARIABLE);
    final BLangVariableDef serviceTypeDef = ASTBuilderUtil.createVariableDefStmt(pos, temp);
    serviceTypeDef.var = ASTBuilderUtil.createVariable(pos, service.name + "type", symTable.typeDesc);
    ASTBuilderUtil.defineVariable(serviceTypeDef.var, varEncSymbol, names);
    final BLangUnaryExpr typeOfExpr = ASTBuilderUtil.createUnaryExpr(pos);
    serviceTypeDef.var.expr = typeOfExpr;
    typeOfExpr.operator = OperatorKind.TYPEOF;
    typeOfExpr.expr = getTypeAccessExpression(pos, service.symbol.type);
    typeOfExpr.type = symTable.typeDesc;
    List<BLangVariable> args = Lists.of(serviceTypeDef.var);
    if (endpoint.registerFunction != null && endpoint.registerFunction.params.size() == 2) {
        // Endpoint is already desugared. Fix this correctly.
        args.add(0, epVariable);
    }
    final BLangExpressionStmt expressionStmt = ASTBuilderUtil.createExpressionStmt(pos, temp);
    final BLangInvocation iExpr = ASTBuilderUtil.createInvocationExpr(pos, endpoint.registerFunction, args, symResolver);
    if (endpoint.registerFunction != null && endpoint.registerFunction.params.size() != 2) {
        iExpr.expr = ASTBuilderUtil.createVariableRef(epVariable.pos, epVariable.symbol);
    }
    expressionStmt.expr = iExpr;
    return temp;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangUnaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangUnaryExpr) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 48 with BVarSymbol

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

the class BLangEndpointContextResolver method resolveItems.

@Override
@SuppressWarnings("unchecked")
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
    BLangNode bLangEndpoint = completionContext.get(CompletionKeys.SYMBOL_ENV_NODE_KEY);
    ArrayList<CompletionItem> completionItems = new ArrayList<>();
    ArrayList<SymbolInfo> configurationFields = new ArrayList<>();
    List<BStructSymbol.BAttachedFunction> attachedFunctions = new ArrayList<>();
    if (((BLangEndpoint) bLangEndpoint).type.tsymbol instanceof BStructSymbol) {
        attachedFunctions.addAll(((BStructSymbol) ((BLangEndpoint) bLangEndpoint).type.tsymbol).attachedFuncs);
    }
    BStructSymbol.BAttachedFunction initFunction = attachedFunctions.stream().filter(bAttachedFunction -> bAttachedFunction.funcName.getValue().equals(INIT)).findFirst().orElseGet(null);
    BVarSymbol configSymbol = initFunction.symbol.getParameters().get(0);
    BType configSymbolType = configSymbol.getType();
    if (configSymbolType instanceof BStructType) {
        ((BStructType) configSymbolType).getFields().forEach(bStructField -> configurationFields.add(new SymbolInfo(bStructField.getName().getValue(), new Scope.ScopeEntry(bStructField.symbol, null))));
    }
    this.populateCompletionItemList(configurationFields, completionItems);
    return completionItems;
}
Also used : BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) ArrayList(java.util.ArrayList) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo) BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) CompletionItem(org.eclipse.lsp4j.CompletionItem) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Example 49 with BVarSymbol

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

the class AbstractItemResolver method populateCompletionItemList.

/**
 * Populate the completion item list by considering the.
 * @param symbolInfoList - list of symbol information
 * @param completionItems - completion item list to populate
 */
protected void populateCompletionItemList(List<SymbolInfo> symbolInfoList, List<CompletionItem> completionItems) {
    symbolInfoList.forEach(symbolInfo -> {
        CompletionItem completionItem = null;
        BSymbol bSymbol = symbolInfo.getScopeEntry() != null ? symbolInfo.getScopeEntry().symbol : null;
        if ((bSymbol instanceof BInvokableSymbol && ((BInvokableSymbol) bSymbol).kind != null && !((BInvokableSymbol) bSymbol).kind.equals(SymbolKind.WORKER)) || symbolInfo.isIterableOperation()) {
            completionItem = this.populateBallerinaFunctionCompletionItem(symbolInfo);
        } else if (!(bSymbol instanceof BInvokableSymbol) && bSymbol instanceof BVarSymbol) {
            completionItem = this.populateVariableDefCompletionItem(symbolInfo);
        } else if (bSymbol instanceof BTypeSymbol && !bSymbol.getName().getValue().equals(UtilSymbolKeys.NOT_FOUND_TYPE) && !(bSymbol instanceof BAnnotationSymbol)) {
            completionItem = this.populateBTypeCompletionItem(symbolInfo);
        }
        if (completionItem != null) {
            completionItems.add(completionItem);
        }
    });
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) CompletionItem(org.eclipse.lsp4j.CompletionItem) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BAnnotationSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol)

Example 50 with BVarSymbol

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

the class SignatureTreeVisitor method populateSymbols.

/**
 * Populate the symbols.
 * @param symbolEntries symbol entries
 */
private void populateSymbols(Map<Name, Scope.ScopeEntry> symbolEntries) {
    // TODO: Populate only the visible functions
    this.terminateVisitor = true;
    String identifierAgainst = documentServiceContext.get(SignatureKeys.IDENTIFIER_AGAINST);
    List<SymbolInfo> visibleSymbols = new ArrayList<>();
    /*
          During the first iteration we filter out the functions and if there is, the variable reference against which
          the function is called.
         */
    symbolEntries.forEach((k, v) -> {
        if (v.symbol instanceof BInvokableSymbol && !(v.symbol instanceof BOperatorSymbol) && !v.symbol.getName().getValue().contains("<init>")) {
            SymbolInfo symbolInfo = new SymbolInfo(k.getValue(), v);
            visibleSymbols.add(symbolInfo);
        } else if (v.symbol instanceof BVarSymbol && k.getValue().equals(identifierAgainst)) {
            documentServiceContext.put(SignatureKeys.IDENTIFIER_TYPE, v.symbol.type.toString());
        } else if (v.symbol instanceof BPackageSymbol && k.getValue().equals(identifierAgainst)) {
            documentServiceContext.put(SignatureKeys.IDENTIFIER_PKGID, v.symbol.pkgID.toString());
            documentServiceContext.put(SignatureKeys.IDENTIFIER_TYPE, v.symbol.type.toString());
            visibleSymbols.addAll(this.getInvokableSymbolsInPackage((BPackageSymbol) v.symbol));
        }
    });
    /*
          In this iteration we filter out the functions either having a receiver or otherwise.
          If the identifier against value is a valid value, then check whether the receiver type equals to identifier
          type. If there is no identifier, filter out functions without the receiver
         */
    List<SymbolInfo> filteredSymbols = new ArrayList<>();
    visibleSymbols.forEach(symbolInfo -> {
        BVarSymbol receiver = ((BInvokableSymbol) symbolInfo.getScopeEntry().symbol).receiverSymbol;
        String[] nameTokens = symbolInfo.getSymbolName().split("\\.");
        String funcNameFromSymbol = nameTokens[nameTokens.length - 1];
        String functionName = documentServiceContext.get(SignatureKeys.CALLABLE_ITEM_NAME);
        String identifierPkgName = documentServiceContext.get(SignatureKeys.IDENTIFIER_PKGID);
        boolean onIdentifierTypePkg = "package".equals(documentServiceContext.get(SignatureKeys.IDENTIFIER_TYPE)) && symbolInfo.getScopeEntry().symbol.pkgID.toString().equals(identifierPkgName);
        boolean onReceiverTypeMatchIdentifier = receiver != null && receiver.type.toString().equals(documentServiceContext.get(SignatureKeys.IDENTIFIER_TYPE));
        boolean onIdentifierAgainstNull = (receiver == null && (identifierAgainst == null || identifierAgainst.equals("")));
        if ((onIdentifierTypePkg || onReceiverTypeMatchIdentifier || onIdentifierAgainstNull) && funcNameFromSymbol.equals(functionName)) {
            filteredSymbols.add(symbolInfo);
        }
    });
    documentServiceContext.put(SignatureKeys.FILTERED_FUNCTIONS, filteredSymbols);
}
Also used : BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) ArrayList(java.util.ArrayList) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo)

Aggregations

BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)29 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)16 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)15 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)13 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)12 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)12 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)11 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)10 Name (org.wso2.ballerinalang.compiler.util.Name)10 ArrayList (java.util.ArrayList)9 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)9 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)8 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)8 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)8 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)7 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)7 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)7 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)6 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)6 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)6