public void visit(BLangFunction funcNode) { List<BLangAnnotationAttachment> attachmentList = funcNode.getAnnotationAttachments(); notifyProcessors(attachmentList, (processor, list) -> processor.process(funcNode, list)); funcNode.endpoints.forEach(endpoint -> endpoint.accept(this)); }
AnnotationAttachmentNode annotation = ConverterUtils .getAnnotationFromList(HttpConstants.ANN_NAME_RESOURCE_CONFIG, httpAlias, resource.getAnnotationAttachments()); Set<String> httpMethods = new LinkedHashSet<>();
/** * Parses the 'ResourceInfo' annotation and builds swagger operation. * * @param resource The resource definition. * @param operation The swagger operation. */ private void parseResourceInfo(BLangFunction resource, Operation operation, String httpMethod) { AnnotationAttachmentNode multiResourceInfoAnnotation = ConverterUtils .getAnnotationFromList(ConverterConstants.ANNON_MULTI_RES_INFO, swaggerAlias, resource.getAnnotationAttachments()); if (multiResourceInfoAnnotation != null) { parseMultiResourceInfoAnnotationAttachment(multiResourceInfoAnnotation, operation, httpMethod); } else { AnnotationAttachmentNode annotation = ConverterUtils .getAnnotationFromList(ConverterConstants.ANNON_RES_INFO, swaggerAlias, resource.getAnnotationAttachments()); if (annotation != null) { BLangRecordLiteral bLiteral = ((BLangRecordLiteral) ((BLangAnnotationAttachment) annotation) .getExpression()); addResourceInfoToOperation(bLiteral, operation); } } }
private static DocAttachmentInfo getFunctionNodeDocumentation(BLangFunction bLangFunction) { List<String> attributes = new ArrayList<>(); DiagnosticPos functionPos = CommonUtil.toZeroBasedPosition(bLangFunction.getPosition()); List<BLangAnnotationAttachment> annotations = bLangFunction.getAnnotationAttachments(); Position docStart = getDocumentationStartPosition(bLangFunction.getPosition(), annotations); int offset = functionPos.getStartColumn(); List<BLangVariable> params = new ArrayList<>(bLangFunction.getParameters()); if (bLangFunction.getRestParameters() != null) { params.add((BLangVariable) bLangFunction.getRestParameters()); } params.addAll(bLangFunction.getDefaultableParameters() .stream() .map(bLangVariableDef -> bLangVariableDef.var) .collect(Collectors.toList())); params.sort(new FunctionArgsComparator()); params.forEach(param -> attributes.add(getDocAttributeFromBLangVariable((BLangSimpleVariable) param, offset))); if (bLangFunction.symbol.retType.getKind() != TypeKind.NIL) { attributes.add(getReturnFieldDescription(offset)); } return new DocAttachmentInfo(getDocumentationAttachment(attributes, functionPos.getStartColumn()), docStart); }
/** * Gets the path value of the @http:resourceConfig. * * @param resource The ballerina resource. * @return The path value. */ private String getPath(BLangFunction resource) { String path = "/" + resource.getName(); AnnotationAttachmentNode annotation = ConverterUtils .getAnnotationFromList(HttpConstants.ANN_NAME_RESOURCE_CONFIG, httpAlias, resource.getAnnotationAttachments()); if (annotation != null) { BLangRecordLiteral bLiteral = ((BLangRecordLiteral) ((BLangAnnotationAttachment) annotation) .getExpression()); List<BLangRecordLiteral.BLangRecordKeyValue> list = bLiteral.getKeyValuePairs(); Map<String, BLangExpression> attributes = ConverterUtils.listToMap(list); if (attributes.containsKey(HttpConstants.ANN_RESOURCE_ATTR_PATH)) { path = ConverterUtils.getStringLiteralValue(attributes.get(HttpConstants.ANN_RESOURCE_ATTR_PATH)); } } return path; }
AnnotationAttachmentNode annotation = ConverterUtils .getAnnotationFromList(HttpConstants.ANN_NAME_RESOURCE_CONFIG, httpAlias, resource.getAnnotationAttachments());