use of org.ballerinalang.plugins.idea.psi.ParameterTypeName in project ballerina by ballerina-lang.
the class BallerinaDocumentationProvider method getReturnTypes.
/**
* Returns the return types of the given definition node. This return types are later used to generate the
* signature.
*
* @param definitionNode definition node which we want to get the return types
* @return list of return type strings.
*/
private static List<String> getReturnTypes(PsiElement definitionNode) {
List<String> results = new LinkedList<>();
// Parameters are in the ReturnParameterNode. So we first get the ReturnParameterNode from the definition
// node.
ReturnParameterNode node = PsiTreeUtil.findChildOfType(definitionNode, ReturnParameterNode.class);
if (node == null) {
return results;
}
// But there can be two possible scenarios. The actual return types can be in either ParameterTypeNameList or
// ParameterListNode. This is because return types can be named parameters. In that case, ParameterListNode is
// available.
// First we check for ParameterTypeNameList.
ParameterTypeNameList parameterTypeNameList = PsiTreeUtil.findChildOfType(node, ParameterTypeNameList.class);
// If it is available, that means the return types are not named parameters.
if (parameterTypeNameList != null) {
// Each parameter will be of type TypeNameNode. So we get all return types.
Collection<ParameterTypeName> parameterTypeNames = PsiTreeUtil.getChildrenOfTypeAsList(parameterTypeNameList, ParameterTypeName.class);
// Add each TypeNameNode to the result list.
parameterTypeNames.forEach(parameterTypeName -> {
TypeNameNode typeNameNode = PsiTreeUtil.getChildOfType(parameterTypeName, TypeNameNode.class);
if (typeNameNode != null) {
results.add(BallerinaParameterInfoHandler.formatParameter(typeNameNode.getText()));
}
});
// Return the results.
return results;
}
// If there is no return type node, we check for ParameterListNode.
ParameterListNode parameterListNode = PsiTreeUtil.findChildOfType(node, ParameterListNode.class);
if (parameterListNode != null) {
// Actual parameters are in ParameterNodes.
Collection<ParameterNode> parameterNodes = PsiTreeUtil.findChildrenOfType(parameterListNode, ParameterNode.class);
// Add each ParameterNode to the result list.
parameterNodes.forEach(parameterNode -> results.add(BallerinaParameterInfoHandler.formatParameter(parameterNode.getText())));
// Return the results.
return results;
}
// Return empty list.
return results;
}
use of org.ballerinalang.plugins.idea.psi.ParameterTypeName in project ballerina by ballerina-lang.
the class BallerinaParameterInfoHandler method getParameterPresentations.
public static List<String> getParameterPresentations(ParameterTypeNameList node) {
List<String> params = new LinkedList<>();
if (node == null) {
return params;
}
// Get type name nodes.
Collection<ParameterTypeName> parameterTypeNames = PsiTreeUtil.findChildrenOfType(node, ParameterTypeName.class);
for (ParameterTypeName parameterTypeName : parameterTypeNames) {
TypeNameNode typeNameNode = PsiTreeUtil.getChildOfType(parameterTypeName, TypeNameNode.class);
if (typeNameNode != null) {
params.add(parameterTypeName.getText());
}
}
return params;
}
Aggregations