Skip to content
This repository was archived by the owner on Nov 10, 2018. It is now read-only.

Using return values

Tim Seckinger edited this page Dec 27, 2016 · 8 revisions

Return types

You can return various types of values from your script, and the result will be intelligently converted for substitution / completion.

"Normal" objects

Often, simply calculating some text to be inserted is all a script needs to do. Therefore, "normal" objects that have no special handling, such as Strings and Integers will be toStringed and inserted in the place of the template variable.

Examples (Groovy)

'asdf' // => asdf
-65.43e21 // => -6.543E+22
java.time.LocalDate.now() // => 2016-12-15
new Observable() // No useful toString() => Observable@1234abcd
null // null-safe => null

I/O

Readers and InputStreams will be fully read using the default charset to insert their text.

Examples (Groovy)

new StringReader('asdf') // => asdf
new ByteArrayInputStream([0x61, 0x73, 0x64, 0x66] as byte[]) // UTF-8 => asdf

Collections

Returning a collection (or similar type, see below) triggers a completion popup offering all its values.
Each value is itself converted according as described on this page.
Nested collections are flattened.

The following collection-ish types are supported:

Examples (Groovy)

['a', 4] // Simple example => a, 4
[a: 'b', c: 'd'] // Map values => b, d
['a', new StringReader('b')] // Recursive conversion => a, b
['a', ['b', 'c']] // Flattening => a, b, c
['a', [abc: ['b', 'c'].stream(), xyz: new StringReader("d")]] // Recursive flattening and conversion => a, b, c, d

Using System.out

TODO

Tips

TODO

Clone this wiki locally