Search in sources :

Example 21 with BLangAnnotationAttachment

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

Aggregations

BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)10 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)9 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)5 HashSet (java.util.HashSet)4 List (java.util.List)4 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)4 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)4 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)3 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)3 BLangArrayLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral)3 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)3 ArrayList (java.util.ArrayList)2 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)2 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 Set (java.util.Set)1