### Example Run with Specific Ballerina Distribution (Linux/macOS) Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/ballerina-shell/README.md An example of running the Ballerina REPL with a specific Ballerina distribution path. This is useful for testing compatibility. ```bash java -jar -Dballerina.home=/usr/lib/ballerina/distributions/ballerina-slp8 shell-cli/build/libs/shell-cli-1.0-SNAPSHOT.jar ``` -------------------------------- ### Sample Ballerina Function with Documentation Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/docerina/docs/README.md This example demonstrates a Ballerina function with inline documentation, including a description, an example, and documentation attributes for parameters and return values. ```ballerina documentation { Submits an HTTP request to a service with the specified HTTP verb. The `submit()` function does not give out a `Response` as the result, rather it returns an `HttpFuture` which can be used to do further interactions with the endpoint. Example: ```ballerina HttpFuture future = myMsg.submit("GET", "/test", req); ``` P{{httpVerb}} The HTTP verb value P{{path}} The resource path P{{request}} An HTTP outbound request message R{{}} An `HttpFuture` that represents an asynchronous service invocation, or an `error` if the submission fails } public function submit(@sensitive string httpVerb, string path, Request request) returns HttpFuture|error; ``` -------------------------------- ### List all installed tools Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-help.txt Displays a list of all tools currently installed in your local Ballerina environment. This helps in managing your installed toolset. ```bash bal tool list ``` -------------------------------- ### Example Source Directory Configuration Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/ballerina-maven-plugins/docs/DocerinaMavenPlugin.md Specify a comma-separated list of directories containing Ballerina source files for documentation generation. ```xml /home/docerina/abc/src,/home/docerina/xyz/src ``` -------------------------------- ### Example Package Filter Configuration Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/ballerina-maven-plugins/docs/DocerinaMavenPlugin.md Provide a comma-separated list of package names to exclude from the generated documentation. ```xml org.ballerinalang.abc.a,org.ballerinalang.xyz.x ``` -------------------------------- ### Example Generate TOC Configuration Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/ballerina-maven-plugins/docs/DocerinaMavenPlugin.md Set to 'true' to generate a table of contents for packages in the documentation. Defaults to 'false'. ```xml false ``` -------------------------------- ### useTransition Hook Example Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html Demonstrates the use of useTransition for managing pending states during transitions. ```javascript useTransition:function(e){var t=ei(!1),n=t[0];return t=t[1],[di(gi.bind(null,t,e),[t,e]),n]} ``` -------------------------------- ### Example Output Directory Configuration Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/ballerina-maven-plugins/docs/DocerinaMavenPlugin.md Define the directory where the generated API documentation will be stored. Defaults to the Maven project's build directory. ```xml /home/docerina/output ``` -------------------------------- ### Example Templates Directory Configuration Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/ballerina-maven-plugins/docs/DocerinaMavenPlugin.md Point to a custom directory containing templates for API documentation generation. Defaults to embedded templates. ```xml /home/docerina/templates ``` -------------------------------- ### Display Ballerina Format CLI Help Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/formatter/modules/formatter-cli/README.md Prints the help guide for the Ballerina format tool. This command shows available options and usage instructions. ```sh $ bal format --help ``` -------------------------------- ### Example Dependency Graph Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0005/case-description.md Illustrates a typical dependency graph for a Ballerina package, showing direct and transitive dependencies. ```dot digraph "example1" { "myOrg/app:0.1.0" -> "myOrg/bazz:1.0.0" "myOrg/bazz:1.0.0" -> "myOrg/bar:1.3.1" "myOrg/bar:1.3.1" -> "ballerinai/foo:0.1.0" "myOrg/bar:1.3.1" [transitive = true] "ballerinai/foo:0.1.0" [transitive = true] } ``` -------------------------------- ### Java BeforeGroups Annotation for Test Setup Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/tests/jballerina-integration-test/integration-test-guidelines.md Used to define setup logic that runs before a group of tests. Ensure `alwaysRun` is set to true for reliable execution. ```java @BeforeGroups(value = "http-test", alwaysRun = true) public void start() throws BallerinaTestException { } ``` -------------------------------- ### Prism Syntax Highlighting Setup Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html This snippet shows how to set up Prism.js for syntax highlighting in a web environment. It handles manual initialization and disables worker messages for simpler integration. ```javascript function(e,t,n){"use strict";(function(t){var a=function(){var e="Prism"in t,n=e?t.Prism:void 0;return function(){e?t.Prism=n:delete t.Prism;e=void 0,n=void 0}}();("undefined"===typeof window?"undefined"===typeof self?{}:self:window).Prism={manual:!0,disableWorkerMessageHandler:!0};var r=n(44),o=n(60),i=n(67),l=n(68),s=n(69),c=n(70),u=n(71);a();var d={}.hasOwnProperty;function p(){}p.prototype=i;var f=new p;function g(e){if("function"!==typeof e||!e.displayName)throw new Error("Expected \`function\` for \`grammar\`, got \`"+e+"\`");void 0===f.languages[e.displayName]&&e(f)}e.exports=f,f.highlight=function(e,t){var n,a=i.highlight;if("string"!==typeof e)throw new Error("Expected \`string\` for \`value\`, got \`"+e+"\`");if("Object"===f.util.type(t))n=t,t=null;else{if("string"!==typeof t)throw new Error("Expected \`string\` for \`name\`, got \`"+t+"\`");if(!d.call(f.languages,t))throw new Error("Unknown language: \`"+t+"\` is not registered");n=f.languages[t]}return a.call(this,e,n,t)},f.reg ``` -------------------------------- ### Example Debug Docerina Configuration Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/ballerina-maven-plugins/docs/DocerinaMavenPlugin.md Enable debug-level logging for the Docerina process by setting this to 'true'. Defaults to 'false'. ```xml true ``` -------------------------------- ### useState Hook Example Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html Demonstrates the usage of the useState hook for managing component state in React. ```javascript useState:ei ``` -------------------------------- ### NoFormatter Output Example Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/syntax-api-calls-gen/docs/README.md Demonstrates the direct string conversion of a segment tree without any whitespace formatting. ```java NodeFactory.createModulePartNode(NodeFactory.createNodeList(),NodeFactory.createNodeList(),NodeFactory.createToken(SyntaxKind.EOF_TOKEN,NodeFactory.createEmptyMinutiaeList(),NodeFactory.createEmptyMinutiaeList())) ``` -------------------------------- ### Pull a tool from Ballerina Central Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-help.txt Use this command to download and install a tool from Ballerina Central. Ensure the tool name is accurate. ```bash bal tool pull health ``` -------------------------------- ### Run Ballerina REPL with Installed Distribution (Linux/macOS) Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/ballerina-shell/README.md Launches the Ballerina REPL using a pre-installed Ballerina distribution. This enables stdlib imports. Replace `$BALLERINA_HOME` with the actual path. ```bash java -jar -Dballerina.home=$BALLERINA_HOME shell-cli/build/libs/shell-cli-1.0-SNAPSHOT.jar ``` -------------------------------- ### Use Ballerina Tool with Specific Version Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-use-with-invalid-tool-version.txt Installs a specific version of a Ballerina tool. Ensure the tool ID and version are correctly formatted. ```bash bal tool use : ``` -------------------------------- ### useRef Hook Example Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html Shows how to use the useRef hook to create mutable references that persist across renders. ```javascript useRef:function(e){return e={current:e},qo().memoizedState=e} ``` -------------------------------- ### Default Formatter Output Example Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/syntax-api-calls-gen/docs/README.md Shows the formatted output of a segment tree with added whitespaces, similar to the Dart formatter. ```java NodeFactory.createModulePartNode( NodeFactory.createNodeList(), NodeFactory.createNodeList(), NodeFactory.createToken( SyntaxKind.EOF_TOKEN, NodeFactory.createEmptyMinutiaeList(), NodeFactory.createEmptyMinutiaeList() ) ) ``` -------------------------------- ### Pull a specific version of a tool Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-help.txt To install a particular version of a tool, specify the version number after the tool name, separated by a colon. ```bash bal tool pull health:1.0.0 ``` -------------------------------- ### React Hooks: useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html Provides examples of common React hooks for memoization, side effects, imperative access, and layout effects. ```javascript useCallback:pi,useEffect:ii,useImperativeHandle:ci,useLayoutEffect:li,useMemo:fi ``` -------------------------------- ### Javadoc Syntax Highlighting Setup Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html Registers the Javadoc syntax highlighting definition, extending 'javadoclike' and adding specific Javadoc elements like class names, namespaces, and code sections. ```javascript function r(e){e.register(a),function(e){var t={code:{pattern:/(^(\s\*(?:\\*\s\*)\*)).\[^\*\s\].+\$/m,lookbehind:!0,inside:e.languages.java,alias:"language-java"}};e.languages.javadoc=e.languages.extend("javadoclike",{}),e.languages.insertBefore("javadoc","keyword",{"class-name":\[{pattern:/(@(?:exception|throws|see|link|linkplain|value)\s+(?:\['a-z\d\]+\.)\*)\[A-Z\](?:\w\*\[a-z\]\w\*)?(?:\.\[A-Z\](?:\w\*\[a-z\]\w\*)?)\/\*/,lookbehind:!0,inside:{"punctuation":/\./}}, {pattern:/(@param\s+)<\['A-Z\]\w\*>/,lookbehind:!0,inside:{"punctuation":/\['.<>\]/}}],namespace:{pattern:/(@(?:exception|throws|see|link|linkplain)\s+)(?:\['a-z\d\]+\.)+/,lookbehind:!0,inside:{"punctuation":/\./}},"code-section":\[{pattern:/(\{@code\s+)(?:\['^{}\]|\{\['^{}\]\*\]\})+?(?=\s\*\})/,lookbehind:!0,inside:t},{pattern:/(<(code|tt)>\s\*)\[\s\S\]+?(?=\s\*<\/\2>)/,lookbehind:!0,inside:t} ],tag:e.languages.markup.tag}),e.languages.javadoclike.addSupport("java",e.languages.javadoc)}(e)}e.exports=r,r.displayName="javadoc",r.aliases=\[\]} ``` -------------------------------- ### Implement `CompletionProvider` Interface in Java Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/docs/language-server/CompilerPluginCompletions.md Implement the `CompletionProvider` interface to define custom code completion logic. This example provides completions for resource functions within service declarations. ```java /** * An example of a completion provider that adds a resource function to a service declaration. * * @since 2201.7.0 */ public class ServiceBodyContextProvider implements CompletionProvider { @Override public String name() { return "ServiceBodyContextProvider"; } @Override public List getCompletions(CompletionContext context, ServiceDeclarationNode node) throws CompletionException { //Adds a resource function if one is not present if (node.members().stream().anyMatch(member -> member.kind() == SyntaxKind.RESOURCE_ACCESSOR_DEFINITION)) { return Collections.emptyList(); } String insertText = "resource function " + CompletionUtil.getPlaceHolderText(1, \"get\") + " " + CompletionUtil.getPlaceHolderText(2, \"foo\") + "(" + CompletionUtil.getPlaceHolderText(3) + ")" + " returns " + CompletionUtil.getPlaceHolderText(4, \"string\") + " {" + CompletionUtil.LINE_BREAK + CompletionUtil.PADDING + "return " + CompletionUtil.getPlaceHolderText(5, \"\\\"\\\") + ";" + CompletionUtil.LINE_BREAK + "}"; String label = "resource function get foo() returns string"; CompletionItem completionItem = new CompletionItem(label, insertText, CompletionItem.Priority.HIGH); return List.of(completionItem); } @Override public List> getSupportedNodes() { return List.of(ServiceDeclarationNode.class); } } ``` -------------------------------- ### Generate Delivery Client using Build Tool Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/graph-with-build-tool.txt Use the 'generate-delivery-client' command with the sample-build-tool to create a delivery client. ```bash sample-build-tool(generate-delivery-client) ``` -------------------------------- ### Initialize Ballerina Project Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/samples/mock/README.md Use this command to initialize a new Ballerina project within the sample directory. Ensure the Ballerina executable is in your PATH. ```bash bal init ``` -------------------------------- ### useDeferredValue Hook Example Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html Explains the use of useDeferredValue for deferring updates to non-critical parts of the UI. ```javascript useDeferredValue:function(e,t){var n=ei(e),a=n[0],r=n[1];return oi((function(){var n=zo.suspense;zo.suspense=void 0!==t?null:t;try{r(e)}finally{zo.suspense=n}}),[e,t]),a} ``` -------------------------------- ### useReducer Hook Example Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html Illustrates the use of the useReducer hook for complex state logic management. ```javascript useReducer:function(e,t,n){var a=qo();return t=void 0!==n?n(t):t,a.memoizedState=a.baseState=t,e=(e=a.queue={pending:null,dispatch:null,lastRenderedReducer:e,lastRenderedState:t}).dispatch=mi.bind(null,Ho,e),[ a.memoizedState, e ] } ``` -------------------------------- ### View Help for `bal doc` Command Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/docerina/docs/README.md For a comprehensive list of available options and their usage, run the `bal doc --help` command. ```bash $ bal doc --help ``` -------------------------------- ### Clone Ballerina Repository Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/docerina/README.md Clone the Ballerina Git repository to start setting up the development environment. ```bash git clone https://github.com/ballerinalang/ballerina ``` -------------------------------- ### Initialize a Ballerina Project Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/docerina/docs/README.md Use `bal init -i` to initialize a new Ballerina project. Follow the prompts to configure organization name, version, and module types. ```bash $ mkdir myproject $ cd myproject $ bal init -i Create Ballerina.toml [yes/y, no/n]: (n) y Organization name: (nirmal) y Version: (0.0.1) Ballerina source [service/s, main/m]: (s) s Module for the service : (no module) math Ballerina source [service/s, main/m, finish/f]: (f) s Module for the service : (no module) time Ballerina source [service/s, main/m, finish/f]: (f) f Ballerina project initialized ``` -------------------------------- ### Ballerina Project Configuration Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/tests/jballerina-integration-test/integration-test-guidelines.md Defines the organization and version for a Ballerina project. This file is essential for project setup. ```toml [project] org-name = "ballerina-test" version = "0.0.1" ``` -------------------------------- ### Get Memoized State Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html Retrieves the memoized state from the current component. This is typically used internally by hooks. ```javascript function ni(){return Xo().memoizedState} ``` -------------------------------- ### React Hooks: useState and Debugging (Alternative) Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html Another example of useState and useDebugValue, potentially from a different context or version. ```javascript useState:function(){return Jo(Zo)},useDebugValue:ui ``` -------------------------------- ### Execute main dummy tool Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-multilevel-subcommands.txt This snippet shows the execution of a main dummy build tool. It represents a basic tool invocation with its corresponding execution message. ```ballerina dummy_tool(main_dummy) Running sample build tool: main_dummy ``` -------------------------------- ### Build Ballerina REPL JAR (Windows) Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/ballerina-shell/README.md Builds the fat JAR for the Ballerina REPL on Windows. This is a prerequisite for running the REPL. ```batch gradlew.bat fatJar ``` -------------------------------- ### Generate API Documentation Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/docerina/README.md Navigate to the Ballerina bin directory and execute the 'bal doc' command to generate API documentation for a Ballerina module. ```bash cd [ballerina-home]/bin ./bal doc [ballerina-module-path] # absolute file path of the ballerina source module ``` -------------------------------- ### Run Ballerina Benchmarks with Maven Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/benchmarks/README.md Use this command to execute the micro-benchmarks. Specify the number of warmup and benchmark iterations. ```bash mvn clean install -P benchmarks -Dwarmup.iterations= -Dbenchmark.iterations= ``` ```bash mvn clean install -P benchmarks -Dwarmup.iterations=22 -Dbenchmark.iterations=25000 ``` -------------------------------- ### Execute read tool Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-multilevel-subcommands.txt This snippet demonstrates calling the `read` function from a dummy tool. It highlights the direct invocation and the output message confirming the execution of the read tool. ```ballerina dummy_tool.read(read_dummy) Running read tool: read_dummy Gayal Dassanayake ``` -------------------------------- ### Remove all versions of an installed tool Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-help.txt Uninstalls all versions of a specified tool from your local Ballerina environment. Use with caution as this action is irreversible. ```bash bal tool remove health ``` -------------------------------- ### Run Ballerina REPL (Windows) Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/ballerina-shell/README.md Executes the Ballerina REPL using the generated fat JAR on Windows. Ensure the path to the JAR is correct. ```batch java -jar -Dballerina.home=home shell-cli/build/libs/shell-cli-1.0-SNAPSHOT.jar ``` -------------------------------- ### Run Ballerina Sample Tests Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/samples/mock/README.md Execute this command to run the tests for your Ballerina sample. This verifies the functionality of your sample code. ```bash bal test ``` -------------------------------- ### Execute write tool Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-multilevel-subcommands.txt This snippet shows how to invoke the `write` function of a dummy tool. It illustrates the direct call and the corresponding execution message, indicating the tool's name. ```ballerina dummy_tool.write(write_dummy) Running write tool: write_dummy Gayal Dassanayake ``` -------------------------------- ### Generate File with Client Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/graph-empty-project-with-build-tools.txt Use the `generate_file` function with the `generate_client` option to create client files. ```ballerina generate_file(generate_client) ``` -------------------------------- ### Get Current State with useReducer Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html Retrieves the current state from a reducer hook. This is useful for accessing the state without triggering a re-render. ```javascript function Jo(e){var t=Xo(),n=t.queue;if(null===n)throw Error(i(311));n.lastRenderedReducer=e;var a=n.dispatch,r=n.pending,o=t.memoizedState;if(null!==r){n.pending=null;var l=r=r.next;do{o=e(o,l.action),l=l.next}while(l!==r);Fa(o,t.memoizedState)||(Ci=!0),t.memoizedState=o,null===t.baseQueue&&(t.baseState=o),n.lastRenderedState=o}return[o,a]} ``` -------------------------------- ### Initialize Compiler Plugin with Completion Provider in Java Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/docs/language-server/CompilerPluginCompletions.md Extend the `CompilerPlugin` class and override the `init` method to register your custom completion provider with the `CompilerPluginContext`. ```java /** * Compiler plugin for testing completion providers. * * @since 2201.7.0 */ public class CompilerPluginWithCompletionProvider extends CompilerPlugin { @Override public void init(CompilerPluginContext pluginContext) { pluginContext.addCompletionProvider(new ServiceBodyContextProvider()); } } ``` -------------------------------- ### Initialize Component Instance Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html Creates a new instance of a React component, setting up its initial state, context, and refs. This is called during the mounting phase of a component's lifecycle. ```javascript function Eo(e,t,n){var a=!1,r=ur,o=t.contextType;"object"===typeof o&&null!==o?o=ao(o):(r=mr(t)?fr:dr.current,o=(a=null!==(a=t.contextTypes)&&void 0!==a)?gr(e,r):ur),t=new t(n,o),e.memoizedState=null!==t.state&&void 0!==t.state?t.state:null,t.updater=bo,e.stateNode=t,t._reactInternalFiber=e,a&&((e=e.stateNode)._unmaskedContext=r,e._maskedContext=o),t.updater=bo} ``` -------------------------------- ### Display Help for `bal doc` Command Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/docerina/README.md Use the `--help` flag to display usage information and available options for the `bal doc` command. ```sh $ bal doc --help ``` -------------------------------- ### Extract Ballerina Archive (.bala) Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/docs/Package.md Extract the generated .bala file to the specified directory within your Ballerina installation. This makes the tool available for use. ```bash Extract the .bala file to ~\.ballerina\repositories\central.ballerina.io\bala\ballerina\gayalstool\0.1.0\any\ ``` -------------------------------- ### Create ModulePartNode with SyntaxKind Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/syntax-api-calls-gen/docs/README.md Demonstrates creating a ModulePartNode using NodeFactory, including token creation with leading and trailing minutiae. The final output is assigned to a variable named modulePartNode. ```java MinutiaeList trailingMinutiae,leadingMinutiae; NodeList nodeList=NodeFactory.createNodeList(); NodeList nodeList1=NodeFactory.createNodeList(); leadingMinutiae=NodeFactory.createEmptyMinutiaeList(); trailingMinutiae=NodeFactory.createEmptyMinutiaeList(); Token token=NodeFactory.createToken(SyntaxKind.EOF_TOKEN,leadingMinutiae,trailingMinutiae); ModulePartNode modulePartNode=NodeFactory.createModulePartNode(nodeList,nodeList1,token); ``` -------------------------------- ### Shell Session Command and Output Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html Represents a typical shell session, showing commands executed and their corresponding output. Useful for scripting and command-line examples. ```shell-session $ echo "Hello, World!" Hello, World! ``` -------------------------------- ### Service Initialization with WorkspaceManagerProxy Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/docs/language-server/WritingExtendedServices.md Initialize the extended service using WorkspaceManagerProxy, which provides access to both the default WorkspaceManager and the expr file scheme based workspace manager, along with LanguageServerContext. ```Java default void init(LanguageServer langServer, WorkspaceManagerProxy workspaceManagerProxy, LanguageServerContext serverContext) { // access and store the parameters } ``` -------------------------------- ### Remove a specific version of an installed tool Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-help.txt Removes a specific version of a tool from your local environment. This is useful for managing disk space or resolving version conflicts. ```bash bal tool remove health:1.0.0 ``` -------------------------------- ### Properties File Language Definition Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html Defines the syntax highlighting for .properties files. It recognizes comments starting with '#' or '!', attribute values, attribute names, and the key-value separator. ```javascript function(e,t,n){"use strict";function a(e){e.languages.properties={comment:/^[ \t]*[#!].*$/m,"attr-value":{pattern:/(^[ \t]*(?:\\(?:\\r\\n|[\s\S])|[^\\\s:=])+?(?: *[=:] *| ))(?:\\(?:\\r\\n|[\s\S])|[^\\\r\n])+/m,lookbehind:!0},"attr-name":/^[ \t]*(?:\\(?:\\r\\n|[\s\S])|[^\\\s:=])+?(?= *[=:] *| )/m,punctuation:/[=:]/}}e.exports=a,a.displayName="properties",a.aliases=[]}} ``` -------------------------------- ### Generated Documentation Files Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/docerina/docs/README.md After running `bal doc`, the `api-docs/html` folder contains the generated documentation files, including an index, module-specific HTML files, and theme assets. ```bash $ ls api-docs/html/ docerina-theme index.html math.html module-list.html time.html ``` -------------------------------- ### Rest Language Syntax Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html Defines syntax highlighting for the Rest language, including strings, keywords, and punctuation. No specific setup is required beyond including the language definition. ```javascript function a(e){e.languages.rest={comment:/#. */,keyword:{pattern:/\b(?:true|false|null|undefined)\b/,alias:"boolean"},string:{pattern:/("|')((?:\\.|(?!\1).)*?)\1/,greedy:!0},number:/\b0x[\da-f]+|\b\d+(\.\d+)?(e[+-]?\d+)?/,operator:/[-+*\/%=<>!&|^~:]/,punctuation:/[;:,.]/,boolean:/\b(?:true|false)\b/,null:/\bnull\b/,undefined:/\bundefined\b/},constant:/\b(?:null|undefined)\b/,variable:/\b[A-Z_][A-Z0-9_]*\b/,function:/\b[a-z_][a-z0-9_]*\b(?=\s*\()/},e.exports=a,a.displayName="rest",a.aliases=[]} ``` -------------------------------- ### Run Ballerina Benchmarks Command Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/tests/jballerina-benchmark-test/README.md Execute this Gradle command to run the benchmarks. Supported arguments allow customization of iterations, paths, and GC logging. ```bash ./gradlew :jballerina-benchmark-test:test ``` -------------------------------- ### Ballerina Compiler Pipeline with BIR Generation Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/docs/compiler/bir-spec.md Illustrates the compiler phases, highlighting the 'BIR gen' stage and its subsequent processing for code generation and optimization. ```text ,-> JVM Code gen Lexer/Parser -> Type Check -> Semantic analyzer -> Desugar -> BIR gen -> BIR instrumentation/optimization - `-> LLVM Code gen ``` -------------------------------- ### Define Listener Class in Ballerina Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/docs/language-server/CompilerPluginCompletions.md Defines a basic `Listener` class with methods for starting, stopping, attaching, and detaching services. This serves as a foundation for network endpoints in Ballerina. ```ballerina public class Listener { private int port = 0; public function 'start() returns error? { return self.startEndpoint(); } public function gracefulStop() returns error? { return (); } public function immediateStop() returns error? { error err = error("not implemented"); return err; } public function attach(service object {} s, string[]|string? name = ()) returns error? { return self.register(s, name); } public function detach(service object {} s) returns error? { return (); } public function init(int port) { } public function initEndpoint() returns error? { return (); } function register(service object {} s, string[]|string? name) returns error? { return (); } function startEndpoint() returns error? { return (); } } ``` -------------------------------- ### Getting the DOM Node from a React Fiber Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/testerina/modules/testerina-runtime/src/main/resources/production.html This function retrieves the actual DOM node (stateNode) from a React Fiber node. It's used for direct DOM manipulation. ```javascript function xn(e){return 5===e.tag||6===e.tag?e.stateNode:null} ``` -------------------------------- ### Execute write caps tool Source: https://github.com/ballerina-platform/ballerina-lang/blob/master/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-multilevel-subcommands.txt This snippet demonstrates calling the `write.caps` function from a dummy tool to execute the write capabilities tool. It shows the direct invocation and the expected output message. ```ballerina dummy_tool.write.caps(write_dummy_caps) Running write caps tool: write_dummy_caps GAYAL DASSANAYAKE ```