Skip to content

Overview

Concepts and Principles

Development

Overview

IDEs

API Explorer

Releases

Release Notes

TORO Integrate

Coder Studio

Coder Cloud

Bug Reports

Search

Decorating with Gloop Annotations

Gloop Annotations are a set of Java annotations that are used on Groovy Services (methods) and other Java code to provide additional information on the usage and input and output of a service. Adding Gloop Annotations to your Groovy Services makes it easier to use them when adding them to your Gloop Services.

Decorating a Groovy Service is as simple as adding annotations to it. These annotations will help you easily create input and output models, add properties to certain parameters, document, and hide a service from the Coder Navigator.

Since a method in a Groovy or Java class has inputs and outputs like a Gloop Service, the Groovy editor in Coder Studio allows you to use the Input/Output view to add the annotations for you!

Coder Studio Gloop enabled Groovy Editor

To decorate a Groovy Service with Gloop Annotations, first you need to have a Groovy script with a class and a public static method. You can create your own Groovy class by following this guide. You can read learn more about Groovy Services here.

Gloop Annotations

Below is a table listing the Gloopdoc Annotations that can be used for decorating a service, including a small summary on how they are used.

Annotation Description
GloopComment Adds comments to a service or method. These comments are shown in the Gloop Service Editor, and in the Coder Navigator.
GloopHide Hides a method from the Coder Navigator.
GloopParameter Provides more information to input and output variables in methods and with extra information for Gloop.
GloopObjectParameter Describes Gloop Model properties in a method.

Note

The file GloopDocsDemo.groovy in the examples package shows some examples on how to decorate a Groovy service.

Decorating a Groovy Service Using Gloop Annotations

Let's add a sample Groovy service with a public static method. If it's not public static, it won't be exposed to Gloop.

Consider this snippet here:

1
2
3
4
5
6
7
8
class Sample {

    static Integer getSum( Integer... input ) {
        int sum = 0
        input.each { sum+=it }
        sum
    }
}

You'll also see if the service is exposed correctly when you have saved your changes and there are no compilation errors, and appears in the Coder Navigator.

Show Groovy metadata

@GloopComment

The @GloopComment annotation should be written above the method, like any other Java Annotation. The @GloopComment annotation is used to add documentation to a method that is used by Gloop.

1
2
3
4
5
6
7
8
9
class Sample {

    @GloopComment( 'Getting the sum of the inputs' )
    static Integer getSum( Integer... input ) {
        int sum = 0
        input.each { sum+=it }
        sum
    }
}

To import or not to import?

Notice that the code above didn't import the @GloopComment annotation? This is because the code was compiled using a nifty Compilation Customizer that imports it for you.

The value of the @GloopComment will then be shown as a tooltip in the Coder Navigator.

Coder Navigator show @GloopComment

The value of the @GloopComment will also appear as a tooltip in the Gloop Service Editor.

Gloop Service Editor showing Gloop Comment

Finally, the value of the @GloopComment will appear as a Java-like comment in the Gloop Service Editor.

Gloop Service Editor showing Gloop Comment inline

Markdown? Yes!

Coder and Gloop both support the use of Markdown in your @GloopComment annotations. Groovy Service with Markdown comments

@GloopHide

The @GloopHide is used to stop a public static method from appearing in the Coder Navigator. This is useful when you have utility methods that need to be public static so other Groovy code can use it, but don't want the method appearing in the Coder Navigator.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
class Sample {

    @GloopHide
    @GloopComment( 'Getting the sum of the inputs' )
    static Integer getSum( Integer... input ) {
        int sum = 0
        input.each { sum+=it }
        sum
    }
}

@GloopParameter

The @GloopParameter annotation is used to describe a method parameter, or its return type with extra information that makes it analogous to a Gloop Property. The table below describes the parameters supported by the @GlooParameter annotation and what they do, and includes links to the associated Gloop documentation. This is because Gloop will treat these annotated code parameters and return types like a Gloop property:

Property Description
value Describes the property
allowNull Tells Gloop whether the method parameter allows null values
name Tells Gloop what the name of the returned object of a method is
choices Allows Coder to provide you with a list of pre-determined values for the property
allowOtherValues Tells Coder and Gloop whether this property allows other values
defaultValue If the value is null, the defaultValue will be used by Gloop instead
allowExtraProperties If this annotation is annotating a Gloop Model, then this will determine whether the model allows extra properties

The example code below shows an example on how to add and populate the annotation.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
class Sample {
    @GloopComment( 'Getting the sum of the inputs' )
    static Integer getSum(
        @GloopParameter ( value = 'The ones to be computed', defaultValue = '[1, 2, 3, 4, 5]' )
        Integer[] input ){
        int sum = 0
        input.each { sum+=it }
        sum
    }
}

As stated earlier, the Groovy editor in Coder Studio is tied to the Gloop Input/Output view, meaning as the cursor moves around your code, the Input/Output view will update itself with the method parameters and return types of your code. When you want to start annotating your code, simply place the cursor and use the Input/Output view like you would when editing a Gloop service, as shown below:

Add GloopParameter via Views

This annotation can also be used on a method. If it's used on a method, the annotation should be above the method, and will be used by Gloop to describe the return type

@GloopObjectParameter

The @GloopObjectParameter annotation is used by Gloop to describe Gloop Models. The value of the annotation is used to tell Gloop what the corresponding Gloop Model will look like. It describes everything from the properties it will have, how the properties will look, the name, and whether the model allows extra properties or not. The syntax of this is called GloopDoc and can be hard to understand, which is why the editor generates it for you.

Using the sample method below:

1
2
3
4
5
6
7
class Sample {
    static GloopModel makePerson( 
        String name,
        Integer age,
        String gender ) {
    }
}

Now lets decorate the return type of the method which is the GloopModel to have properties of name, age, and gender.

Adding GloopObjectParameter demo

1
2
3
4
5
6
7
8
class Sample {
    @GloopObjectParameter( 'output{\n  Person{\n    name\n    age:int\n    gender\n  }\n}' )
    static GloopModel makePerson(
    String name,
    Integer age,
    String gender ){
    }
}

Now that we have decorated our return type, lets complete the method by adding its body.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
class Sample {
    @GloopObjectParameter( 'output{\n  Person{\n    name\n    age:int\n    gender\n  }\n}' )
    static GloopModel makePerson(
        String name,
        Integer age,
        String gender ){
        GloopModel output = GloopObject.fromGloopDoc( 'output{\n  Person{\n    name\n    age:int\n    gender\n  }\n}' )
        output.Person.name = name
        output.Person.age = age
        output.Person.gender = gender
        output
    }
}

Notice that line 7 of the code uses a static GloopObject method called fromGloopDoc. This method builds a Gloop Model using the passed in Gloop Doc. When you write a service that uses a Model, generate the Gloop Doc as demonstrated in the short GIF image above, then copy and paste it as the argument to the method, as the sample code above shows.

Want in on a Gloop Model?

This annotation can also be used for the method parameters (inputs) of a method that are Gloop Models.

Gloop Enabled Groovy Editor

As stated earlier, the default Groovy editor in Coder Studio is called the "Gloop Enabled Groovy Editor". This editor provides additional functionality to 'decorate' Groovy services. This editor is connected with the Input View and Output View that can be used to decorate the method parameters and return type respectively. The Properties View can also be used to add additional object properties of an input or return of the method.

For example when you write with Groovy, you will see the input parameters of the method is generated in the Input View while the return type of the method is in the Output View. It will be shown while your text cursor is in the method.

Show method input and return type to UI