Search in sources :

Example 91 with Parameter

use of org.wso2.transport.http.netty.config.Parameter in project ballerina by ballerina-lang.

the class DocumentationTest method testDocNativeFunction.

@Test(description = "Test doc native function.")
public void testDocNativeFunction() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/native_function.bal", CompilerPhase.TYPE_CHECK);
    Assert.assertEquals(1, compileResult.getWarnCount());
    BAssertUtil.validateWarning(compileResult, 0, "no such documentable attribute 'successful' with doc prefix 'P'", 6, 1);
    PackageNode packageNode = compileResult.getAST();
    List<BLangDocumentation> docNodes = ((BLangFunction) packageNode.getFunctions().get(0)).docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, "\n" + "Gets a access parameter value (`true` or `false`) for a given key. " + "Please note that #foo will always be bigger than #bar.\n" + "Example:\n" + "``SymbolEnv pkgEnv = symbolEnter.packageEnvs.get(pkgNode.symbol);``\n");
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "accessMode");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " read or write mode\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "successful");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " boolean `true` or `false`\n");
}
Also used : BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) Test(org.testng.annotations.Test)

Example 92 with Parameter

use of org.wso2.transport.http.netty.config.Parameter in project ballerina by ballerina-lang.

the class ParserUtils method createNewConnector.

/**
 * Create new connector.
 *
 * @param name         name of the connector
 * @param annotations  list of annotation
 * @param actions      list of actions
 * @param params       list of params
 * @param returnParams list of return params
 * @return {Connector} connector
 */
private static Connector createNewConnector(String name, List<AnnotationAttachment> annotations, List<Action> actions, List<Parameter> params, List<Parameter> returnParams, String fileName) {
    Connector connector = new Connector();
    connector.setName(name);
    connector.setActions(actions);
    connector.setParameters(params);
    connector.setAnnotations(annotations);
    connector.setReturnParameters(returnParams);
    connector.setFileName(fileName);
    return connector;
}
Also used : Connector(org.ballerinalang.composer.service.ballerina.parser.service.model.lang.Connector) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector)

Example 93 with Parameter

use of org.wso2.transport.http.netty.config.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 94 with Parameter

use of org.wso2.transport.http.netty.config.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)

Example 95 with Parameter

use of org.wso2.transport.http.netty.config.Parameter 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

HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)19 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)14 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)11 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)11 CharonException (org.wso2.charon3.core.exceptions.CharonException)11 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)11 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)11 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)11 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)11 Test (org.testng.annotations.Test)8 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)8 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)8 JSONEncoder (org.wso2.charon3.core.encoder.JSONEncoder)8 List (java.util.List)7 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)7 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)7 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)7 Parameter (org.apache.axis2.description.Parameter)6 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)6