Search in sources :

Example 71 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project ballerina by ballerina-lang.

the class CommandUtil method getTransformerDocumentationByPosition.

/**
 * Get the Documentation attachment for the transformer.
 * @param bLangPackage      BLangPackage built
 * @param line              Start line of the transformer in the source
 * @return {@link String}   Documentation attachment for the transformer
 */
static DocAttachmentInfo getTransformerDocumentationByPosition(BLangPackage bLangPackage, int line) {
    for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
        if (topLevelNode instanceof BLangTransformer) {
            BLangTransformer transformerNode = (BLangTransformer) topLevelNode;
            DiagnosticPos transformerPos = CommonUtil.toZeroBasedPosition(transformerNode.getPosition());
            int transformerStart = transformerPos.getStartLine();
            if (transformerStart == line) {
                return getTransformerNodeDocumentation(transformerNode, line);
            }
        }
    }
    return null;
}
Also used : BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode)

Example 72 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment 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 73 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project ballerina by ballerina-lang.

the class CommandUtil method getFunctionDocumentationByPosition.

/**
 * Get the Documentation attachment for the function.
 * @param bLangPackage      BLangPackage built
 * @param line              Start line of the function in the source
 * @return {@link String}   Documentation attachment for the function
 */
static DocAttachmentInfo getFunctionDocumentationByPosition(BLangPackage bLangPackage, int line) {
    List<FunctionNode> filteredFunctions = new ArrayList<>();
    for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
        if (topLevelNode instanceof BLangFunction) {
            filteredFunctions.add((BLangFunction) topLevelNode);
        } else if (topLevelNode instanceof BLangObject) {
            filteredFunctions.addAll(((BLangObject) topLevelNode).getFunctions());
        }
        for (FunctionNode filteredFunction : filteredFunctions) {
            DiagnosticPos functionPos = CommonUtil.toZeroBasedPosition((DiagnosticPos) filteredFunction.getPosition());
            int functionStart = functionPos.getStartLine();
            if (functionStart == line) {
                return getFunctionNodeDocumentation(filteredFunction, line);
            }
        }
    }
    return null;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) FunctionNode(org.ballerinalang.model.tree.FunctionNode) ArrayList(java.util.ArrayList) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode)

Example 74 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project ballerina by ballerina-lang.

the class CommandUtil method getEnumDocumentationByPosition.

/**
 * Get the Documentation attachment for the enum.
 * @param bLangPackage      BLangPackage built
 * @param line              Start line of the enum in the source
 * @return {@link String}   Documentation attachment for the enum
 */
static DocAttachmentInfo getEnumDocumentationByPosition(BLangPackage bLangPackage, int line) {
    for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
        if (topLevelNode instanceof BLangEnum) {
            BLangEnum enumNode = (BLangEnum) topLevelNode;
            DiagnosticPos enumPos = CommonUtil.toZeroBasedPosition(enumNode.getPosition());
            int enumStart = enumPos.getStartLine();
            if (enumStart == line) {
                return getEnumNodeDocumentation(enumNode, line);
            }
        }
    }
    return null;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode)

Aggregations

HashMap (java.util.HashMap)11 AttachmentMgtException (org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)11 TAttachment (org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)10 DataHandler (javax.activation.DataHandler)9 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)9 ArrayList (java.util.ArrayList)8 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)8 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)8 File (java.io.File)7 Response (javax.ws.rs.core.Response)7 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)7 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)7 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)6 AttachmentDAO (org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO)6 BaseTaskService (org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)5 IOException (java.io.IOException)4 List (java.util.List)4 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)4 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)4 Attachment (org.wso2.carbon.attachment.mgt.api.attachment.Attachment)4