Search in sources :

Example 11 with BLangResource

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

the class HTTPServiceCompilerPlugin method process.

@Override
public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) {
    for (AnnotationAttachmentNode annotation : annotations) {
        if (!PROTOCOL_PACKAGE_HTTP.equals(((BLangAnnotationAttachment) annotation).annotationSymbol.pkgID.name.value)) {
            continue;
        }
        if (annotation.getAnnotationName().getValue().equals(ANN_NAME_HTTP_SERVICE_CONFIG) || annotation.getAnnotationName().getValue().equals(WebSocketConstants.WEBSOCKET_ANNOTATION_CONFIGURATION)) {
            handleServiceConfigAnnotation(serviceNode, (BLangAnnotationAttachment) annotation);
        }
    }
    if (HttpConstants.HTTP_SERVICE_TYPE.equals(serviceNode.getServiceTypeStruct().getTypeName().getValue())) {
        List<BLangResource> resources = (List<BLangResource>) serviceNode.getResources();
        resources.forEach(resource -> ResourceSignatureValidator.validate(resource.getParameters()));
    }
}
Also used : BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) List(java.util.List) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 12 with BLangResource

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

the class TaintAnalyzer method visit.

public void visit(BLangResource resourceNode) {
    BSymbol resourceSymbol = resourceNode.symbol;
    SymbolEnv resourceEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceSymbol.scope, env);
    visitEntryPoint(resourceNode, resourceEnv);
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 13 with BLangResource

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

the class SemanticAnalyzer method visit.

public void visit(BLangResource resourceNode) {
    BSymbol resourceSymbol = resourceNode.symbol;
    SymbolEnv resourceEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceSymbol.scope, env);
    resourceNode.annAttachments.forEach(a -> {
        a.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.RESOURCE);
        this.analyzeDef(a, resourceEnv);
    });
    defineResourceEndpoint(resourceNode, resourceEnv);
    resourceNode.docAttachments.forEach(doc -> analyzeDef(doc, resourceEnv));
    resourceNode.requiredParams.forEach(p -> analyzeDef(p, resourceEnv));
    resourceNode.endpoints.forEach(e -> {
        symbolEnter.defineNode(e, resourceEnv);
        analyzeDef(e, resourceEnv);
    });
    analyzeStmt(resourceNode.body, resourceEnv);
    this.processWorkers(resourceNode, resourceEnv);
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)

Example 14 with BLangResource

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

the class CodeGenerator method createResourceInfoEntry.

private void createResourceInfoEntry(BLangResource resourceNode, ServiceInfo serviceInfo) {
    BInvokableType resourceType = (BInvokableType) resourceNode.symbol.type;
    // Add resource name as an UTFCPEntry to the constant pool
    int serviceNameCPIndex = addUTF8CPEntry(currentPkgInfo, resourceNode.name.value);
    ResourceInfo resourceInfo = new ResourceInfo(currentPackageRefCPIndex, serviceNameCPIndex);
    resourceInfo.paramTypes = resourceType.paramTypes.toArray(new BType[0]);
    setParameterNames(resourceNode, resourceInfo);
    resourceInfo.retParamTypes = new BType[0];
    resourceInfo.signatureCPIndex = addUTF8CPEntry(currentPkgInfo, generateFunctionSig(resourceInfo.paramTypes, resourceInfo.retParamTypes));
    // Add worker info
    int workerNameCPIndex = addUTF8CPEntry(currentPkgInfo, "default");
    resourceInfo.defaultWorkerInfo = new WorkerInfo(workerNameCPIndex, "default");
    resourceNode.workers.forEach(worker -> addWorkerInfoEntry(worker, resourceInfo));
    // Add resource info to the service info
    serviceInfo.resourceInfoMap.put(resourceNode.name.getValue(), resourceInfo);
}
Also used : ResourceInfo(org.wso2.ballerinalang.programfile.ResourceInfo) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) WorkerInfo(org.wso2.ballerinalang.programfile.WorkerInfo) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 15 with BLangResource

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

the class CodeGenerator method setParameterNames.

private void setParameterNames(BLangResource resourceNode, ResourceInfo resourceInfo) {
    int paramCount = resourceNode.requiredParams.size();
    resourceInfo.paramNameCPIndexes = new int[paramCount];
    for (int i = 0; i < paramCount; i++) {
        BLangVariable paramVar = resourceNode.requiredParams.get(i);
        String paramName = null;
        boolean isAnnotated = false;
        for (BLangAnnotationAttachment annotationAttachment : paramVar.annAttachments) {
            String attachmentName = annotationAttachment.getAnnotationName().getValue();
            if ("PathParam".equalsIgnoreCase(attachmentName) || "QueryParam".equalsIgnoreCase(attachmentName)) {
                // TODO:
                // paramName = annotationAttachment.getAttributeNameValuePairs().get("value")
                // .getLiteralValue().stringValue();
                isAnnotated = true;
                break;
            }
        }
        if (!isAnnotated) {
            paramName = paramVar.name.getValue();
        }
        int paramNameCPIndex = addUTF8CPEntry(currentPkgInfo, paramName);
        resourceInfo.paramNameCPIndexes[i] = paramNameCPIndex;
    }
}
Also used : BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

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