Search code examples
dataweavemulesoftmule4

How to Access Source Code or Definitions of Inbuilt Functions in Mule 4 DataWeave?


I've primarily relied on custom modules and functions I've created for specific needs. However, I've also been utilizing a number of inbuilt functions provided by Mule in DataWeave, such as the upper function, which returns the provided string in uppercase characters, with the syntax upper(text: String): String.

how does Mule implement this? Or where could I find the source code of this function?


Solution

  • For see implementations of the DataWeave functions in Anypoint studio, use [CTRL] button and LMB click at the function name.

    picture of Set Payload where to CTRL and LMB

    For example, upper:

    /**
    * Returns the provided string in uppercase characters.
    *
    * === Parameters
    *
    * [%header, cols="1,3"]
    * |===
    * | Name   | Description
    * | `text` | The string to convert to uppercase.
    * |===
    *
    * === Example
    *
    * This example converts lowercase characters to uppercase.
    *
    * ==== Source
    *
    * [source,DataWeave,linenums]
    * ----
    * %dw 2.0
    * output application/json
    * ---
    * { "name" : upper("mulesoft") }
    * ----
    *
    * ==== Output
    *
    * [source,JSON,linenums]
    * ----
    * { "name": "MULESOFT" }
    * ----
    **/
    fun upper(text: String): String = native("system::StringUpperFunctionValue")
    

    You can see native("system::StringUpperFunctionValue"). The function native means that the implementation is in jar or class files. Specifically, system::StringUpperFunctionValue StringUpperFunctionValue.class is located in the maven package groupId org.mule.weave artifactId runtime.