Search in sources :

Example 1 with Parameter

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

the class ParserUtils method createNewParameter.

/**
 * Create new parameter.
 *
 * @param name parameter name
 * @param type parameter type
 * @return {Parameter} parameter
 */
private static Parameter createNewParameter(String name, String type, BLangType typeNode) {
    Parameter parameter = new Parameter();
    parameter.setType(type);
    parameter.setName(name);
    BType bType = typeNode.type;
    if (bType instanceof BConnectorType) {
        parameter.setPkgAlias(((BLangUserDefinedType) typeNode).pkgAlias.toString());
        parameter.setConnector(true);
    }
    return parameter;
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BConnectorType(org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType) Parameter(org.ballerinalang.composer.service.ballerina.parser.service.model.lang.Parameter) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType)

Example 2 with Parameter

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

the class ParserUtils method extractFunction.

/**
 * Extract Functions from ballerina lang.
 *
 * @param packages    packages to send.
 * @param packagePath package path
 * @param function    function.
 */
private static void extractFunction(Map<String, ModelPackage> packages, String packagePath, BLangFunction function) {
    String fileName = function.getPosition().getSource().getCompilationUnitName();
    if (packages.containsKey(packagePath)) {
        ModelPackage modelPackage = packages.get(packagePath);
        List<Parameter> parameters = new ArrayList<>();
        addParameters(parameters, function.getParameters());
        List<Parameter> returnParameters = new ArrayList<>();
        addParameters(returnParameters, function.getReturnParameters());
        List<AnnotationAttachment> annotations = new ArrayList<>();
        addAnnotations(annotations, function.getAnnotationAttachments());
        String receiverType = getReceiverType(function.getReceiver());
        // Check if the function is public or not
        boolean isPublic = function.getFlags().contains(Flag.PUBLIC);
        modelPackage.addFunctionsItem(createNewFunction(function.getName().getValue(), annotations, parameters, returnParameters, receiverType, isPublic, fileName));
    } else {
        ModelPackage modelPackage = new ModelPackage();
        modelPackage.setName(packagePath);
        List<Parameter> parameters = new ArrayList<>();
        addParameters(parameters, function.getParameters());
        List<Parameter> returnParameters = new ArrayList<>();
        addParameters(returnParameters, function.getReturnParameters());
        List<AnnotationAttachment> annotations = new ArrayList<>();
        addAnnotations(annotations, function.getAnnotationAttachments());
        String receiverType = getReceiverType(function.getReceiver());
        // Check if the function is public or not
        boolean isPublic = function.getFlags().contains(Flag.PUBLIC);
        modelPackage.addFunctionsItem(createNewFunction(function.getName().getValue(), annotations, parameters, returnParameters, receiverType, isPublic, fileName));
        packages.put(packagePath, modelPackage);
    }
}
Also used : 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 3 with Parameter

use of org.ballerinalang.composer.service.ballerina.parser.service.model.lang.Parameter 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)

Aggregations

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