@Override public Map<String, BLangMarkdownParameterDocumentation> getParameterDocumentations() { Map<String, BLangMarkdownParameterDocumentation> parameterDocumentations = new HashMap<>(); parameters.forEach(p -> parameterDocumentations.put(p.getParameterName().getValue(), p)); return parameterDocumentations; }
private IdentifierNode createIdentifier(String value) { IdentifierNode node = TreeBuilder.createIdentifierNode(); if (value == null) { return node; } if (value.startsWith(IDENTIFIER_LITERAL_PREFIX) && value.endsWith(IDENTIFIER_LITERAL_SUFFIX)) { value = StringEscapeUtils.unescapeJava(value); node.setValue(value.substring(2, value.length() - 1)); node.setLiteral(true); } else { node.setValue(value); node.setLiteral(false); } return node; }
private static IdentifierNode createIdentifier(String value) { IdentifierNode node = TreeBuilder.createIdentifierNode(); if (value != null) { node.setValue(value); } return node; }
private IdentifierNode createIdentifier(String value) { IdentifierNode node = TreeBuilder.createIdentifierNode(); if (value != null) { node.setValue(value); } return node; }
@Override public void visit(BLangInvocation invocationExpr) { StringBuilder sqlStringBuilder = new StringBuilder(); if (invocationExpr.pkgAlias != null) { String pkgAlias = invocationExpr.pkgAlias.value; if (pkgAlias != null && !pkgAlias.isEmpty()) { sqlStringBuilder.append(pkgAlias).append(":"); } } sqlStringBuilder.append(invocationExpr.getName().getValue()).append("("); List<String> argList = new ArrayList<>(); for (BLangExpression arg : invocationExpr.argExprs) { arg.accept(this); argList.add(exprStack.pop()); } sqlStringBuilder.append(String.join(", ", argList)).append(")"); exprStack.push(sqlStringBuilder.toString()); }
void endTableDataList(DiagnosticPos pos, Set<Whitespace> ws) { BLangRecordLiteral recordLiteral = (BLangRecordLiteral) TreeBuilder.createRecordLiteralNode(); List<BLangTableLiteral.BLangTableColumn> keyNames = tableLiteralNodes.peek().columns; List<ExpressionNode> recordValues = exprNodeListStack.pop(); if (keyNames.size() == recordValues.size()) { int index = 0; for (ExpressionNode expr : recordValues) { BLangRecordKeyValue keyValue = (BLangRecordKeyValue) TreeBuilder.createRecordKeyValue(); //Value keyValue.valueExpr = (BLangExpression) expr; //key BLangSimpleVarRef keyExpr = (BLangSimpleVarRef) TreeBuilder.createSimpleVariableReferenceNode(); keyExpr.pos = pos; IdentifierNode identifierNode = TreeBuilder.createIdentifierNode(); identifierNode.setValue(keyNames.get(index).columnName); keyExpr.variableName = (BLangIdentifier) identifierNode; keyValue.key = new BLangRecordKey(keyExpr); //Key-Value pair recordLiteral.keyValuePairs.add(keyValue); ++index; } recordLiteral.addWS(ws); recordLiteral.pos = pos; if (commaWsStack.size() > 0) { recordLiteral.addWS(commaWsStack.pop()); } this.tableLiteralNodes.peek().tableDataRows.add(recordLiteral); } }
/** * Retrieve a specific annotation by name from a list of annotations. * * @param name name of the required annotation * @param pkg package of the required annotation * @param annotations list of annotations containing the required annotation * @return returns annotation with the name <code>name</code> if found or * null if annotation not found in the list */ public static AnnotationAttachmentNode getAnnotationFromList(String name, String pkg, List<? extends AnnotationAttachmentNode> annotations) { AnnotationAttachmentNode annotation = null; if (name == null || pkg == null) { return null; } for (AnnotationAttachmentNode ann : annotations) { if (pkg.equals(ann.getPackageAlias().getValue()) && name.equals(ann.getAnnotationName().getValue())) { annotation = ann; } } return annotation; }
private void addImportPkg(BLangPackage bLangPackage, String orgName, String sourcePkgName, String version) { List<Name> nameComps = getPackageNameComps(sourcePkgName); List<BLangIdentifier> pkgNameComps = new ArrayList<>(); nameComps.forEach(comp -> { IdentifierNode node = TreeBuilder.createIdentifierNode(); node.setValue(comp.value); pkgNameComps.add((BLangIdentifier) node); }); BLangIdentifier orgNameNode = (BLangIdentifier) TreeBuilder.createIdentifierNode(); orgNameNode.setValue(orgName); BLangIdentifier versionNode = (BLangIdentifier) TreeBuilder.createIdentifierNode(); versionNode.setValue(version); BLangImportPackage importDcl = (BLangImportPackage) TreeBuilder.createImportPackageNode(); importDcl.pos = bLangPackage.pos; importDcl.pkgNameComps = pkgNameComps; importDcl.orgName = orgNameNode; importDcl.version = versionNode; BLangIdentifier alias = (BLangIdentifier) TreeBuilder.createIdentifierNode(); alias.setValue(names.merge(Names.ORG_NAME_SEPARATOR, nameComps.get(nameComps.size() - 1)).value); importDcl.alias = alias; bLangPackage.imports.add(importDcl); }
/** * Retrieves a specific annotation by name from a list of annotations. * * @param name name of the required annotation * @param pkg package of the required annotation * @param annotations list of annotations containing the required annotation * @return returns annotation with the name <code>name</code> if found or * null if annotation not found in the list */ public static AnnotationAttachmentNode getAnnotationFromList(String name, String pkg, List<? extends AnnotationAttachmentNode> annotations) { AnnotationAttachmentNode annotation = null; if (name == null || pkg == null) { return null; } for (AnnotationAttachmentNode ann : annotations) { if (pkg.equals(ann.getPackageAlias().getValue()) && name.equals(ann.getAnnotationName().getValue())) { annotation = ann; } } return annotation; } }
private String getParamNames(List<BLangVariable> paramTypes) { return paramTypes.stream().map(paramType -> { if (paramType.getKind() == NodeKind.USER_DEFINED_TYPE) { return ((UserDefinedTypeNode) paramType).getTypeName().getValue(); } else { return paramType.toString(); } }).collect(Collectors.joining(", ")); } }
@Override public void visit(BLangStreamAction streamAction) { streamActionClause = new StringBuilder("insert into "); String streamName = "stream" + streamAction.getInvokableBody().getFunctionNode().getName().getValue(); streamName = streamName.replaceAll("\\$", "_"); streamActionClause.append(streamName); }
/** * Get the current file's imports. * * @param pkg BLangPackage to extract content from * @param ctx LS Operation Context * @return {@link List} List of imports in the current file */ public static List<BLangImportPackage> getCurrentFileImports(BLangPackage pkg, LSContext ctx) { String currentFile = ctx.get(DocumentServiceKeys.RELATIVE_FILE_PATH_KEY); return getCurrentFileTopLevelNodes(pkg, ctx).stream() .filter(topLevelNode -> topLevelNode instanceof BLangImportPackage) .map(topLevelNode -> (BLangImportPackage) topLevelNode) .filter(bLangImportPackage -> bLangImportPackage.pos.getSource().cUnitName.replace("/", FILE_SEPARATOR).equals(currentFile) && !(bLangImportPackage.getOrgName().getValue().equals("ballerina") && getPackageNameComponentsCombined(bLangImportPackage).equals("transaction"))) .collect(Collectors.toList()); }
private String getOutputFilePath(ServiceNode serviceNode) { String cUnit = serviceNode.getPosition().getSource().getCompilationUnitName(); String dir = cUnit.substring(0, cUnit.lastIndexOf(File.separator) + 1); String file = serviceNode.getName().getValue().toLowerCase(Locale.ENGLISH) + "_client.bal"; return dir + file; }
@Override public void process(ServiceNode serviceData, List<AnnotationAttachmentNode> annotations) { List<BLangFunction> resources = (List<BLangFunction>) serviceData.getResources(); resources.forEach(res -> validate(serviceData.getName().getValue(), res, this.dlog)); }
private void extractDetails(EndpointNode ep, AnnotationAttachmentNode ann) { this.name = ep.getName().getValue();
packageNode.getGlobalEndpoints().forEach(endpoint -> strings.add(endpoint.getName().getValue())); packageNode.getServices().forEach(service -> strings.add(service.name.value)); packageNode.getFunctions().forEach(func -> strings.add(func.name.value));
if (servicepkg instanceof ServiceNode) { ServiceNode pkg = ((ServiceNode) servicepkg); services.add(pkg.getName().getValue());
private static boolean isServerStreaming(FunctionNode resourceNode) { boolean serverStreaming = false; for (AnnotationAttachmentNode annotationNode : resourceNode.getAnnotationAttachments()) { if (!ANN_RESOURCE_CONFIG.equals(annotationNode.getAnnotationName().getValue())) { continue; } if (annotationNode.getExpression() instanceof BLangRecordLiteral) { List<BLangRecordLiteral.BLangRecordKeyValue> attributes = ((BLangRecordLiteral) annotationNode .getExpression()).getKeyValuePairs(); for (BLangRecordLiteral.BLangRecordKeyValue attributeNode : attributes) { String attributeName = attributeNode.getKey().toString(); String attributeValue = attributeNode.getValue() != null ? attributeNode.getValue().toString() : null; if (ANN_ATTR_RESOURCE_SERVER_STREAM.equals(attributeName)) { serverStreaming = attributeValue != null && Boolean.parseBoolean(attributeValue); } } } } return serverStreaming; }
@SuppressWarnings("unchecked") @Override public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) { if (annotations.size() > 1) { int count = 0; for (AnnotationAttachmentNode annotation : annotations) { if (annotation.getAnnotationName().getValue().equals(WEBSOCKET_ANNOTATION_CONFIGURATION)) { count++; } } if (count > 1) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), "There cannot be more than one " + WEBSOCKET_SERVICE + " annotations"); } } List<BLangFunction> resources = (List<BLangFunction>) serviceNode.getResources(); resources.forEach( res -> WebSocketResourceValidator.validate(res, dlog, isResourceReturnsErrorOrNil(res), false)); } }
/** * Build a parsable context from a Ballerina {@link ServiceNode}. * * @param service {@code ServiceNode} for a valid ballerina source file * @param endpoints list of endpoints to be used as service endpoints for generated client * @return A parsable data model for provided ballerina {@code service} * @throws CodeGeneratorException when there are generation exceptions */ public static ClientContextHolder buildContext(ServiceNode service, List<EndpointNode> endpoints) throws CodeGeneratorException { ClientContextHolder context = new ClientContextHolder(); context.name = service.getName().getValue(); context.resources = new ArrayList<>(); context.endpoints = new ArrayList<>(); // Extract bound endpoint details for (EndpointNode ep : endpoints) { EndpointContextHolder epContext = EndpointContextHolder.buildContext(service, ep); if (epContext != null) { context.endpoints.add(EndpointContextHolder.buildContext(service, ep)); } } // Extract ballerina resource nodes as parsable resources for (ResourceNode resource: service.getResources()) { ResourceContextHolder operation = ResourceContextHolder.buildContext(resource); context.resources.add(operation); } return context; }