From 71757e1ec8aa31cd285b86f620dd111e05af0e39 Mon Sep 17 00:00:00 2001 From: Marcin Zajaczkowski Date: Fri, 13 Feb 2015 00:11:00 +0100 Subject: [PATCH] [#5] Minor enhancements --- .../groovy/io/coderate/accurest/dsl/GroovyDsl.groovy | 6 ++---- .../accurest/dsl/internal/ClientDslProperty.groovy | 3 --- .../io/coderate/accurest/dsl/internal/Common.groovy | 3 +-- .../accurest/dsl/internal/DelegateHelper.groovy | 10 ---------- .../coderate/accurest/dsl/internal/DslProperty.groovy | 1 + .../io/coderate/accurest/dsl/internal/Request.groovy | 8 +++----- .../io/coderate/accurest/dsl/internal/Response.groovy | 5 ++--- .../accurest/dsl/internal/ServerDslProperty.groovy | 4 +--- .../accurest/dsl/internal/WithValuePattern.groovy | 2 -- 9 files changed, 10 insertions(+), 32 deletions(-) delete mode 100644 accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/DelegateHelper.groovy diff --git a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/GroovyDsl.groovy b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/GroovyDsl.groovy index 1ae6fe4644..4c7ef95839 100644 --- a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/GroovyDsl.groovy +++ b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/GroovyDsl.groovy @@ -18,15 +18,13 @@ class GroovyDsl { } void request(@DelegatesTo(Request) Closure closure) { - Request request = new Request() - this.request = request + this.request = new Request() closure.delegate = request closure() } void response(@DelegatesTo(Response) Closure closure) { - Response response = new Response() - this.response = response + this.response = new Response() closure.delegate = response closure() } diff --git a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/ClientDslProperty.groovy b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/ClientDslProperty.groovy index 005d52bc7b..5551688e02 100644 --- a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/ClientDslProperty.groovy +++ b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/ClientDslProperty.groovy @@ -4,9 +4,6 @@ import groovy.transform.CompileStatic @CompileStatic class ClientDslProperty extends DslProperty { - ClientDslProperty(Object clientValue, Object serverValue) { - super(clientValue, serverValue) } - ClientDslProperty(Object singleValue) { super(singleValue) } diff --git a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Common.groovy b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Common.groovy index 7fbd42caea..fc5135af33 100644 --- a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Common.groovy +++ b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Common.groovy @@ -39,7 +39,7 @@ class Common { } DslProperty $(ServerDslProperty server, ClientDslProperty client) { - return value(client, server) + return value(server, client) } ClientDslProperty client(Object clientValue) { @@ -49,5 +49,4 @@ class Common { ServerDslProperty server(Object serverValue) { return new ServerDslProperty(serverValue) } - } diff --git a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/DelegateHelper.groovy b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/DelegateHelper.groovy deleted file mode 100644 index baa8240dcf..0000000000 --- a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/DelegateHelper.groovy +++ /dev/null @@ -1,10 +0,0 @@ -package io.coderate.accurest.dsl.internal - -//TODO: There is problem with a trait usage -class DelegateHelper { - - public static void delegateToClosure(@DelegatesTo(T) Closure closure, T delegate) { - closure.delegate = delegate - closure() - } -} diff --git a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/DslProperty.groovy b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/DslProperty.groovy index 11ede5a82e..485ff61a79 100644 --- a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/DslProperty.groovy +++ b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/DslProperty.groovy @@ -1,4 +1,5 @@ package io.coderate.accurest.dsl.internal + import groovy.transform.CompileStatic @CompileStatic diff --git a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Request.groovy b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Request.groovy index d28bc159c0..7f41fe41fd 100644 --- a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Request.groovy +++ b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Request.groovy @@ -2,8 +2,6 @@ package io.coderate.accurest.dsl.internal import groovy.transform.CompileStatic import groovy.transform.TypeChecked -import static io.coderate.accurest.dsl.internal.DelegateHelper.delegateToClosure - @TypeChecked class Request extends Common { @@ -49,9 +47,9 @@ class Request extends Common { } void headers(@DelegatesTo(Headers) Closure closure) { - Headers headers = new Headers() - this.headers = headers - delegateToClosure(closure, headers) + this.headers = new Headers() + closure.delegate = headers + closure() } void urlPath(String urlPath) { diff --git a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Response.groovy b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Response.groovy index fe15280bde..928d441dc5 100644 --- a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Response.groovy +++ b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Response.groovy @@ -3,8 +3,6 @@ package io.coderate.accurest.dsl.internal import groovy.transform.CompileStatic import groovy.transform.TypeChecked -import static io.coderate.accurest.dsl.internal.DelegateHelper.delegateToClosure - @TypeChecked class Response extends Common { @@ -31,7 +29,8 @@ class Response extends Common { void headers(@DelegatesTo(Headers) Closure closure) { this.headers = new Headers() - delegateToClosure(closure, headers) + closure.delegate = headers + closure() } void body(Map body) { diff --git a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/ServerDslProperty.groovy b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/ServerDslProperty.groovy index a23cc80c23..1e468f10e5 100644 --- a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/ServerDslProperty.groovy +++ b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/ServerDslProperty.groovy @@ -1,12 +1,10 @@ package io.coderate.accurest.dsl.internal + import groovy.transform.CompileStatic @CompileStatic class ServerDslProperty extends DslProperty { - ServerDslProperty(Object clientValue, Object serverValue) { - super(clientValue, serverValue) } - ServerDslProperty(Object singleValue) { super(singleValue) } diff --git a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/WithValuePattern.groovy b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/WithValuePattern.groovy index 32dfddf741..d9fb4cc588 100644 --- a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/WithValuePattern.groovy +++ b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/WithValuePattern.groovy @@ -94,6 +94,4 @@ class WithValuePattern { void matchesJsonPath(DslProperty matchesJsonPath) { this.matchesJsonPath = matchesJsonPath } - - }