Search in sources :

Example 6 with BLangResource

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

the class TaintAnalyzer method isEntryPoint.

// Private methods related to invokable node analysis and taint-table generation.
private boolean isEntryPoint(BLangFunction funcNode) {
    // Service resources are handled through BLangResource visitor.
    boolean isMainFunction = false;
    if (funcNode.name.value.equals(MAIN_FUNCTION_NAME) && funcNode.symbol.params.size() == 1 && funcNode.symbol.retParams.size() == 0) {
        BType paramType = funcNode.symbol.params.get(0).type;
        BArrayType arrayType = (BArrayType) paramType;
        if (paramType.tag == TypeTags.ARRAY && arrayType.eType.tag == TypeTags.STRING) {
            isMainFunction = true;
        }
    }
    return isMainFunction;
}
Also used : BArrayType(org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType)

Example 7 with BLangResource

use of org.wso2.ballerinalang.compiler.tree.BLangResource 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 8 with BLangResource

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

the class CodeGenerator method visit.

public void visit(BLangResource resourceNode) {
    ResourceInfo resourceInfo = currentServiceInfo.resourceInfoMap.get(resourceNode.name.getValue());
    currentCallableUnitInfo = resourceInfo;
    SymbolEnv resourceEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceNode.symbol.scope, this.env);
    visitInvokableNode(resourceNode, currentCallableUnitInfo, resourceEnv);
}
Also used : ResourceInfo(org.wso2.ballerinalang.programfile.ResourceInfo) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 9 with BLangResource

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

the class Desugar method visit.

@Override
public void visit(BLangResource resourceNode) {
    addReturnIfNotPresent(resourceNode);
    SymbolEnv resourceEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceNode.symbol.scope, env);
    // To preserve endpoint code gen order at resource
    Collections.reverse(resourceNode.endpoints);
    resourceNode.endpoints = rewrite(resourceNode.endpoints, resourceEnv);
    resourceNode.body = rewrite(resourceNode.body, resourceEnv);
    resourceNode.workers = rewrite(resourceNode.workers, resourceEnv);
    result = resourceNode;
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 10 with BLangResource

use of org.wso2.ballerinalang.compiler.tree.BLangResource 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)

Aggregations

BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)10 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)7 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)6 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)5 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)4 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)3 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)3 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)3 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)3 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)2 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)2 BLangAction (org.wso2.ballerinalang.compiler.tree.BLangAction)2 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)2 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)2 LinkedTreeMap (com.google.gson.internal.LinkedTreeMap)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1