Skip to content

Add type helpers #2

Description

@baffelli

To make it easier to write the scripts in a IDE, you might want to add a "annotation only" @BaseScript class.
For a SCIM/REST script, this almost works:

package ch.empa.connector.ide

import com.evolveum.polygon.scimrest.groovy.*
import com.evolveum.polygon.scimrest.groovy.api.*
import groovy.transform.CompileStatic

/**
 * IDE helper base class for SCIM search scripts.
 * Provides autocompletion and static type hints only.
 * Never executed at runtime.
 */
@CompileStatic
abstract class RestSearchScript extends Script {

    AuthenticationCustomizationBuilder authentication(
            @DelegatesTo(AuthenticationCustomizationBuilder)
                    Closure<?> body = null
    ) { null }

    RestRelationshipBuilder relationship(
            @DelegatesTo(RestRelationshipBuilder)
                    Closure<?> body = null
    ) { null }

    GroovyRestHandlerBuilder objectClass(
            String name,
            @DelegatesTo(value = BaseOperationSupportBuilder,
                    strategy = Closure.DELEGATE_ONLY)
                    Closure<?> body = null
    ) { null }

    Object run() { null }
}

then in your script you can do:

package ch.empa.connector.ide

import com.evolveum.polygon.scimrest.groovy.*
import com.evolveum.polygon.scimrest.groovy.api.*
import groovy.transform.CompileStatic

/**
 * IDE helper base class for SCIM search scripts.
 * Provides autocompletion and static type hints only.
 * Never executed at runtime.
 */
@CompileStatic
abstract class RestSearchScript extends Script {

    AuthenticationCustomizationBuilder authentication(
            @DelegatesTo(AuthenticationCustomizationBuilder)
                    Closure<?> body = null
    ) { null }

    RestRelationshipBuilder relationship(
            @DelegatesTo(RestRelationshipBuilder)
                    Closure<?> body = null
    ) { null }

    GroovyRestHandlerBuilder objectClass(
            String name,
            @DelegatesTo(value = BaseOperationSupportBuilder,
                    strategy = Closure.DELEGATE_ONLY)
                    Closure<?> body = null
    ) { null }

    Object run() { null }
}

Unfortunately I am still not doing it fully correctly and it fails at runtime, but the compile time type information is correct

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions