Search in sources :

Example 1 with Action

use of org.ballerinalang.composer.service.ballerina.parser.service.model.lang.Action in project ballerina by ballerina-lang.

the class ParserUtils method extractConnector.

/**
 * Extract connectors from ballerina lang.
 *
 * @param packages  packages to send
 * @param connector connector
 */
private static void extractConnector(Map<String, ModelPackage> packages, String packagePath, BLangConnector connector) {
    String fileName = connector.getPosition().getSource().getCompilationUnitName();
    if (packages.containsKey(packagePath)) {
        ModelPackage modelPackage = packages.get(packagePath);
        List<Parameter> parameters = new ArrayList<>();
        addParameters(parameters, connector.getParameters());
        List<AnnotationAttachment> annotations = new ArrayList<>();
        addAnnotations(annotations, connector.getAnnotationAttachments());
        List<Action> actions = new ArrayList<>();
        addActions(actions, connector.getActions());
        modelPackage.addConnectorsItem(createNewConnector(connector.getName().getValue(), annotations, actions, parameters, null, fileName));
    } else {
        ModelPackage modelPackage = new ModelPackage();
        modelPackage.setName(packagePath);
        List<Parameter> parameters = new ArrayList<>();
        addParameters(parameters, connector.getParameters());
        List<AnnotationAttachment> annotations = new ArrayList<>();
        addAnnotations(annotations, connector.getAnnotationAttachments());
        List<Action> actions = new ArrayList<>();
        addActions(actions, connector.getActions());
        modelPackage.addConnectorsItem(createNewConnector(connector.getName().getValue(), annotations, actions, parameters, null, fileName));
        packages.put(packagePath, modelPackage);
    }
}
Also used : BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) Action(org.ballerinalang.composer.service.ballerina.parser.service.model.lang.Action) AnnotationAttachment(org.ballerinalang.composer.service.ballerina.parser.service.model.lang.AnnotationAttachment) BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) ArrayList(java.util.ArrayList) ModelPackage(org.ballerinalang.composer.service.ballerina.parser.service.model.lang.ModelPackage) Parameter(org.ballerinalang.composer.service.ballerina.parser.service.model.lang.Parameter)

Example 2 with Action

use of org.ballerinalang.composer.service.ballerina.parser.service.model.lang.Action in project ballerina by ballerina-lang.

the class ParserUtils method createNewAction.

/**
 * Create new action.
 *
 * @param name         action name
 * @param params       list of params
 * @param returnParams list of return params
 * @param annotations  list of annotations
 * @return {Action} action
 */
private static Action createNewAction(String name, List<Parameter> params, List<Parameter> returnParams, List<AnnotationAttachment> annotations, String fileName) {
    Action action = new Action();
    action.setName(name);
    action.setParameters(params);
    action.setReturnParams(returnParams);
    action.setAnnotations(annotations);
    action.setFileName(fileName);
    return action;
}
Also used : BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) Action(org.ballerinalang.composer.service.ballerina.parser.service.model.lang.Action)

Aggregations

Action (org.ballerinalang.composer.service.ballerina.parser.service.model.lang.Action)2 BLangAction (org.wso2.ballerinalang.compiler.tree.BLangAction)2 ArrayList (java.util.ArrayList)1 AnnotationAttachment (org.ballerinalang.composer.service.ballerina.parser.service.model.lang.AnnotationAttachment)1 ModelPackage (org.ballerinalang.composer.service.ballerina.parser.service.model.lang.ModelPackage)1 Parameter (org.ballerinalang.composer.service.ballerina.parser.service.model.lang.Parameter)1 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)1