Search in sources :

Example 26 with Node

use of org.wso2.carbon.identity.core.model.Node in project ballerina by ballerina-lang.

the class Generator method createDocForNode.

/**
 * Create documentation for enums.
 * @param enumNode ballerina enum node.
 * @return documentation for enum.
 */
public static EnumDoc createDocForNode(EnumNode enumNode) {
    String enumName = enumNode.getName().getValue();
    List<Variable> enumerators = new ArrayList<>();
    // Iterate through the enumerators
    if (enumNode.getEnumerators().size() > 0) {
        for (EnumNode.Enumerator enumerator : enumNode.getEnumerators()) {
            String desc = fieldAnnotation((BLangNode) enumNode, (BLangNode) enumerator);
            Variable variable = new Variable(enumerator.getName().getValue(), "", desc);
            enumerators.add(variable);
        }
    }
    return new EnumDoc(enumName, description((BLangNode) enumNode), new ArrayList<>(), enumerators);
}
Also used : EnumDoc(org.ballerinalang.docgen.model.EnumDoc) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Variable(org.ballerinalang.docgen.model.Variable) ArrayList(java.util.ArrayList) EnumNode(org.ballerinalang.model.tree.EnumNode)

Example 27 with Node

use of org.wso2.carbon.identity.core.model.Node in project ballerina by ballerina-lang.

the class Generator method createDocForNode.

/**
 * Create documentation for connectors.
 * @param connectorNode ballerina connector node.
 * @return documentation for connectors.
 */
public static ConnectorDoc createDocForNode(BLangConnector connectorNode) {
    String connectorName = connectorNode.getName().value;
    List<Variable> parameters = new ArrayList<>();
    List<Documentable> actions = new ArrayList<>();
    // Iterate through the connector parameters
    if (connectorNode.getParameters().size() > 0) {
        for (BLangVariable param : connectorNode.getParameters()) {
            String dataType = type(param);
            String desc = paramAnnotation(connectorNode, param);
            Variable variable = new Variable(param.getName().value, dataType, desc);
            parameters.add(variable);
        }
    }
    // Iterate through the actions of the connectors
    if (connectorNode.getActions().size() > 0) {
        for (BLangAction action : connectorNode.getActions()) {
            actions.add(createDocForNode(action));
        }
    }
    return new ConnectorDoc(connectorName, description(connectorNode), actions, parameters);
}
Also used : BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Variable(org.ballerinalang.docgen.model.Variable) Documentable(org.ballerinalang.docgen.model.Documentable) ArrayList(java.util.ArrayList) ConnectorDoc(org.ballerinalang.docgen.model.ConnectorDoc) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction)

Example 28 with Node

use of org.wso2.carbon.identity.core.model.Node in project ballerina by ballerina-lang.

the class Generator method fieldAnnotation.

/**
 * Get description annotation of the field.
 * @param node parent node.
 * @param param field.
 * @return description of the field.
 */
private static String fieldAnnotation(BLangNode node, BLangNode param) {
    String subName = "";
    if (param instanceof BLangVariable) {
        BLangVariable paramVariable = (BLangVariable) param;
        subName = (paramVariable.getName() == null) ? paramVariable.type.tsymbol.name.value : paramVariable.getName().getValue();
    } else if (param instanceof BLangEnum.Enumerator) {
        BLangEnum.Enumerator paramEnumVal = (BLangEnum.Enumerator) param;
        subName = paramEnumVal.getName().getValue();
    }
    for (AnnotationAttachmentNode annotation : getAnnotationAttachments(node)) {
        BLangRecordLiteral bLangRecordLiteral = (BLangRecordLiteral) annotation.getExpression();
        if (bLangRecordLiteral.getKeyValuePairs().size() != 1) {
            continue;
        }
        BLangExpression bLangLiteral = bLangRecordLiteral.getKeyValuePairs().get(0).getValue();
        String attribVal = bLangLiteral.toString();
        if (annotation.getAnnotationName().getValue().equals("Field") && attribVal.startsWith(subName + ":")) {
            return attribVal.split(subName + ":")[1].trim();
        }
    }
    // annotation's value
    for (AnnotationAttachmentNode annotation : getAnnotationAttachments(node)) {
        BLangRecordLiteral bLangRecordLiteral = (BLangRecordLiteral) annotation.getExpression();
        if (bLangRecordLiteral.getKeyValuePairs().size() != 1) {
            continue;
        }
        if (annotation.getAnnotationName().getValue().equals("Field")) {
            BLangExpression bLangLiteral = bLangRecordLiteral.getKeyValuePairs().get(0).getValue();
            return bLangLiteral.toString();
        }
    }
    return "";
}
Also used : BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 29 with Node

use of org.wso2.carbon.identity.core.model.Node in project ballerina by ballerina-lang.

the class Generator method paramAnnotation.

/**
 * Get description annotation of the parameter.
 * @param node parent node.
 * @param param parameter.
 * @return description of the parameter.
 */
private static String paramAnnotation(BLangNode node, BLangVariable param) {
    String subName = param.getName() == null ? param.type.tsymbol.name.value : param.getName().getValue();
    for (AnnotationAttachmentNode annotation : getAnnotationAttachments(node)) {
        BLangRecordLiteral bLangRecordLiteral = (BLangRecordLiteral) annotation.getExpression();
        if (bLangRecordLiteral.getKeyValuePairs().size() != 1) {
            continue;
        }
        BLangExpression bLangLiteral = bLangRecordLiteral.getKeyValuePairs().get(0).getValue();
        String attribVal = bLangLiteral.toString();
        if ((annotation.getAnnotationName().getValue().equals("Param")) && attribVal.startsWith(subName + ":")) {
            return attribVal.split(subName + ":")[1].trim();
        }
    }
    return "";
}
Also used : BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 30 with Node

use of org.wso2.carbon.identity.core.model.Node in project ballerina by ballerina-lang.

the class Generator method annotFieldAnnotation.

/**
 * Get description annotation of the annotation attribute.
 * @param annotationNode parent node.
 * @param annotAttribute annotation attribute.
 * @return description of the annotation attribute.
 */
private static String annotFieldAnnotation(BLangAnnotation annotationNode, BLangAnnotAttribute annotAttribute) {
    List<? extends AnnotationAttachmentNode> annotationAttachments = getAnnotationAttachments(annotationNode);
    for (AnnotationAttachmentNode annotation : annotationAttachments) {
        if ("Field".equals(annotation.getAnnotationName().getValue())) {
            BLangRecordLiteral bLangRecordLiteral = (BLangRecordLiteral) annotation.getExpression();
            BLangExpression bLangLiteral = bLangRecordLiteral.getKeyValuePairs().get(0).getValue();
            String value = bLangLiteral.toString();
            if (value.startsWith(annotAttribute.getName().getValue())) {
                String[] valueParts = value.split(":");
                return valueParts.length == 2 ? valueParts[1] : valueParts[0];
            }
        }
    }
    return "";
}
Also used : BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Aggregations

ArrayList (java.util.ArrayList)33 Operation (io.swagger.v3.oas.annotations.Operation)26 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)26 Response (javax.ws.rs.core.Response)26 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)25 Test (org.testng.annotations.Test)24 Node (org.wso2.charon3.core.utils.codeutils.Node)22 ExpressionNode (org.wso2.charon3.core.utils.codeutils.ExpressionNode)20 IOException (java.io.IOException)19 Node (org.w3c.dom.Node)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 List (java.util.List)16 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)16 OperationNode (org.wso2.charon3.core.utils.codeutils.OperationNode)16 Artifacts (org.wso2.ei.dashboard.core.rest.model.Artifacts)15 CAppArtifacts (org.wso2.ei.dashboard.core.rest.model.CAppArtifacts)15 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)13 Ack (org.wso2.ei.dashboard.core.rest.model.Ack)13 Map (java.util.Map)12 NodeList (org.w3c.dom.NodeList)12