Search in sources :

Example 86 with Parameter

use of org.wso2.siddhi.annotation.Parameter in project ballerina by ballerina-lang.

the class HtmlDocTest method testFunctionsPropertiesExtracted.

@Test(description = "Function properties should be available via construct")
public void testFunctionsPropertiesExtracted() throws Exception {
    BLangPackage bLangPackage = createPackage("package x.y; " + "@Description { value:\"This function would say hello\"}" + "@Param { value:\"message: The message sent\" }" + "@Return { value:\"int representation of the message\" }" + "public function sayHello(string message) returns (int){}");
    FunctionDoc functionDoc = Generator.createDocForNode(bLangPackage.getFunctions().get(0));
    Assert.assertEquals(functionDoc.name, "sayHello", "Function name should be extracted");
    Assert.assertEquals(functionDoc.description, "This function would say hello", "Description of the " + "function should be extracted");
    Assert.assertEquals(functionDoc.parameters.get(0).name, "message", "Parameter name should be extracted");
    Assert.assertEquals(functionDoc.parameters.get(0).dataType, "string", "Parameter type should be extracted");
    Assert.assertEquals(functionDoc.parameters.get(0).description, "The message sent", "Description of the " + "parameter should be extracted");
    Assert.assertEquals(functionDoc.returnParams.get(0).dataType, "int", "Return parameter type " + "should be extracted");
    Assert.assertEquals(functionDoc.returnParams.get(0).description, "int representation of the message", "Description of the return parameter should be extracted");
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) FunctionDoc(org.ballerinalang.docgen.model.FunctionDoc) Test(org.testng.annotations.Test)

Example 87 with Parameter

use of org.wso2.siddhi.annotation.Parameter in project ballerina by ballerina-lang.

the class ResourceContextHolder method buildContext.

public static ResourceContextHolder buildContext(ResourceNode resource) throws CodeGeneratorException {
    ResourceContextHolder context = new ResourceContextHolder();
    context.name = resource.getName().getValue();
    context.parameters = new ArrayList<>();
    for (VariableNode node : resource.getParameters()) {
        ParameterContextHolder parameter = ParameterContextHolder.buildContext(node);
        if (parameter != null) {
            context.parameters.add(parameter);
        }
    }
    // Iterate through all resource level annotations and find out resource configuration information
    AnnotationAttachmentNode ann = GeneratorUtils.getAnnotationFromList(GeneratorConstants.RES_CONFIG_ANNOTATION, GeneratorConstants.HTTP_PKG_ALIAS, resource.getAnnotationAttachments());
    if (ann == null) {
        throw new CodeGeneratorException("Incomplete resource configuration found");
    }
    BLangRecordLiteral bLiteral = ((BLangRecordLiteral) ((BLangAnnotationAttachment) ann).getExpression());
    List<BLangRecordLiteral.BLangRecordKeyValue> list = bLiteral.getKeyValuePairs();
    Map<String, String[]> attrs = GeneratorUtils.getKeyValuePairAsMap(list);
    // We don't expect multiple http methods to be supported by single action
    // We only consider first content type for a single resource
    context.method = attrs.get(GeneratorConstants.ATTR_METHODS) != null ? attrs.get(GeneratorConstants.ATTR_METHODS)[0] : null;
    context.contentType = attrs.get(GeneratorConstants.ATTR_CONSUMES) != null ? attrs.get(GeneratorConstants.ATTR_CONSUMES)[0] : null;
    String path = attrs.get(GeneratorConstants.ATTR_PATH) != null ? attrs.get(GeneratorConstants.ATTR_PATH)[0] : null;
    context.path = context.getTemplatePath(path);
    return context;
}
Also used : VariableNode(org.ballerinalang.model.tree.VariableNode) BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) CodeGeneratorException(org.ballerinalang.code.generator.exception.CodeGeneratorException) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 88 with Parameter

use of org.wso2.siddhi.annotation.Parameter in project ballerina by ballerina-lang.

the class ParameterContextHolder method buildContext.

/**
 * Build a readable parameter model from a Ballerina <code>VariableNode</code>.
 *
 * @param parameter {@code VariableNode} with parameter definition
 * @return built Parameter context model
 */
public static ParameterContextHolder buildContext(VariableNode parameter) {
    ParameterContextHolder context = new ParameterContextHolder();
    TypeNode type = parameter.getTypeNode();
    if (type instanceof BLangValueType) {
        context.type = ((BLangValueType) parameter.getTypeNode()).getTypeKind().typeName();
    } else if (type instanceof BLangUserDefinedType) {
        context.type = ((BLangUserDefinedType) parameter.getTypeNode()).getTypeName().getValue();
    }
    // Ignore Connection and InRequest parameters
    if (context.isIgnoredType(context.type)) {
        return null;
    }
    context.name = parameter.getName().toString();
    context.defaultValue = context.getDefaultValue(context.type, context.name);
    // examples are not yet supported
    context.example = "";
    return context;
}
Also used : BLangValueType(org.wso2.ballerinalang.compiler.tree.types.BLangValueType) TypeNode(org.ballerinalang.model.tree.types.TypeNode) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType)

Example 89 with Parameter

use of org.wso2.siddhi.annotation.Parameter in project ballerina by ballerina-lang.

the class DocumentationTest method testDocFunction.

@Test(description = "Test doc function.")
public void testDocFunction() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/function.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    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(), "file");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " file path ``C:\\users\\OddThinking\\Documents\\My Source\\Widget\\foo.src``\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "accessMode");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " read or write mode\n");
    docNodes = ((BLangStruct) packageNode.getStructs().get(0)).docAttachments;
    dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, " Documentation for File struct\n");
    Assert.assertEquals(dNode.getAttributes().size(), 1);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "path");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " struct `field path` documentation\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 90 with Parameter

use of org.wso2.siddhi.annotation.Parameter in project ballerina by ballerina-lang.

the class DocumentationTest method testDocConnectorFunction.

@Test(description = "Test doc connector/function.", enabled = false)
public void testDocConnectorFunction() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/connector_function.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    BLangConnector connector = (BLangConnector) packageNode.getConnectors().get(0);
    List<BLangDocumentation> docNodes = connector.docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.documentationText, "Test Connector\n");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "url");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " url for endpoint\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "path");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " path for endpoint\n");
    dNode = connector.getActions().get(0).docAttachments.get(0);
    Assert.assertEquals(dNode.getAttributes().size(), 1);
    Assert.assertEquals(dNode.documentationText, "Test Connector action testAction ");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "s");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " which represent successful or not");
    dNode = connector.getActions().get(1).docAttachments.get(0);
    Assert.assertEquals(dNode.documentationText, "Test Connector action testSend ");
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "ep");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " which represent successful or not ");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "s");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " which represent successful or not");
    docNodes = ((BLangFunction) packageNode.getFunctions().get(0)).docAttachments;
    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(), 3);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "file");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " file path ``C:\\users\\OddThinking\\Documents\\My Source\\Widget\\foo.src``\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "accessMode");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " read or write mode\n");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "successful");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " boolean `true` or `false`\n");
    docNodes = ((BLangStruct) packageNode.getStructs().get(0)).docAttachments;
    dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, " Documentation for File struct\n");
    Assert.assertEquals(dNode.getAttributes().size(), 1);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "path");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " struct `field path` documentation\n");
}
Also used : BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) Test(org.testng.annotations.Test)

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