Search in sources :

Example 1 with BEndpointVarSymbol

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

the class SymbolEnter method defineEndpointVarSymbol.

public BEndpointVarSymbol defineEndpointVarSymbol(DiagnosticPos pos, Set<Flag> flagSet, BType varType, Name varName, SymbolEnv env) {
    // Create variable symbol
    Scope enclScope = env.scope;
    BEndpointVarSymbol varSymbol = new BEndpointVarSymbol(Flags.asMask(flagSet), varName, env.enclPkg.symbol.pkgID, varType, enclScope.owner);
    // Find duplicates
    if (!symResolver.checkForUniqueSymbol(pos, env, varSymbol, SymTag.VARIABLE_NAME)) {
        varSymbol.type = symTable.errType;
    }
    enclScope.define(varSymbol.name, varSymbol);
    return varSymbol;
}
Also used : Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol)

Example 2 with BEndpointVarSymbol

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

the class SemanticAnalyzer method defineResourceEndpoint.

private void defineResourceEndpoint(BLangResource resourceNode, SymbolEnv resourceEnv) {
    if (!resourceNode.getParameters().isEmpty()) {
        final BLangVariable variable = resourceNode.getParameters().get(0);
        if (variable.type == symTable.endpointType) {
            String actualVarName = variable.name.value.substring(1);
            variable.name = new BLangIdentifier();
            variable.name.value = actualVarName;
            if (resourceEnv.enclService.endpointType != null) {
                variable.type = resourceEnv.enclService.endpointType;
                final BEndpointVarSymbol bEndpointVarSymbol = symbolEnter.defineEndpointVarSymbol(variable.pos, EnumSet.noneOf(Flag.class), variable.type, names.fromString(actualVarName), resourceEnv);
                variable.symbol = bEndpointVarSymbol;
                endpointSPIAnalyzer.populateEndpointSymbol((BStructSymbol) variable.type.tsymbol, bEndpointVarSymbol);
            } else {
                variable.type = symTable.errType;
                variable.symbol = symbolEnter.defineVarSymbol(variable.pos, EnumSet.noneOf(Flag.class), variable.type, names.fromString(actualVarName), resourceEnv);
            }
            // Replace old symbol with new one.
            resourceNode.symbol.params.remove(0);
            resourceNode.symbol.params.add(0, variable.symbol);
            ((BInvokableType) resourceNode.symbol.type).paramTypes.remove(0);
            ((BInvokableType) resourceNode.symbol.type).paramTypes.add(0, variable.type);
        }
    }
}
Also used : BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) Flag(org.ballerinalang.model.elements.Flag) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 3 with BEndpointVarSymbol

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

the class SemanticAnalyzer method handleServiceEndpointBinds.

private void handleServiceEndpointBinds(BLangService serviceNode, BServiceSymbol serviceSymbol) {
    for (BLangSimpleVarRef ep : serviceNode.boundEndpoints) {
        typeChecker.checkExpr(ep, env);
        if (ep.symbol == null || (ep.symbol.tag & SymTag.ENDPOINT) != SymTag.ENDPOINT) {
            dlog.error(ep.pos, DiagnosticCode.ENDPOINT_INVALID_TYPE, ep.variableName);
            continue;
        }
        final BEndpointVarSymbol epSym = (BEndpointVarSymbol) ep.symbol;
        if ((epSym.tag & SymTag.ENDPOINT) == SymTag.ENDPOINT) {
            if (epSym.registrable) {
                serviceSymbol.boundEndpoints.add(epSym);
                if (serviceNode.endpointType == null) {
                    serviceNode.endpointType = (BStructType) epSym.type;
                    serviceNode.endpointClientType = endpointSPIAnalyzer.getClientType((BStructSymbol) serviceNode.endpointType.tsymbol);
                }
            // TODO : Validate serviceType endpoint type with bind endpoint types.
            } else {
                dlog.error(ep.pos, DiagnosticCode.ENDPOINT_NOT_SUPPORT_REGISTRATION, epSym);
            }
        } else {
            dlog.error(ep.pos, DiagnosticCode.ENDPOINT_INVALID_TYPE, epSym);
        }
    }
    if (serviceNode.endpointType == null) {
        dlog.error(serviceNode.pos, DiagnosticCode.SERVICE_INVALID_ENDPOINT_TYPE, serviceNode.name);
    }
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)

Example 4 with BEndpointVarSymbol

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

the class TypeChecker method checkActionInvocationExpr.

private void checkActionInvocationExpr(BLangInvocation iExpr, BType conType) {
    List<BType> actualTypes = getListWithErrorTypes(expTypes.size());
    if (conType == symTable.errType || conType.tag != TypeTags.STRUCT || iExpr.expr.symbol.tag != SymTag.ENDPOINT) {
        dlog.error(iExpr.pos, DiagnosticCode.INVALID_ACTION_INVOCATION);
        resultTypes = actualTypes;
        return;
    }
    final BEndpointVarSymbol epSymbol = (BEndpointVarSymbol) iExpr.expr.symbol;
    if (!epSymbol.interactable) {
        dlog.error(iExpr.pos, DiagnosticCode.ENDPOINT_NOT_SUPPORT_INTERACTIONS, epSymbol.name);
        resultTypes = actualTypes;
        return;
    }
    BSymbol conSymbol = epSymbol.clientSymbol;
    if (conSymbol == null || conSymbol == symTable.notFoundSymbol || conSymbol == symTable.errSymbol || conSymbol.tag != SymTag.STRUCT) {
        dlog.error(iExpr.pos, DiagnosticCode.INVALID_ACTION_INVOCATION);
        resultTypes = actualTypes;
        return;
    }
    Name actionName = names.fromIdNode(iExpr.name);
    Name uniqueFuncName = names.fromString(Symbols.getAttachedFuncSymbolName(conSymbol.name.value, actionName.value));
    BPackageSymbol packageSymbol = (BPackageSymbol) conSymbol.owner;
    BSymbol actionSym = symResolver.lookupMemberSymbol(iExpr.pos, packageSymbol.scope, this.env, uniqueFuncName, SymTag.FUNCTION);
    if (actionSym == symTable.errSymbol || actionSym == symTable.notFoundSymbol) {
        dlog.error(iExpr.pos, DiagnosticCode.UNDEFINED_ACTION, actionName, epSymbol.name, conSymbol.type);
        resultTypes = actualTypes;
        return;
    }
    iExpr.symbol = actionSym;
    checkInvocationParamAndReturnType(iExpr);
}
Also used : BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 5 with BEndpointVarSymbol

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

the class EndpointSPIAnalyzer method populateEndpointSymbol.

public void populateEndpointSymbol(BStructSymbol structSymbol, BEndpointVarSymbol endpointVarSymbol) {
    final Endpoint endpoint = validSPIs.get(structSymbol);
    if (endpoint != null) {
        final Endpoint endPoint = validSPIs.get(structSymbol);
        endpointVarSymbol.initFunction = endPoint.initFunction;
        endpointVarSymbol.interactable = endPoint.interactable;
        endpointVarSymbol.getClientFunction = endPoint.getClientFunction;
        endpointVarSymbol.clientSymbol = (BStructSymbol) endPoint.clientStruct.tsymbol;
        endpointVarSymbol.startFunction = endPoint.startFunction;
        endpointVarSymbol.stopFunction = endPoint.stopFunction;
        endpointVarSymbol.registrable = endPoint.registrable;
        endpointVarSymbol.registerFunction = endPoint.registerFunction;
    }
}
Also used : BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

BEndpointVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol)7 Name (org.wso2.ballerinalang.compiler.util.Name)3 ArrayList (java.util.ArrayList)2 Scope (org.wso2.ballerinalang.compiler.semantics.model.Scope)2 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)2 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)2 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)2 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)2 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)2 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Token (org.antlr.v4.runtime.Token)1 TokenStream (org.antlr.v4.runtime.TokenStream)1 DocumentServiceKeys (org.ballerinalang.langserver.DocumentServiceKeys)1 TextDocumentServiceContext (org.ballerinalang.langserver.TextDocumentServiceContext)1 UtilSymbolKeys (org.ballerinalang.langserver.common.UtilSymbolKeys)1 CommonUtil (org.ballerinalang.langserver.common.utils.CommonUtil)1