Search in sources :

Example 1 with ResourceInfo

use of org.wso2.ballerinalang.programfile.ResourceInfo in project ballerina by ballerina-lang.

the class CommandExecutor method executeAddAllDocumentation.

/**
 * Generate workspace edit for generating doc comments for all top level nodes and resources.
 * @param context   Workspace Service Context
 */
private static void executeAddAllDocumentation(WorkspaceServiceContext context) {
    String documentUri = "";
    VersionedTextDocumentIdentifier textDocumentIdentifier = new VersionedTextDocumentIdentifier();
    for (Object arg : context.get(ExecuteCommandKeys.COMMAND_ARGUMENTS_KEY)) {
        if (((LinkedTreeMap) arg).get(ARG_KEY).equals(CommandConstants.ARG_KEY_DOC_URI)) {
            documentUri = (String) ((LinkedTreeMap) arg).get(ARG_VALUE);
            textDocumentIdentifier.setUri(documentUri);
            context.put(DocumentServiceKeys.FILE_URI_KEY, documentUri);
        }
    }
    BLangPackage bLangPackage = TextDocumentServiceUtil.getBLangPackage(context, context.get(ExecuteCommandKeys.DOCUMENT_MANAGER_KEY), false, LSCustomErrorStrategy.class, false).get(0);
    String fileContent = context.get(ExecuteCommandKeys.DOCUMENT_MANAGER_KEY).getFileContent(Paths.get(URI.create(documentUri)));
    String[] contentComponents = fileContent.split(System.lineSeparator());
    List<TextEdit> textEdits = new ArrayList<>();
    bLangPackage.topLevelNodes.forEach(topLevelNode -> {
        CommandUtil.DocAttachmentInfo docAttachmentInfo = getDocumentEditForNode(topLevelNode);
        if (docAttachmentInfo != null) {
            textEdits.add(getTextEdit(docAttachmentInfo, contentComponents));
        }
        if (topLevelNode instanceof BLangService) {
            ((BLangService) topLevelNode).getResources().forEach(bLangResource -> {
                CommandUtil.DocAttachmentInfo resourceInfo = getDocumentEditForNode(bLangResource);
                if (resourceInfo != null) {
                    textEdits.add(getTextEdit(resourceInfo, contentComponents));
                }
            });
        }
    });
    TextDocumentEdit textDocumentEdit = new TextDocumentEdit(textDocumentIdentifier, textEdits);
    applyWorkspaceEdit(Collections.singletonList(textDocumentEdit), context.get(ExecuteCommandKeys.LANGUAGE_SERVER_KEY).getClient());
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) ArrayList(java.util.ArrayList) TextDocumentEdit(org.eclipse.lsp4j.TextDocumentEdit) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) TextEdit(org.eclipse.lsp4j.TextEdit) LSCustomErrorStrategy(org.ballerinalang.langserver.common.LSCustomErrorStrategy)

Example 2 with ResourceInfo

use of org.wso2.ballerinalang.programfile.ResourceInfo 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 3 with ResourceInfo

use of org.wso2.ballerinalang.programfile.ResourceInfo 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 4 with ResourceInfo

use of org.wso2.ballerinalang.programfile.ResourceInfo 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

BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 ResourceInfo (org.wso2.ballerinalang.programfile.ResourceInfo)2 LinkedTreeMap (com.google.gson.internal.LinkedTreeMap)1 ArrayList (java.util.ArrayList)1 LSCustomErrorStrategy (org.ballerinalang.langserver.common.LSCustomErrorStrategy)1 TextDocumentEdit (org.eclipse.lsp4j.TextDocumentEdit)1 TextEdit (org.eclipse.lsp4j.TextEdit)1 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)1 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)1 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)1 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)1 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)1 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)1 WorkerInfo (org.wso2.ballerinalang.programfile.WorkerInfo)1