Search in sources :

Example 21 with BLangResource

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

the class CommandUtil method getResourceDocumentationByPosition.

/**
 * Get the Documentation attachment for the resource.
 * @param bLangPackage      BLangPackage built
 * @param line              Start line of the resource in the source
 * @return {@link String}   Documentation attachment for the resource
 */
static DocAttachmentInfo getResourceDocumentationByPosition(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;
            for (BLangResource bLangResource : serviceNode.getResources()) {
                List<BLangAnnotationAttachment> annotationAttachments = bLangResource.getAnnotationAttachments();
                DiagnosticPos resourcePos = CommonUtil.toZeroBasedPosition(bLangResource.getPosition());
                if (!annotationAttachments.isEmpty()) {
                    DiagnosticPos lastAttachmentPos = CommonUtil.toZeroBasedPosition(annotationAttachments.get(annotationAttachments.size() - 1).getPosition());
                    if (lastAttachmentPos.getEndLine() < line && line < resourcePos.getEndLine()) {
                        return getResourceNodeDocumentation(bLangResource, lastAttachmentPos.getEndLine() + 1);
                    }
                } else if (resourcePos.getStartLine() == line) {
                    return getResourceNodeDocumentation(bLangResource, 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) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode)

Example 22 with BLangResource

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

the class CommandUtil method getResourceNodeDocumentation.

static DocAttachmentInfo getResourceNodeDocumentation(BLangResource bLangResource, int replaceFrom) {
    List<String> attributes = new ArrayList<>();
    DiagnosticPos resourcePos = CommonUtil.toZeroBasedPosition(bLangResource.getPosition());
    bLangResource.getParameters().forEach(bLangVariable -> {
        if (!(bLangVariable.symbol instanceof BEndpointVarSymbol)) {
            attributes.add(getDocAttributeFromBLangVariable(bLangVariable, resourcePos.getStartColumn()));
        }
    });
    return new DocAttachmentInfo(getDocumentationAttachment(attributes, resourcePos.getStartColumn()), replaceFrom);
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol) ArrayList(java.util.ArrayList)

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