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");
}
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;
}
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;
}
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");
}
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");
}
Aggregations