Search in sources :

Example 1 with BLangService

use of org.wso2.ballerinalang.compiler.tree.BLangService in project kubernetes by ballerinax.

the class KubernetesPlugin method extractEndpointName.

private Set<String> extractEndpointName(ServiceNode serviceNode) {
    Set<String> endpoints = new HashSet<>();
    List<BLangSimpleVarRef> endpointList = ((BLangService) serviceNode).boundEndpoints;
    for (BLangSimpleVarRef var : endpointList) {
        endpoints.add(var.variableName.getValue());
    }
    return endpoints;
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) HashSet(java.util.HashSet)

Example 2 with BLangService

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

the class SignatureTreeVisitor method visit.

@Override
public void visit(BLangService serviceNode) {
    BSymbol serviceSymbol = serviceNode.symbol;
    SymbolEnv serviceEnv = SymbolEnv.createPkgLevelSymbolEnv(serviceNode, serviceSymbol.scope, symbolEnv);
    serviceNode.resources.forEach(r -> this.acceptNode(r, serviceEnv));
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 3 with BLangService

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

the class CommandExecutor method getDocumentEditForNode.

/**
 * Get the document edit attachment info for a given particular node.
 * @param node      Node given
 * @return          Doc Attachment Info
 */
private static CommandUtil.DocAttachmentInfo getDocumentEditForNode(Node node) {
    CommandUtil.DocAttachmentInfo docAttachmentInfo = null;
    int replaceFrom;
    switch(node.getKind()) {
        case FUNCTION:
            if (((BLangFunction) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangFunction) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getFunctionNodeDocumentation((BLangFunction) node, replaceFrom);
            }
            break;
        case STRUCT:
            if (((BLangStruct) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangStruct) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getStructNodeDocumentation((BLangStruct) node, replaceFrom);
            }
            break;
        case ENUM:
            if (((BLangEnum) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangEnum) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getEnumNodeDocumentation((BLangEnum) node, replaceFrom);
            }
            break;
        case TRANSFORMER:
            if (((BLangTransformer) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangTransformer) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getTransformerNodeDocumentation((BLangTransformer) node, replaceFrom);
            }
            break;
        case RESOURCE:
            if (((BLangResource) node).docAttachments.isEmpty()) {
                BLangResource bLangResource = (BLangResource) node;
                replaceFrom = getReplaceFromForServiceOrResource(bLangResource, bLangResource.getAnnotationAttachments());
                docAttachmentInfo = CommandUtil.getResourceNodeDocumentation(bLangResource, replaceFrom);
            }
            break;
        case SERVICE:
            if (((BLangService) node).docAttachments.isEmpty()) {
                BLangService bLangService = (BLangService) node;
                replaceFrom = getReplaceFromForServiceOrResource(bLangService, bLangService.getAnnotationAttachments());
                docAttachmentInfo = CommandUtil.getServiceNodeDocumentation(bLangService, replaceFrom);
            }
            break;
        default:
            break;
    }
    return docAttachmentInfo;
}
Also used : BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum)

Example 4 with BLangService

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

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

the class CommandUtil method getServiceDocumentationByPosition.

/**
 * Get the Documentation attachment for the service.
 * @param bLangPackage      BLangPackage built
 * @param line              Start line of the service in the source
 * @return {@link String}   Documentation attachment for the service
 */
static DocAttachmentInfo getServiceDocumentationByPosition(BLangPackage bLangPackage, int line) {
    // TODO: Currently resource position is invalid and we use the annotation attachment positions.
    for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
        if (topLevelNode instanceof BLangService) {
            BLangService serviceNode = (BLangService) topLevelNode;
            DiagnosticPos servicePos = CommonUtil.toZeroBasedPosition(serviceNode.getPosition());
            List<BLangAnnotationAttachment> annotationAttachments = serviceNode.getAnnotationAttachments();
            if (!annotationAttachments.isEmpty()) {
                DiagnosticPos lastAttachmentPos = CommonUtil.toZeroBasedPosition(annotationAttachments.get(annotationAttachments.size() - 1).getPosition());
                if (lastAttachmentPos.getEndLine() < line && line < servicePos.getEndLine()) {
                    return getServiceNodeDocumentation(serviceNode, lastAttachmentPos.getEndLine() + 1);
                }
            } else if (servicePos.getStartLine() == line) {
                return getServiceNodeDocumentation(serviceNode, line);
            }
        }
    }
    return null;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode)

Aggregations

BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)16 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)8 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)7 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)7 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)6 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)6 BServiceSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BServiceSymbol)5 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)5 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)5 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)5 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)4 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)4 CompileResult (org.ballerinalang.launcher.util.CompileResult)3 PackageNode (org.ballerinalang.model.tree.PackageNode)3 Test (org.testng.annotations.Test)3 BServiceType (org.wso2.ballerinalang.compiler.semantics.model.types.BServiceType)3 BLangAction (org.wso2.ballerinalang.compiler.tree.BLangAction)3 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)3 BLangInvokableNode (org.wso2.ballerinalang.compiler.tree.BLangInvokableNode)3 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)3