use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project ballerina by ballerina-lang.
the class Generator method createDocForNode.
/**
* Create documentation for functions.
* @param functionNode ballerina function node.
* @return documentation for functions.
*/
public static FunctionDoc createDocForNode(BLangFunction functionNode) {
String functionName = functionNode.getName().value;
List<Variable> parameters = new ArrayList<>();
List<Variable> returnParams = new ArrayList<>();
// Iterate through the parameters
if (functionNode.getParameters().size() > 0) {
for (BLangVariable param : functionNode.getParameters()) {
String dataType = type(param);
String desc = paramAnnotation(functionNode, param);
Variable variable = new Variable(param.getName().value, dataType, desc);
parameters.add(variable);
}
}
// Iterate through the return types
if (functionNode.getReturnParameters().size() > 0) {
for (int i = 0; i < functionNode.getReturnParameters().size(); i++) {
BLangVariable returnParam = functionNode.getReturnParameters().get(i);
String dataType = type(returnParam);
String desc = returnParamAnnotation(functionNode, i);
Variable variable = new Variable(returnParam.getName().value, dataType, desc);
returnParams.add(variable);
}
}
return new FunctionDoc(functionName, description(functionNode), new ArrayList<>(), parameters, returnParams);
}
use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project ballerina by ballerina-lang.
the class ProducesConsumesAnnotationTest method testWithoutProducesConsumeAnnotation.
@Test(description = "Test without Pro-Con annotation with URL. /echo67/echo1 ")
public void testWithoutProducesConsumeAnnotation() {
String path = "/echo67/echo1";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
cMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), "text/plain; charset=ISO-8859-4");
cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), "text/*;q=0.3, text/html;Level=1;q=0.7");
HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("echo33").asText(), "echo1", "No media types");
}
use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project ballerina by ballerina-lang.
the class ProducesConsumesAnnotationTest method testProducesConsumeAnnotation.
@Test(description = "Test Produces and Consumes with URL. /echo66/test3 ")
public void testProducesConsumeAnnotation() {
String path = "/echo66/test3";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Test");
cMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), "text/plain; charset=ISO-8859-4");
cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), "text/*;q=0.3, text/html;Level=1;q=0.7");
HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("msg").asText(), "wso222", "media types matched");
}
use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project jaggery by wso2.
the class RegistryHostObject method jsFunction_get.
public static Scriptable jsFunction_get(Context cx, Scriptable thisObj, Object[] arguments, Function funObj) throws ScriptException {
RegistryHostObject rho = (RegistryHostObject) thisObj;
if (arguments.length == 1) {
if (arguments[0] instanceof String) {
try {
Scriptable hostObject;
Resource resource = rho.registry.get((String) arguments[0]);
if (resource instanceof Collection) {
hostObject = cx.newObject(rho, "Collection", new Object[] { resource });
} else {
hostObject = cx.newObject(rho, "Resource", new Object[] { resource });
}
return hostObject;
} catch (RegistryException e) {
throw new ScriptException("Registry error occurred while executing get() operation", e);
}
} else {
throw new ScriptException("Path argument of method get() should be a string");
}
} else if (arguments.length == 3) {
if (arguments[0] instanceof String && arguments[1] instanceof Number && arguments[2] instanceof Number) {
try {
Collection collection = rho.registry.get((String) arguments[0], ((Number) arguments[1]).intValue(), ((Number) arguments[2]).intValue());
CollectionHostObject cho = (CollectionHostObject) cx.newObject(rho, "Collection", new Object[] { collection });
return cho;
} catch (RegistryException e) {
throw new ScriptException("Registry error occurred while executing get() operation", e);
}
} else {
throw new ScriptException("Invalid argument types for get() method");
}
} else {
throw new ScriptException("Invalid no. of arguments for get() method");
}
}
use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-apimgt by wso2.
the class AbstractKeyManager method buildFromJSON.
/**
* This method will accept json String and will do the json parse will set oAuth application properties to OAuthApplicationInfo object.
*
* @param jsonInput this jsonInput will contain set of oAuth application properties.
* @return OAuthApplicationInfo object will be return.
* @throws APIManagementException
*/
public OAuthApplicationInfo buildFromJSON(OAuthApplicationInfo oAuthApplicationInfo, String jsonInput) throws APIManagementException {
// initiate json parser.
JSONParser parser = new JSONParser();
JSONObject jsonObject;
try {
// parse json String
jsonObject = (JSONObject) parser.parse(jsonInput);
if (jsonObject != null) {
// create a map to hold json parsed objects.
Map<String, Object> params = (Map) jsonObject;
if (params.get(APIConstants.JSON_CALLBACK_URL) != null) {
oAuthApplicationInfo.setCallBackURL((String) params.get(APIConstants.JSON_CALLBACK_URL));
}
if (params.get(APIConstants.JSON_GRANT_TYPES) != null) {
String grantTypeString = params.get(APIConstants.JSON_GRANT_TYPES).toString();
if (StringUtils.isEmpty(oAuthApplicationInfo.getCallBackURL()) && (grantTypeString.contains("implicit") || grantTypeString.contains("authorization_code"))) {
throw new EmptyCallbackURLForCodeGrantsException("The callback url must have at least one URI " + "value when using Authorization code or implicit grant types.");
}
}
// set client Id
if (params.get(APIConstants.JSON_CLIENT_ID) != null) {
oAuthApplicationInfo.setClientId((String) params.get(APIConstants.JSON_CLIENT_ID));
}
// set client secret
if (params.get(APIConstants.JSON_CLIENT_SECRET) != null) {
oAuthApplicationInfo.setClientSecret((String) params.get(APIConstants.JSON_CLIENT_SECRET));
}
// copy all params map in to OAuthApplicationInfo's Map object.
oAuthApplicationInfo.putAll(params);
validateOAuthAppCreationProperties(oAuthApplicationInfo);
return oAuthApplicationInfo;
}
} catch (ParseException e) {
handleException("Error occurred while parsing JSON String", e);
}
return null;
}
Aggregations